@@ -39,6 +39,21 @@ def entries_from_text(text: str) -> list[BiblioEntry]:
|
||||
return entries
|
||||
|
||||
|
||||
# After citation linking, `[5]: …` often becomes `[]: …` in paragraph.text
|
||||
# (the digits live in a hyperlink). Still a biblio source line to drop.
|
||||
BIBLIO_RESIDUE_RE = re.compile(r"^\[\d*(?:\.\d+)?\]:\s*\S")
|
||||
|
||||
|
||||
def is_biblio_source_paragraph(text: str) -> bool:
|
||||
"""True if paragraph is a [n]: / []: bibliography source line (or empty)."""
|
||||
stripped = (text or "").strip()
|
||||
if not stripped:
|
||||
return True
|
||||
if entries_from_text(stripped):
|
||||
return True
|
||||
return bool(BIBLIO_RESIDUE_RE.match(stripped))
|
||||
|
||||
|
||||
def extract_bibliography_from_markdown(md: str) -> list[BiblioEntry] | list[tuple[str, list[BiblioEntry]]]:
|
||||
"""
|
||||
Parse bibliography from raw markdown (reliable even if Marko merges lines).
|
||||
@@ -126,8 +141,8 @@ def fold_bibliography(renderables: list[Renderable], parent,
|
||||
consumed += 1
|
||||
continue
|
||||
if isinstance(item, Paragraph):
|
||||
text = (item._docx_paragraph.text or "").strip()
|
||||
if entries_from_text(text) or (not text):
|
||||
text = item._docx_paragraph.text or ""
|
||||
if is_biblio_source_paragraph(text):
|
||||
consumed += 1
|
||||
continue
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user