<pre> tag causing large offset of first line

时间:2016-08-13 13:24:07

标签: html pre php-include

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?

1 个答案:

答案 0 :(得分:0)

删除开始<pre>标记和PHP标记<?php之间的四个空格。

这些是按字面解释的,并且PHP脚本读取的内容在这四个空格之后插入,因此第一行偏移相同。

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

应该有用。