1

Im inserting code snippets in my website using the <pre> tag.

Here is the HTML/PHP code:

<pre class="prettyprint">
    <?php include('canny.py'); ?>
</pre>

And here is the content of canny.py:

import cv2
img = cv2.imread('/path/to/file/line_02.jpg', 0)
edges = cv2.Canny(img, 100, 200)
cv2.imwrite('mycanny.jpg', edges)

However, for some reason the first line renders like 3 or 4 tabs away from the left margin of the div element. And this only happens in the first line i.e, if i leave the first line of the .py file empty, the second line still renders fine.

enter image description here

Why is this happening, what is the way to make it work properly?

Community
  • 1
  • 1
fartagaintuxedo
  • 749
  • 10
  • 28

1 Answers1

0

Remove the four spaces between your opening <pre> tag and the PHP tag <?php.

These are interpreted literally and the content that your PHP script reads is inserted after these four spaces, therefore your first line is offset by the same.

<pre class="prettyprint"><?php include('canny.py'); ?></pre>

should work.

Joseph
  • 1,003
  • 3
  • 11
  • 25