md updates
This commit is contained in:
@@ -74,9 +74,9 @@ def process_wikilinks(content: str) -> str:
|
||||
def process_citations(content: str, resolver) -> str:
|
||||
"""Process org-mode citations and resolve them.
|
||||
|
||||
Handles:
|
||||
Handles (after pandoc conversion, brackets may be escaped):
|
||||
- cite:key
|
||||
- [cite:@key]
|
||||
- [cite:@key] or \[cite:@key\]
|
||||
- [[cite:key][description]]
|
||||
"""
|
||||
if resolver is None:
|
||||
@@ -86,18 +86,19 @@ def process_citations(content: str, resolver) -> str:
|
||||
cite_key = match.group(1)
|
||||
return resolver.resolve(cite_key)
|
||||
|
||||
# cite:key pattern
|
||||
content = re.sub(r"cite:([a-zA-Z0-9_-]+)", replace_cite, content)
|
||||
# cite:key pattern (not preceded by @, to avoid double-matching)
|
||||
content = re.sub(r"(?<!@)cite:([a-zA-Z0-9_-]+)", replace_cite, content)
|
||||
|
||||
# [cite:@key] pattern
|
||||
content = re.sub(r"\[cite:@([a-zA-Z0-9_-]+)\]", replace_cite, content)
|
||||
# [cite:@key] pattern (escaped or not after pandoc)
|
||||
# Pandoc escapes [ ] as \[ \]
|
||||
content = re.sub(r"\\?\[cite:@([a-zA-Z0-9_-]+)\\?\]", replace_cite, content)
|
||||
|
||||
# [[cite:key][description]] - use resolved link but keep description context
|
||||
def replace_cite_with_desc(match) -> str:
|
||||
cite_key = match.group(1)
|
||||
# [[cite:key][description]] - after pandoc becomes [description](cite:key)
|
||||
def replace_cite_link(match) -> str:
|
||||
cite_key = match.group(2)
|
||||
return resolver.resolve(cite_key)
|
||||
|
||||
content = re.sub(r"\[\[cite:([a-zA-Z0-9_-]+)\]\[[^\]]*\]\]", replace_cite_with_desc, content)
|
||||
content = re.sub(r"\[([^\]]+)\]\(cite:([a-zA-Z0-9_-]+)\)", replace_cite_link, content)
|
||||
|
||||
return content
|
||||
|
||||
|
||||
Reference in New Issue
Block a user