aboutsummaryrefslogtreecommitdiff
path: root/pyblog
diff options
context:
space:
mode:
authorZhiming Wang <zmwangx@gmail.com>2015-07-17 21:27:52 -0700
committerZhiming Wang <zmwangx@gmail.com>2015-07-17 21:47:05 -0700
commit110cf961113af9d5386cd9ba35404161e473e39b (patch)
treee16f4e4af4b4e8a8f35483f515257ddf1b843979 /pyblog
parent8b6e38dd3c63fbf1badc2fb6492fa9523e0048d9 (diff)
downloadmy_new_personal_website-110cf961113af9d5386cd9ba35404161e473e39b.tar.xz
my_new_personal_website-110cf961113af9d5386cd9ba35404161e473e39b.zip
fix line number placement
Global font size in each style sheet has been tweaked very carefully so that the precise line height is very close to a whole number of pixels, so that precision alignment using em, which aligns something precise (top: 13.5em) to something inprecise (line heights, with accumulated errors due to rounding in every line), is not lost. Note that Firefox is NOT supported, since each line seems to always occupy one more pixel than the calculated line height. For some reason line numbers in the print view are still rather problematic at a page continuation. In Chrome and Safari, the first two line numbers on a new page tend to overlap, so everything afterwards are off (and on Firefox line numbers do not show up on the second page at all). Anyway, printing shouldn't be a big concern.
Diffstat (limited to '')
-rwxr-xr-xpyblog6
1 files changed, 3 insertions, 3 deletions
diff --git a/pyblog b/pyblog
index ef6f6d6e..605813ed 100755
--- a/pyblog
+++ b/pyblog
@@ -593,12 +593,12 @@ def _pre_tag_insert_line_numbers(soup, pre_tag):
num_lines = len(pre_tag.text.split("\n"))
for line_number in range(1, num_lines + 1):
# line number divs will look like:
- # <span class="line-number" data-line="1" style="top: 1px"><!----></span>
- # <span class="line-number" data-line="2" style="top: 19px"><!----></span>
+ # <span class="line-number" data-line="1" style="top: 0em"><!----></span>
+ # <span class="line-number" data-line="2" style="top: 1.35em"><!----></span>
ln_tag = soup.new_tag("span")
ln_tag["class"] = "line-number"
ln_tag["data-line"] = line_number
- ln_tag["style"] = "top: %dpx" % ((line_number - 1) * CODE_LINE_HEIGHT + 1)
+ ln_tag["style"] = "top: %.2fem" % ((line_number - 1) * 1.35)
# add a comment to the content of the span to suppress tidy5
# empty <span> tag warning
ln_tag.append(soup.new_string("", bs4.Comment))