• Stars
    star
    174
  • Rank 219,104 (Top 5 %)
  • Language
    Ruby
  • License
    Other
  • Created almost 9 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A kramdown extension for converting Markdown documents to AsciiDoc.

Kramdown AsciiDoc (Markdown to AsciiDoc)

Gem Version Build Status (GitHub Actions)

Kramdown AsciiDoc (gem: kramdown-asciidoc, command: kramdoc) is a kramdown extension for converting Markdown documents to AsciiDoc. Notably, the converter generates modern AsciiDoc syntax suitable for use with Asciidoctor.

Prerequisites

To install and run Kramdown AsciiDoc, you need Ruby 2.3 or better installed and a few RubyGems (aka gems). The instructions for installing the gems is covered in the next section.

To check whether you have Ruby installed, and which version, run the following command:

$ ruby -v

If Ruby is not installed, you can install it using RVM (or, if you prefer, the package manager for your system). We generally recommend using RVM because it allows you to install gems without requiring elevated privileges or messing with system libraries.

Installation

Kramdown AsciiDoc is published to RubyGems.org as a gem named kramdown-asciidoc.

You can install the latest version of the gem using the following command:

$ gem install kramdown-asciidoc

Installing this gem makes the kramdoc command available on your $PATH.

๐Ÿ’ก
To test a feature thatโ€™s not yet released, you can run the application from source.

Usage

To convert a Markdown file to AsciiDoc using Kramdown AsciiDoc, pass the name of the file to the kramdoc command as follows:

$ kramdoc sample.md

By default, the kramdoc command automatically creates the output file sample.adoc in the same folder as the input file. This path is calculated by removing the Markdown file extension, .md, and replacing it with the AsciiDoc file extension, .adoc.

๐Ÿ“Ž
The converter assumes the input uses the GitHub-flavor Markdown (GFM) syntax.

If you want to direct the output to a different file, pass the name of that file to the kramdoc command using the -o option as follows:

$ kramdoc -o result.adoc sample.md

To direct the output to the console (i.e., STDOUT) instead of a file, use the special value - as follows:

$ kramdoc -o - sample.md

To see all the options the kramdoc command accepts, pass the -h option to the kramdoc command as follows:

$ kramdoc -h

For example, you can inject attributes (key/value pairs) into the header of the AsciiDoc output document using the -a option.

$ kramdoc -a product-name="ACME Cloud" -a hide-url-scheme sample.md

Another use for attributes is setting the shared images directory, which is covered in the next section.

Configure shared images directory

If the images in the source document share a common directory prefix, such as images/, you can configure the converter to extract that prefix, optionally promoting it to the document header.

Letโ€™s assume you want to convert the following Markdown source:

# Document Title

![Octocat](images/octocat.png)

You can extract the images/ prefix from the image reference and promote this value to the header of the output document by setting the imagesdir attribute:

$ kramdoc -a imagesdir=images sample.md

Setting this attribute will produce the following document:

= Document Title
:imagesdir: images

image::octocat.png[Octocat]

If you want the images/ prefix to be removed altogether and not added to the document header (i.e., an implied prefix), set the --imagesdir option instead:

$ kramdoc --imagesdir=images sample.md

Setting this option will produce the following document:

= Document Title

image::octocat.png[Octocat]

In this scenario, you may need to pass the imagesdir attribute to the AsciiDoc processor when converting the output document so the image is resolved, depending on where the image is stored.

Auto-generate IDs

You can configure kramdoc to automatically generate explicit IDs for each section title (aka heading) that doesnโ€™t already have an ID assigned to it (in the Markdown source). To do so, simply enable the --auto-ids flag:

$ kramdoc --auto-ids sample.md

By default, kramdoc does not add a prefix to the generated ID and uses - as the separator / replacement character. You can change these values using the --auto-id-prefix and --auto-id-separator options, respectively:

$ kramdoc --auto-ids --auto-id-prefix=_ --auto-id-separator=_ sample.md

Since the AsciiDoc processor generates an ID for any section title that doesnโ€™t have one by default, you may decide you want to drop any ID which matches its auto-generated value. You can enable this behavior by adding the --lazy-ids flag:

$ kramdoc --lazy-ids sample.md

The catch is that kramdown/kramdoc and AsciiDoc donโ€™t use the same prefix and separator when generating IDs. So itโ€™s necessary to sync them. The simplest way is to set the --auto-id-prefix and --auto-id-separator values to match those used by AsciiDoc.

$ kramdoc --lazy-ids --auto-id-prefix=_ --auto-id-separator=_ sample.md

If these values do not match the defaults in AsciiDoc, the idprefix and/or idseparator attributes will be assigned explicitly in the generated document.

API

In additional to the command-line interface, Kramdown AsciiDoc also provides a porcelain API (see API docs). We use the term โ€œporcelainโ€ because the API hides the details of registering the converter, preprocessing the Markdown document, parsing the document with kramdown, and calling the converter method to transform the parse tree to AsciiDoc.

The API consists of two static methods in the Kramdoc module:

  • Kramdoc.convert(source, opts) - convert a Markdown string or IO object to AsciiDoc

  • Kramdoc.convert_file(file, opts) - convert a Markdown file object or path to AsciiDoc

๐Ÿ“Ž
Kramdoc is a shorthand for Kramdown::AsciiDoc to align with the name of the CLI.

Both API methods accept the source as the first argument and an options hash as the second.

To convert a Markdown file to AsciiDoc using the Kramdown AsciiDoc API, pass the name of the file to the Kramdoc.convert_file method as follows:

require 'kramdown-asciidoc'

Kramdoc.convert_file 'sample.md'

Like the command-line, Kramdoc.convert_file converts the Markdown file to an adjacent AsciiDoc file calculated by removing the Markdown file extension, .md, and replacing it with the AsciiDoc file extension, .adoc.

If you want to direct the output to a different file, pass the name of that file to the Kramdoc.convert_file method using the :to option as follows:

require 'kramdown-asciidoc'

Kramdoc.convert_file 'sample.md', to: 'result.adoc'

To convert a Markdown string to an AsciiDoc string using the Kramdown AsciiDoc API, pass the string to the Kramdoc.convert method as follows:

require 'kramdown-asciidoc'

markdown = <<~EOS
# Document Title

Hello, world!
EOS

asciidoc = Kramdoc.convert markdown

If you want to direct the output to a file, pass the name of that file to the Kramdoc.convert method using the :to option as follows:

Kramdoc.convert markdown, to: 'result.adoc'

The input string is automatically converted to UTF-8.

For more information about the API, refer to the API documentation.

Development

To help develop Kramdown AsciiDoc, or to simply test-drive the development version, you need to retrieve the source from GitHub. Follow the instructions below to learn how to clone the source and run the application from source (i.e., your clone).

Retrieve the source code

Simply copy the GitHub repository URL and pass it to the git clone command:

$ git clone https://github.com/asciidoctor/kramdown-asciidoc

Next, switch to the project directory:

$ cd kramdown-asciidoc

Prepare RVM (optional)

We recommend using RVM when developing applications with Ruby. We like RVM because it keeps the dependencies required by the project isolated from the rest of your system. Follow the installation instructions on the RVM site to setup RVM and install Ruby.

Once you have RVM setup, switch to the RVM-managed version of Ruby recommended by the project using this command:

$ rvm use

The recommended version of Ruby is defined in the .ruby-version file at the root of the project.

Install the dependencies

The dependencies needed to use Kramdown AsciiDoc are defined in the Gemfile at the root of the project. Youโ€™ll use Bundler to install these dependencies.

To check if you have Bundler available, use the bundle command to query the version installed:

$ bundle --version

If Bundler is not installed, use the gem command to install it.

$ gem install bundler

Then, use the bundle command to install the project dependencies under the project directory:

$ bundle --path=.bundle/gems
๐Ÿ“Ž
You must invoke bundle from the projectโ€™s root directory so it can locate the Gemfile.

Run the tests

The test suite is located in the spec directory. The tests are all based on RSpec.

Most specs are scenarios, located under the spec/scenarios directory. Each scenario consists of a Markdown file that ends in .md (the given), an AsciiDoc file that ends in .adoc (the then), and an optional options file that ends in .opts. The test converts the Markdown to AsciiDoc (the when) and validates the result against whatโ€™s expected. The specification name of each scenario is derived from the directory name.

You can run all of the tests using Rake:

$ bundle exec rake

For more fine-grained control, you can also run the tests directly using RSpec:

$ bundle exec rspec

To run all the scenarios, point RSpec at the spec file:

$ bundle exec rspec spec/scenario_spec.rb

Run individual tests

If you only want to run a single test, or a group of tests, you can do so by tagging the test cases, then filtering the test run using that tag.

Start by adding the wip tag to one or more specifications:

it 'should do something new', wip: true do
  expect(true).to be true
end

Next, run RSpec with the wip flag enabled:

$ bundle exec rspec -t wip

RSpec will only run the specifications that contain this flag.

You can also filter tests by keyword. Letโ€™s assume we want to run all the tests that have wrap in the description. Run RSpec with the example filter:

$ bundle exec rspec -e wrap

RSpec will only run the specifications that have a description containing the text wrap.

Generate code coverage

To generate a code coverage report when running tests using simplecov, set the COVERAGE environment variable as follows when running the tests:

$ COVERAGE=true bundle exec rake

Youโ€™ll see a total coverage score as well as a link to the HTML report in the output. The HTML report helps you understand which lines and branches were missed, if any.

Despite being fast, the downside of using simplecov is that it misses branches. You can use deep-cover to generate a more thorough report. To do so, set the COVERAGE environment variable as follows when running the tests:

$ COVERAGE=deep bundle exec rake

Youโ€™ll see a total coverage score, a detailed coverage report, and a link to HTML report in the output. The HTML report helps you understand which lines and branches were missed, if any.

As an alternative to deep coverโ€™s native HTML reporter, you can also use istanbul / nyc. First, youโ€™ll need to have the nyc command available on your system:

$ npm install -g nyc

or

$ yarn global add nyc

Next, in addition to the COVERAGE environment variable, also set the DEEP_COVER_REPORTER environment variable as follows when running the tests:

$ COVERAGE=deep DEEP_COVER_REPORTER=istanbul bundle exec rake

Youโ€™ll see a total coverage score, a detailed coverage report, and a link to HTML report in the output. The HTML report helps you understand which lines and branches were missed, if any.

Usage

When running the kramdoc command from source, you must prefix the command with bundle exec:

$ bundle exec kramdoc sample.md

To avoid having to do this, or make the kramdoc command available from anywhere, you need to build the development gem and install it.

Alternatives

Authors

Kramdown AsciiDoc was written by Dan Allen.

Copyright ยฉ 2016-2021 OpenDevise Inc. and the individual contributors to Kramdown AsciiDoc. Free use of this software is granted under the terms of the MIT License.

See the LICENSE file for details.

More Repositories

1

asciidoctor

๐Ÿ’Ž A fast, open source text processor and publishing toolchain, written in Ruby, for converting AsciiDoc content to HTML 5, DocBook 5, and other formats.
Ruby
4,437
star
2

asciidoctor-pdf

๐Ÿ“ƒ Asciidoctor PDF: A native PDF converter for AsciiDoc based on Asciidoctor and Prawn, written entirely in Ruby.
Ruby
1,089
star
3

asciidoctor.js

๐Ÿ“œ A JavaScript port of Asciidoctor, a modern implementation of AsciiDoc
JavaScript
664
star
4

asciidoctorj

โ˜• Java bindings for Asciidoctor. Asciidoctor on the JVM!
Java
593
star
5

asciidoctor-diagram

โ†”๏ธ Asciidoctor diagram extension, with support for AsciiToSVG, BlockDiag (BlockDiag, SeqDiag, ActDiag, NwDiag), Ditaa, Erd, GraphViz, Mermaid, Msc, PlantUML, Shaape, SvgBob, Syntrax, UMLet, Vega, Vega-Lite and WaveDrom.
Ruby
434
star
6

asciidoctor-intellij-plugin

AsciiDoc plugin for products on the IntelliJ platform (IDEA, RubyMine, etc)
Java
324
star
7

asciidoctor.org

๐ŸŒ Asciidoctor project site. Composed in AsciiDoc. Baked with Awestruct.
SCSS
308
star
8

asciidoctor-maven-plugin

A Maven plugin that uses Asciidoctor via JRuby to process AsciiDoc source files within the project.
Java
298
star
9

jekyll-asciidoc

๐Ÿ’‰ A Jekyll plugin that converts AsciiDoc source files in your site to HTML pages using Asciidoctor.
Ruby
298
star
10

docker-asciidoctor

๐Ÿšข A Docker image for using the Asciidoctor toolchain to process AsciiDoc content
Shell
294
star
11

asciidoctor-vscode

AsciiDoc support for Visual Studio Code using Asciidoctor
TypeScript
281
star
12

asciidoctor-gradle-plugin

A Gradle plugin that uses Asciidoctor via JRuby to process AsciiDoc source files within the project.
Groovy
272
star
13

asciidoctor-reveal.js

๐Ÿ”ฎ A reveal.js converter for Asciidoctor and Asciidoctor.js. Write your slides in AsciiDoc!
HTML
270
star
14

asciidoctor-epub3

๐Ÿ“˜ Asciidoctor EPUB3 is a set of Asciidoctor extensions for converting AsciiDoc to EPUB3 & KF8/MOBI
Ruby
203
star
15

asciidoctor-browser-extension

โšช An extension for web browsers that converts AsciiDoc files to HTML using Asciidoctor.js.
CSS
202
star
16

asciidoctor-maven-examples

A collection of example projects that demonstrates how to use the Asciidoctor Maven plugin.
Java
187
star
17

asciidoctor-stylesheet-factory

!DEPRECATED! This was the utility project for producing the default stylesheet for the HTML converter in Asciidoctor. The source of the default stylesheet now lives in the main Asciidoctor repository.
SCSS
178
star
18

asciidoctor-gradle-examples

A collection of example projects that demonstrates how to use the Asciidoctor Gradle plugin
Java
145
star
19

atom-asciidoc-preview

โš› AsciiDoc preview for the Atom editor.
CoffeeScript
142
star
20

asciidoctor-kroki

Asciidoctor.js extension to convert diagrams to images using Kroki!
JavaScript
124
star
21

asciidoclet

๐Ÿ“‹ A Javadoc Doclet based on Asciidoctor that lets you write Javadoc in the AsciiDoc syntax.
Java
120
star
22

asciidoctor-fopub

A portable DocBook-to-PDF build command that wraps DocBook XSL and Apache FOP
Java
111
star
23

asciidoctor-latex

๐Ÿ“ Add LaTeX features to AsciiDoc & convert AsciiDoc to LaTeX
Ruby
106
star
24

jekyll-asciidoc-quickstart

A template project for creating AsciiDoc-based websites using Jekyll.
CSS
105
star
25

asciidoctor-extensions-lab

A lab for testing and demonstrating Asciidoctor extensions. Please do not use this code in production. If you want to use one of these extensions in your application, create a new project, import the code, and distribute it as a RubyGem. You can then request to make it a top-level project under the Asciidoctor organization.
Ruby
97
star
26

asciidoctor-confluence

Push Asciidoctor file to Confluence
Ruby
80
star
27

asciidoctor-backends

Backends (i.e., templates) for Asciidoctor, a Ruby port of AsciiDoc.
HTML
66
star
28

asciidoctor-bibtex

Add bibtex citation support for asciidoc documents
Ruby
59
star
29

docgist

Render AsciiDoc documents from Gists, GitHub, DropBox and other remote sources in the browser.
CSS
56
star
30

asciidoc-docs

The source files in this repository served as the initial contribution for the AsciiDoc Language specification project at Eclipse. This repository is now archived.
55
star
31

brackets-asciidoc-preview

Live Preview of AsciiDoc for Adobe Brackets
JavaScript
51
star
32

asciidoctor-bespoke

๐Ÿ…ฑ๏ธ An Asciidoctor converter that generates the HTML component of a Bespoke.js presentation from AsciiDoc.
Slim
49
star
33

sublimetext-asciidoc

AsciiDoc Package for SublimeText 3
Python
49
star
34

asciidoctor-mathematical

An extension for Asciidoctor that converts the content of STEM blocks and inline macros using Mathematical.
Ruby
44
star
35

atom-language-asciidoc

โš› AsciiDoc language package for the Atom editor.
CoffeeScript
42
star
36

asciidoctorj-pdf

AsciidoctorJ PDF bundles the Asciidoctor PDF RubyGem (asciidoctor-pdf) so it can be loaded into the JVM using JRuby.
Java
33
star
37

asciidoctor-firefox-addon

๐Ÿบ An add-on for Mozilla Firefox that converts AsciiDoc files to HTML directly in the browser using Asciidoctor.js.
JavaScript
32
star
38

asciidoctorj-screenshot

A set of AsciidoctorJ extensions for adding automated screenshots to an AsciiDoc document.
Groovy
32
star
39

asciidoctor-tabs

An extension for Asciidoctor that adds a tabs block to the AsciiDoc syntax.
Ruby
29
star
40

asciidoctor-lein-plugin

A Leiningen plugin for generating documentation using Asciidoctor
Clojure
26
star
41

asciidoctor-chart

A set of Asciidoctor extensions that add a chart block and block macro to AsciiDoc for including charts in your AsciiDoc document.
Ruby
25
star
42

asciidoctor-reducer

โš—๏ธ A tool to generate a single AsciiDoc document by expanding all the include directives reachable from the parent document.
Ruby
24
star
43

asciimath

Asciimath parser
Ruby
23
star
44

docbookrx

(An early version of) a DocBook to AsciiDoc converter written in Ruby.
Ruby
22
star
45

gitbucket-asciidoctor-plugin

A GitBucket plug-in that provided AsciiDoc rendering capabilities
Scala
18
star
46

asciidoctor-leanpub-converter

A backend for AsciidoctorJ to generate Leanpub-flavoured Markdown
Groovy
16
star
47

codemirror-asciidoc

AsciiDoc mode for CodeMirror
JavaScript
16
star
48

asciidoc-grammar-prototype

โ›” ARCHIVED: An experiment to create of a formal grammar for the AsciiDoc markup language. Work is being continued at https://github.com/Mogztter/asciidoctor-inline-parser.
Java
16
star
49

asciidoctor-cli.js

The Command Line Interface (CLI) for Asciidoctor.js
JavaScript
15
star
50

asciidoctor-documentation-planning

โ›” ARCHIVED: Planning for the documentation that covers the AsciiDoc syntax, the Asciidoctor processor, and various projects in the Asciidoctor ecosystem.
15
star
51

asciidoctorj-groovy-dsl

A Groovy DSL that allows for easy definition of Asciidoctor extensions
Groovy
14
star
52

gulp-asciidoctor

gulp-asciidoctor
JavaScript
14
star
53

asciidoctor-docs-ui

The project that produces the UI (theme & user interactions) for docs.asciidoctor.org.
CSS
12
star
54

docs.asciidoctor.org

The Antora playbook project (i.e., site manifest) for the Asciidoctor documentation site.
JavaScript
11
star
55

asciidoctor-deck.js

โ›” ARCHIVED: deck.js converter templates for Asciidoctor, implemented in Haml
HTML
11
star
56

asciidoctor-doctest

๐Ÿ”จ Test suite for Asciidoctor backends
Ruby
10
star
57

asciidoctorj-reveal.js

AsciidoctorJ Reveal.js bundles the Asciidoctor Reveal.js RubyGem (asciidoctor-revealjs) so it can be loaded into the JVM using JRuby
Java
10
star
58

asciidoctor-ant

๐Ÿœ Ant task to render Asciidoc documentation
Ruby
9
star
59

asciidoctor-diagram-java

Java
9
star
60

asciidoctorj-diagram

AsciidoctorJ Diagram bundles the Asciidoctor Diagram RubyGem (asciidoctor-diagram) so it can be loaded into the JVM using JRuby.
Java
9
star
61

atom-asciidoc-image-helper

โš› Tool to make insertion of images into AsciiDocs easier in the Atom editor.
CoffeeScript
9
star
62

atom-asciidoc-assistant

โš› AsciiDoc Assistant package for the Atom editor.
Shell
9
star
63

asciidoctor-chrome-editor

โ›” ARCHIVED: AsciiDoc Editor inside Chrome!
JavaScript
8
star
64

guard-asciidoc

Guard::AsciiDoc monitors and automatically renders your AsciiDoc documents using Asciidoctor
Ruby
8
star
65

atom-autocomplete-asciidoc

โš› AsciiDoc language autocompletions
CoffeeScript
7
star
66

asciidoctor-docbook.js

DocBook converter for Asciidoctor.js
JavaScript
7
star
67

asciidoctor-mallard

A Mallard 1.0 converter for Asciidoctor
Ruby
6
star
68

asciidoctor-lazybones

Lazybones templates for Asciidoctor projects
Groovy
5
star
69

asciidoctor-fb2

๐Ÿ“• Asciidoctor FB2 is an Asciidoctor extension for converting AsciiDoc to FB2
Ruby
5
star
70

html-pipeline-asciidoc_filter

โ›” ARCHIVED: An AsciiDoc processing filter for html-pipeline based on Asciidoctor.
Ruby
5
star
71

brand

Brand assets and visual identity for the Asciidoctor project
Shell
4
star
72

opal-node-runtime

โšก๏ธ Opal Runtime specifically designed for Asciidoctor
JavaScript
4
star
73

asciidoctor-template.js

โ›”๏ธ DEPRECATED: Generic template backend for Asciidoctor.js
JavaScript
4
star
74

asciidoctor-deb-mirror

A mirror of the asciidoctor deb (Debian) package build in the pkg-ruby-extras package group. DO NOT PUSH CHANGES TO THIS MIRROR.
Ruby
3
star
75

docker-asciidoctorj

Ensure that AsciidoctorJ can be used by apps into a Java Application Server (WildFly AS for now)
Java
3
star
76

asciidoctor-community-docs

Process, policy, and other shared documentation for the Asciidoctor community of projects.
3
star
77

asciidoctorj-chart

AsciidoctorJ Chart bundles the Asciidoctor Chart RubyGem (asciidoctor-chart) so it can be loaded into the JVM using JRuby.
HTML
3
star
78

asciidoctor-grunt-plugin

A Grunt plugin that uses Asciidoctor via Asciidoctor.js to process AsciiDoc source files within the project.
HTML
2
star
79

asciidoctor-rpm-mirror

A mirror of the package spec for the rubygem-asciidoctor (alias: asciidoctor) rpm. DO NOT PUSH CHANGES TO THIS MIRROR.
Ruby
2
star
80

default-to-asciidoc-chrome-extension

You love AsciiDoc and you want it to be the default option, this extension is for you!
JavaScript
2
star
81

asciidoctorj-epub3

AsciidoctorJ EPUB3 bundles the Asciidoctor EPUB3 RubyGem (asciidoctor-epub3) so it can be loaded into the JVM using JRuby.
Java
1
star
82

asciidoctor-docbook45

!DEPRECATED! An Asciidoctor converter that converts AsciiDoc to DocBook 4.5. This converter is community maintained and will not be released. Use the built-in DocBook 5 converter instead.
Ruby
1
star