From 28289ae4f3ac197489feda201843407e1f7f2537 Mon Sep 17 00:00:00 2001 From: neodarz Date: Sun, 26 May 2019 00:47:00 +0200 Subject: Move _pre_tag_insert_line_numbers function to external file --- pyblog | 17 ----------------- utils/utils.py | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/pyblog b/pyblog index 7bdf88ae..ad89e71e 100755 --- a/pyblog +++ b/pyblog @@ -766,23 +766,6 @@ def generate_index_and_feed(): generate_sitemap(feed) -def _pre_tag_insert_line_numbers(soup, pre_tag): - """Insert line numbers to a 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: - # - # - ln_tag = soup.new_tag("span") - ln_tag["class"] = "line-number" - ln_tag["data-line"] = line_number - ln_tag["style"] = "top: %.2fem" % ((line_number - 1) * 1.35) - # add a comment to the content of the span to suppress tidy5 - # empty tag warning - ln_tag.append(soup.new_string("", bs4.Comment)) - pre_tag.code.append(ln_tag) - - def process_footnote_backlinks(soup): """Add class attribute "footnotes-backlink" to each footnote backlink.""" for footnotes in soup.find_all("div", attrs={"class": "footnotes"}): diff --git a/utils/utils.py b/utils/utils.py index bc42291c..401e133e 100644 --- a/utils/utils.py +++ b/utils/utils.py @@ -148,3 +148,20 @@ def link_img_tags(soup): a_tag = soup.new_tag("a", href=img_tag["src"], target="_blank") a_tag.insert(0, copy.copy(img_tag)) img_tag.replace_with(a_tag) + + +def _pre_tag_insert_line_numbers(soup, pre_tag): + """Insert line numbers to a 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: + # + # + ln_tag = soup.new_tag("span") + ln_tag["class"] = "line-number" + ln_tag["data-line"] = line_number + ln_tag["style"] = "top: %.2fem" % ((line_number - 1) * 1.35) + # add a comment to the content of the span to suppress tidy5 + # empty tag warning + ln_tag.append(soup.new_string("", bs4.Comment)) + pre_tag.code.append(ln_tag) -- cgit v1.2.1