- add Local Render Mermaid - add page-starе для указания смещения страниц - add Гиперссылки в документе на списки литературы
This commit is contained in:
@@ -156,3 +156,38 @@ def ensure_continuous_page_numbers(document) -> None:
|
||||
# Keep continuous: remove start attribute if present
|
||||
if child.get(qn("w:start")) is not None:
|
||||
del child.attrib[qn("w:start")]
|
||||
|
||||
|
||||
def set_section_page_start(section, start: int) -> None:
|
||||
"""Set w:pgNumType/@w:start so PAGE field begins at ``start`` in this section."""
|
||||
if start < 1:
|
||||
return
|
||||
sect_pr = section._sectPr
|
||||
pg = sect_pr.find(qn("w:pgNumType"))
|
||||
if pg is None:
|
||||
sect_pr.append(create_element("w:pgNumType", {"w:start": str(int(start))}))
|
||||
else:
|
||||
pg.set(qn("w:start"), str(int(start)))
|
||||
|
||||
|
||||
def apply_page_number_start(
|
||||
document,
|
||||
start: int | None,
|
||||
*,
|
||||
front_sections: int = 0,
|
||||
) -> None:
|
||||
"""
|
||||
Apply page-number offset for the body.
|
||||
|
||||
``start`` is None / <1 — leave continuous numbering (strip explicit starts).
|
||||
``start`` >= 1 — first section after front matter restarts PAGE at that number;
|
||||
later body sections stay continuous from there.
|
||||
"""
|
||||
ensure_continuous_page_numbers(document)
|
||||
if start is None or int(start) < 1:
|
||||
return
|
||||
sections = list(document.sections)
|
||||
idx = max(0, int(front_sections))
|
||||
if idx >= len(sections):
|
||||
return
|
||||
set_section_page_start(sections[idx], int(start))
|
||||
|
||||
Reference in New Issue
Block a user