当前位置: 首页 > 工具软件 > AsciiDoc > 使用案例 >

adoc(asciidoc)转为markdown的方法

康弘义
2023-12-01

adoc(asciidoc)转为markdown的方法

转换原因

平时写文档,更倾向于使用asciidoc来写文档,因为他有更加丰富的功能。有的时候想发博客出去,但是一般网站的博客都是支持markdown的,所要有需求要将adoc转换为markdown的形式发送到网站上去。

转换方法

  • install pandoc and asciidoc

sudo apt install pandoc asciidoc

  • Convert asciidoc to docbook

asciidoc -b docbook foo.adoc

foo.xml will be output into the same directory as foo.adoc

  • Convert docbook to markdown

pandoc -f docbook -t markdown_strict foo.xml -o foo.md

  • Unicode symbols were mangled in foo.md. Quick workaround: (Unicode编码会被搞乱,快速的变通办法为:)

iconv -t utf-8 foo.xml | pandoc -f docbook -t markdown_strict | iconv -f utf-8 > foo.md

  • Pandoc inserted hard line breaks at 80 characters. Removed like so:

iconv -t utf-8 foo.xml | pandoc -f docbook -t markdown_strict --wrap=none | iconv -f utf-8 > foo.md

 类似资料: