mirror of
https://github.com/Vonng/ddia.git
synced 2026-06-23 09:57:56 +08:00
fix: render epub callouts
This commit is contained in:
parent
47c360951b
commit
b95b81c8cd
1 changed files with 9 additions and 0 deletions
|
|
@ -13,6 +13,7 @@ import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
FIGURE_SHORTCODE_RE = re.compile(r"\{\{<\s*figure\b(.*?)>\}\}", re.DOTALL)
|
FIGURE_SHORTCODE_RE = re.compile(r"\{\{<\s*figure\b(.*?)>\}\}", re.DOTALL)
|
||||||
|
CALLOUT_SHORTCODE_RE = re.compile(r"\{\{<\s*callout\b(.*?)>\}\}(.*?)\{\{<\s*/callout\s*>\}\}", re.DOTALL)
|
||||||
ATTR_RE = re.compile(r'([\w-]+)="([^"]*)"')
|
ATTR_RE = re.compile(r'([\w-]+)="([^"]*)"')
|
||||||
ABS_IMAGE_RE = re.compile(r'!\[([^\]]*)\]\(/(?!static/)([^)]+)\)')
|
ABS_IMAGE_RE = re.compile(r'!\[([^\]]*)\]\(/(?!static/)([^)]+)\)')
|
||||||
FRONT_MATTER_RE = re.compile(r"\A---\s*\n(.*?)\n---\s*\n?", re.DOTALL)
|
FRONT_MATTER_RE = re.compile(r"\A---\s*\n(.*?)\n---\s*\n?", re.DOTALL)
|
||||||
|
|
@ -135,6 +136,14 @@ def convert_markdown(text, slug, known_pages=None):
|
||||||
alt = _escape_alt_text(attrs.get("caption") or attrs.get("title") or "")
|
alt = _escape_alt_text(attrs.get("caption") or attrs.get("title") or "")
|
||||||
return f''
|
return f''
|
||||||
|
|
||||||
|
def replace_callout_shortcode(match):
|
||||||
|
body = match.group(2).strip()
|
||||||
|
if not body:
|
||||||
|
return ""
|
||||||
|
quoted = "\n".join(f"> {line}" if line else ">" for line in body.splitlines())
|
||||||
|
return f"> **注意**\n>\n{quoted}"
|
||||||
|
|
||||||
|
text = CALLOUT_SHORTCODE_RE.sub(replace_callout_shortcode, text)
|
||||||
text = FIGURE_SHORTCODE_RE.sub(replace_figure_shortcode, text)
|
text = FIGURE_SHORTCODE_RE.sub(replace_figure_shortcode, text)
|
||||||
|
|
||||||
# 把 Markdown 里的绝对路径图片  转为 static/map/ch01.png
|
# 把 Markdown 里的绝对路径图片  转为 static/map/ch01.png
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue