From c29e1ab61ab659eb9ba1f440a3d52aa4294d70c3 Mon Sep 17 00:00:00 2001 From: neodarz Date: Sun, 26 May 2019 12:34:24 +0200 Subject: Move process_footnote_backlinks function to external file --- utils/utils.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'utils') diff --git a/utils/utils.py b/utils/utils.py index 401e133e..f8cb8ef6 100644 --- a/utils/utils.py +++ b/utils/utils.py @@ -165,3 +165,15 @@ def _pre_tag_insert_line_numbers(soup, pre_tag): # 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"}): + for fn_a_tag in footnotes.find_all(lambda tag: + tag.name == "a" and + tag.has_attr("href") and + tag["href"].startswith("#fnref") and + tag.string == "\u21A9"): # U+21A9: LEFTWARDS ARROW WITH HOOK + fn_a_tag["class"] = "footnotes-backlink" + fn_a_tag.string = "\u21A9\uFE0E" # U+FE0E: VARIATION SELECTOR-15 -- cgit v1.2.1