Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert asciidoc to Github Flavored Markdown
# Adapted from https://tinyapps.org/blog/nix/201701240700_convert_asciidoc_to_markdown.html
# Using asciidoctor 1.5.6.1 and pandoc 2.0.0.1
# Install pandoc and asciidoctor
$ sudo apt install asciidoctor
$ sudo wget https://github.com/jgm/pandoc/releases/download/2.0.0.1/pandoc-2.0.0.1-1-amd64.deb
$ sudo dpkg -i pandoc-2.0.0.1-1-amd64.deb
# Convert asciidoc to docbook using asciidoctor
$ asciidoctor -b docbook foo.adoc
# foo.xml will be output into the same directory as foo.adoc
# Convert docbook to markdown
$ pandoc -f docbook -t gfm foo.xml -o foo.md
# Unicode symbols were mangled in foo.md. Quick workaround:
$ iconv -t utf-8 foo.xml | pandoc -f docbook -t gfm | iconv -f utf-8 > foo.md
# Pandoc inserted hard line breaks at 72 characters. Removed like so:
$ pandoc -f docbook -t gfm --wrap=none # don't wrap lines at all
$ pandoc -f docbook -t gfm --columns=120 # extend line breaks to 120
@nebrass

This comment has been minimized.

Copy link

@nebrass nebrass commented Mar 28, 2018

thank you :) this is was useful for me !

@kitplummer

This comment has been minimized.

Copy link

@kitplummer kitplummer commented Jun 18, 2018

Much obliged. The intermediate move to docbook with asciidoctor was the trick I needed.

@acassaigne

This comment has been minimized.

Copy link

@acassaigne acassaigne commented Sep 6, 2018

Really useful. Many Thanks.

@AnushaBilakanti

This comment has been minimized.

Copy link

@AnushaBilakanti AnushaBilakanti commented Jan 16, 2019

when I run the command iconv -t utf-8 foo.xml | pandoc -f docbook -t gfm | iconv -f utf-8 > foo.md, I get message as
iconv: conversion from char unsupported
iconv: try 'iconv -l' to get the list of supported encodings
iconv: conversion to char unsupported
iconv: try 'iconv -l' to get the list of supported encodings

@diguage

This comment has been minimized.

Copy link

@diguage diguage commented Mar 19, 2019

This is a great shell.

@sshaaf

This comment has been minimized.

Copy link

@sshaaf sshaaf commented Aug 13, 2019

For mac users: If you do a brew install on mac for both pandoc and asciidoctor, it works quite well. the following two did the job.
$ asciidoctor -b docbook foo.adoc
$ pandoc -f docbook -t gfm foo.xml -o foo.md

@AquisTech

This comment has been minimized.

Copy link

@AquisTech AquisTech commented Sep 4, 2020

Thanks for the script.
I have updated it in my fork

I have shortened the script.
I have added --columns=120 option in earlier step itself. So last time commands can be removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.