From: Radek Czajka Date: Tue, 21 Dec 2021 12:44:24 +0000 (+0100) Subject: Support for numeracja in HTML. X-Git-Tag: 2.3.3~1 X-Git-Url: https://git.mdrn.pl/librarian.git/commitdiff_plain/92b8744bb51907c7147018d4fb44b0c56298d472?ds=sidebyside;hp=3eeb653bf9948d69c8290fd453b638bb783ab084 Support for numeracja in HTML. --- diff --git a/src/librarian/html.py b/src/librarian/html.py index d4b9795..fddeb2f 100644 --- a/src/librarian/html.py +++ b/src/librarian/html.py @@ -312,6 +312,7 @@ def any_ancestor(element, test): def add_anchors(root): counter = 1 + visible_counter = 1 for element in root.iterdescendants(): def f(e): return ( @@ -322,16 +323,25 @@ def add_anchors(root): or e.tag == 'blockquote' or e.get('id') == 'footnotes' ) + + if element.get('class') == 'numeracja': + try: + visible_counter = int(element.get('data-start')) + except ValueError: + visible_counter = 1 + if any_ancestor(element, f): continue if element.tag == 'div' and 'verse' in element.get('class', ''): - if counter == 1 or counter % 5 == 0: - add_anchor(element, "f%d" % counter, link_text=counter) + if visible_counter == 1 or visible_counter % 5 == 0: + add_anchor(element, "f%d" % counter, link_text=visible_counter) counter += 1 + visible_counter += 1 elif 'paragraph' in element.get('class', ''): - add_anchor(element, "f%d" % counter, link_text=counter) + add_anchor(element, "f%d" % counter, link_text=visible_counter) counter += 1 + visible_counter += 1 def raw_printable_text(element): diff --git a/src/librarian/xslt/book2html.xslt b/src/librarian/xslt/book2html.xslt index 9b77b5e..ba9dbb4 100644 --- a/src/librarian/xslt/book2html.xslt +++ b/src/librarian/xslt/book2html.xslt @@ -559,4 +559,12 @@ + + + + + + + +