cmark

CommonMark Markdown parser and renderer bindings for Kit

Files

FileDescription
.editorconfigEditor formatting configuration
.gitignoreGit ignore rules for build artifacts and dependencies
.tool-versionsasdf tool versions (Zig, Kit)
LICENSEMIT license file
README.mdThis file
c/kit_cmark.cC FFI wrapper
c/kit_cmark.hC header for FFI wrapper
examples/basic.kitBasic usage example
kit.tomlPackage manifest with metadata and dependencies
src/cmark.kitKit Cmark - CommonMark Markdown parser and renderer
tests/cmark.test.kitTests for cmark

Dependencies

No Kit package dependencies.

Installation

kit add gitlab.com/kit-lang/packages/kit-cmark.git

System Requirements

PlatformCommand
macOSbrew install cmark
Ubuntusudo apt install libcmark-dev
Fedorasudo dnf install cmark-devel

Usage

import Kit.CMark as Cmark

main = fn =>
  println ("cmark version: " ++ Cmark.version())

  md = "# Hello, Kit!\n\nThis is **bold** and *italic*.\n\n- Item one\n- Item two\n"

  # Markdown to HTML
  html = Cmark.to-html md
  println html

  # Markdown to normalized CommonMark
  cm = Cmark.to-commonmark md
  println cm

  # Markdown to man page format
  man = Cmark.to-man md
  println man

  # Markdown to LaTeX
  latex = Cmark.to-latex md
  println latex

main

Development

Running Examples

Run examples with the interpreter:

kit run examples/basic.kit

Compile examples to a native binary:

kit build examples/basic.kit && ./basic

Running Tests

Run the test suite:

kit test

Run the test suite with coverage:

kit test --coverage

Running kit dev

Run the standard development workflow (format, check, test):

kit dev

This will:

  1. Format and check source files in src/
  2. Run tests in tests/ with coverage

Generating Documentation

Generate API documentation from doc comments:

kit doc

Note: Kit sources with doc comments (##) will generate HTML documents in docs/*.html

Cleaning Build Artifacts

Remove generated files, caches, and build artifacts:

kit task clean

Note: Defined in kit.toml.

Local Installation

To install this package locally for development:

kit install

This installs the package to ~/.kit/packages/@kit/cmark/, making it available for import as Kit.CMark in other projects.

License

This package is released under the MIT License - see LICENSE for details.

cmark is released under the BSD 2-Clause License.

Exported Functions & Types

to-html

Convert Markdown to HTML.

Parameters:

Returns:

String -> String

html = to-html "# Hello\n\nWorld"
# html = "<h1>Hello</h1>\n<p>World</p>\n"

to-xml

Convert Markdown to an XML AST representation.

Produces an XML document representing the parsed abstract syntax tree. Useful for debugging or programmatic analysis of Markdown documents.

Parameters:

Returns:

String -> String

xml = to-xml "# Hello"
println xml

to-commonmark

Normalize Markdown to canonical CommonMark format.

Parses and re-renders the Markdown, producing a normalized output that follows CommonMark conventions. Useful for canonicalizing Markdown from different sources.

Parameters:

Returns:

String -> String

normalized = to-commonmark "#Hello\n*bold*"
# normalized = "# Hello\n\n*bold*\n"

to-man

Convert Markdown to man page (groff) format.

Parameters:

Returns:

String -> String

man = to-man "# MyTool\n\nA useful tool."
println man

to-latex

Convert Markdown to LaTeX format.

Parameters:

Returns:

String -> String

latex = to-latex "# Introduction\n\nSome math: $E = mc^2$"
println latex

version

Get the cmark library version as a string.

Returns:

String

println ("cmark version: " ++ version())