Coradoc is a modern Parser for Asciidoc document. It defines a grammar for AsciiDoc, and then build the Parser for that grammar.
Once the document is parsed, it provides a pure ruby object Coradoc::Document
,
which can used to customize the document in easiest way.
Installation
Add this line to your application’s Gemfile:
gem "coradoc"
And then execute:
bundle install
Or install it yourself as:
gem install coradoc
Development
We are following Sandi Metz’s Rules for this gem, you can read the description of the rules here.[1] All new code should follow these rules. If you make changes in a pre-existing file that violates these rules you should fix the violations as part of your contribution.
Setup
Clone the repository.
git clone https://github.com/metanorma/coradoc.git
Setup your environment in docker
make setup
Run the test suite
make test
Usage from command line
Converting a document
$ coradoc help convert
$ coradoc convert file.html -o file.adoc
Usage from Ruby
Parsing a document
To parse any AsciiDoc, we can use the following:
This interface will return the abstract syntax tree.
Converting a document
To convert any document of a supported format (right now: .html
, .adoc
, .docx
) to any supported
format (right now: .adoc
), you can execute:
The converters are chosen based on file extension, but you can select a converter manually like so:
Some converters may support additional options, which can likewise be passed as keyword arguments:
It is also possible to pass IO objects instead of filenames. By default, if an argument is not provided, it defaults to STDIN/STDOUT. Note that not all combinations of formats and converter options are supported in this mode.