如何在markdown_github中结合link_attributes与pandoc-plantuml过滤器?
能否在markdown_github中使用link_attributes扩展与pandoc过滤器?
问题背景
我想确认是否可以在markdown_github输入格式下,同时使用link_attributes扩展和pandoc过滤器(比如pandoc-plantuml)。
测试用的极简示例代码块:
```{ .plantuml height=0.2cm} Alice -> Bob: Authentication Request Bob --> Alice: Authentication Response
- 不指定输入格式时,执行命令: ```bash pandoc demo.md --filter pandoc-plantuml -o demo.tex
能得到预期的LaTeX输出:
\includegraphics[width=\textwidth,height=0.2cm]{plantuml-images/ce4ad67a96c31b33df8381cc8bb0730a201226b2.png}
- 但添加
-f markdown_github参数后:
输出完全不符合预期,代码块被当成纯文本转义处理:pandoc demo.md --filter pandoc-plantuml -o demo.tex -f markdown_github\texttt{\{\ .plantuml\ height=0.2cm\ \}\ Alice\ -\textgreater{}\ Bob:\ Authentication\ Request\ Bob\ -\/-\textgreater{}\ Alice:\ Authentication\ Response}
我测试了所有Markdown变体,仅commonmark_x能正常工作。尝试给markdown_github手动添加扩展参数:
-f markdown_github+yaml_metadata_block+raw_tex+link_attributes+header_attributes
但问题仍未解决。
原因分析
markdown_github基于GitHub Flavored Markdown(GFM)实现,GFM本身不支持代码块的属性语法(即```{ .class attr=val}这种形式),而且pandoc的markdown_github默认禁用了fenced_code_attributes扩展——这是识别代码块属性的关键扩展,你之前只添加了link_attributes,但代码块的属性解析需要的是另一个扩展。
只有当代码块被正确解析为带属性的代码块节点,pandoc-plantuml过滤器才能识别并处理它;否则代码块会被当成普通文本转义输出。
解决方案
要让markdown_github支持带属性的代码块并配合过滤器工作,需要额外启用fenced_code_attributes扩展,完整命令参数如下:
pandoc demo.md --filter pandoc-plantuml -o demo.tex -f markdown_github+fenced_code_attributes+yaml_metadata_block+raw_tex+link_attributes+header_attributes
另外,如果你不需要严格遵循GFM的所有限制,直接使用commonmark_x作为输入格式也是可行的,它默认支持包括代码块属性在内的更多扩展,能直接满足需求。
内容的提问来源于stack exchange,提问作者Sir l33tname
相关产品推荐
相关产品推荐

