fix(export): handle metadata-only notes and HTML image resources

This commit is contained in:
2026-09-07 14:45:47 +08:00
parent 894f220239
commit ca5b52bc8a
6 changed files with 60 additions and 2 deletions
+2
View File
@@ -178,6 +178,8 @@ class _AstMapper:
type="link", node_id=self.next_id(), attributes=attributes,
children=self.map_inline(token.get("children", [])),
)
if kind == "inline_html":
return DocumentNode(type="text", node_id=self.next_id(), text=token.get("raw", ""), attributes={"raw_html": True})
if kind == "codespan":
return DocumentNode(type="codespan", node_id=self.next_id(), text=token.get("raw", ""))
if kind == "image":
+12 -1
View File
@@ -411,12 +411,23 @@ async def preview_resources(request: ExportRequest):
from app.export.assets import enrich_document
from app.plot.parser import parse_source
from app.plot.render import render_svg
from app.export.document import Document
from app.export.document import Document, DocumentNode
from html.parser import HTMLParser
markdown, _, metadata = await _resolve_source(request.source, True)
def prepare():
document = parse_document(markdown)
images, plots = [], []
class HtmlImages(HTMLParser):
def handle_starttag(self, tag, attrs):
if tag == 'img':
src = dict(attrs).get('src')
if src:
visit(DocumentNode(type='image', node_id='html-image', attributes={'src':src}))
def visit(node):
if node.type == 'html_block' or node.attributes.get('raw_html'):
parser = HtmlImages(convert_charrefs=True)
parser.feed(node.text)
parser.close()
if node.type == 'image':
warnings = enrich_document(Document(node_id='pdf-resources', children=[node]), (metadata or {}).get('file_path'), True, request.options, preserve_alpha=True)
raw = node.attributes.get('static_png')