cmark
| Kind | ffi-c |
|---|---|
| Capabilities | ffi |
| Categories | text-processing ffi |
| Keywords | markdown commonmark cmark parser html |
CommonMark Markdown parser and renderer bindings for Kit
Files
| File | Description |
|---|---|
.editorconfig | Editor formatting configuration |
.gitignore | Git ignore rules for build artifacts and dependencies |
.tool-versions | asdf tool versions (Zig, Kit) |
LICENSE | MIT license file |
README.md | This file |
c/kit_cmark.c | C FFI wrapper |
c/kit_cmark.h | C header for FFI wrapper |
examples/basic.kit | Basic usage example |
kit.toml | Package manifest with metadata and dependencies |
src/cmark.kit | Kit Cmark - CommonMark Markdown parser and renderer |
tests/cmark.test.kit | Tests for cmark |
Dependencies
No Kit package dependencies.
Installation
kit add gitlab.com/kit-lang/packages/kit-cmark.gitSystem Requirements
| Platform | Command |
|---|---|
| macOS | brew install cmark |
| Ubuntu | sudo apt install libcmark-dev |
| Fedora | sudo 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
mainDevelopment
Running Examples
Run examples with the interpreter:
kit run examples/basic.kitCompile examples to a native binary:
kit build examples/basic.kit && ./basicRunning Tests
Run the test suite:
kit testRun the test suite with coverage:
kit test --coverageRunning kit dev
Run the standard development workflow (format, check, test):
kit devThis will:
- Format and check source files in
src/ - Run tests in
tests/with coverage
Generating Documentation
Generate API documentation from doc comments:
kit docNote: Kit sources with doc comments (##) will generate HTML documents in docs/*.html
Cleaning Build Artifacts
Remove generated files, caches, and build artifacts:
kit task cleanNote: Defined in kit.toml.
Local Installation
To install this package locally for development:
kit installThis 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 xmlto-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 manto-latex
Convert Markdown to LaTeX format.
Parameters:
Returns:
String -> String
latex = to-latex "# Introduction\n\nSome math: $E = mc^2$"
println latexversion
Get the cmark library version as a string.
Returns:
String
println ("cmark version: " ++ version())