Help language development. Donate to The Perl Foundation

CommonMark cpan:JGOFF last updated on 2018-03-04


Build Status


Interface to the libcmark CommonMark parser


use CommonMark;

say"Hello, world!");
# "<p>Hello, world!</p>"

say CommonMark.version-string;
# 0.28.3


CommonMark is Markdown with a proper spec - It should render most Markdown files the same; it nails down some edge cases, and specifies byte encodings.

You'll want to call .to-html($text) to convert markdown to HTML. The library itself also supports XML, LaTeX, and nroff/troff formats, but I haven't seen where it's tested. Check out the Perl 6 source for more details there.

CommonMark class


Return HTML from CommonMark format. This is likely the only method you'll use. There's a lower-level interface that'll let you interrogate the library at the individual node level, look at the source for more inspiration.

Returns a 32-bit int containing the version number.

From the documetation:

* Bits 16-23 contain the major version.
* Bits 8-15 contain the minor version.
* Bits 0-7 contain the patchlevel.

Returns the library version in text form.

Returns a CommonMark::Node root of the document.

CommonMark::Node class

Create a new CommonMark node with the specified type - this isn't well-documented in the library, so please read the source.

Return this node's successor in the multiply-linked list

Return this node's predecessor in the multiply-linked list

Return this node's parent in the multiply-linked list

Return this node's first child within the multiply-linked list

Return this node's last child within the multiply-linked list

Return this node's user data (generic pointer)

Set user data pointer

Return this node's type number

Return this node's type as a string

Return this node's literal string

Set this node's literal string

Return this node's heading level

Set this node's heading level

Return this node's list type

Set this node's list type

Return this node's list delimiter

Set this node's list delimiter

Return this node's list start

Set this node's list start

Return this node's list tightness

Set this node's list tightness

Return this node's fence information

Set this node's fence information

Return this node's URL content

Set this node's URL content

Return this node's title

Set this node's title

Return this node's on-enter string

Set this node's on-enter string

Return this node's on-exit string

Set this node's on-exit string

Return this node's starting line

Return this node's starting column

Return this node's end line

Return this node's end column

Unlink this node from the tree.

Insert $node before this node

Insert $node after this node

Replace this node with $node

Prepend $node below this node

Append $node below this node

Consolidate the text nodes in this node

Render this node as XML, with the appropriate options $options

Render this node as HTML, with the appropriate options $options

Render this node as a manpage, with the appropriate options $options, $width

Render this node as the original CommonMark text, with the appropriate options $options and $idth

Render this node as LaTeX, with the appropriate options $options, $width

Check this node with file descriptor $file-ID

CommonMark::Iterator class

Return the next item in this iterator

Return the current node for the iterator

Return the current event type

Return the root for the iterator

Reset the iterator to node $current, type $event-type

CommonMark::Parser class

Feed the buffer to the parser

Finish parsing the document