KaisarCode

mdp.c

mdp.c - Markdown Parser

mdp.c parses Markdown text, extracts optional YAML frontmatter, and renders the body as an HTML fragment through a small C library and stdin/stdout CLI.


CLI

Examples

Render Markdown as HTML:

echo '# Hello' | ./bin/x86_64/linux/mdp

Extract frontmatter only:

echo $'---\ntitle: Home\n---\n# Hello' | ./bin/x86_64/linux/mdp --meta

Extract body without frontmatter:

echo $'---\ntitle: Home\n---\n# Hello' | ./bin/x86_64/linux/mdp --body

Parameters

FlagDescription
--htmlRender Markdown body as HTML fragment (default)
--bodyOutput raw body without frontmatter
--metaOutput raw frontmatter block
-h, --helpShow help and usage
-v, --versionShow version

Frontmatter

An optional metadata block delimited by --- at the top of the document is supported. The block content is raw text accessible via --meta and is excluded from body rendering.

---
title: My Page
date: 2026-05-07
---

# My Page

Both LF and CRLF line endings are supported in the frontmatter delimiter.


Supported Markdown

FeatureSyntax
Headings# H1 through ###### H6
ParagraphPlain text lines
Bold**text**
Italic*text*
Inline code code
Link[label](url)
Image![alt](url)
Linked image[![alt](img)](url)
Unordered list- item or * item
Blockquote> text
Fenced code block ...
Horizontal rule--- or ***

Public API

#include "mdp.h"

kc_mdp_t *ctx = kc_mdp_open();

kc_mdp_set_mode(ctx, KC_MDP_MODE_HTML);
kc_mdp_exec(ctx, "# Hello", stdout);

kc_mdp_close(ctx);

Lifecycle

  • kc_mdp_open() - allocates and returns a new context owned by the caller.
  • kc_mdp_set_mode() - selects HTML, body, or metadata output.
  • kc_mdp_mode() - converts a CLI mode name to an API mode constant.
  • kc_mdp_exec() - parses a null-terminated Markdown string and writes output to the caller-provided stream.
  • kc_mdp_close() - releases the context.

Build

Compiled artifacts are generated under bin/{arch}/{platform}/ for the host architecture running the build.

make clean && make

The host build emits:

bin/{arch}/{platform}/mdp
bin/{arch}/{platform}/libmdp.a
bin/{arch}/{platform}/libmdp.so

Windows builds emit:

bin/{arch}/windows/mdp.exe
bin/{arch}/windows/libmdp.dll
bin/{arch}/windows/libmdp.dll.a

Multiarch Builds

The project is prepared to build artifacts for multiple architectures under bin/{arch}/{platform}/. A plain make builds only the current host architecture, while the targets below build the full matrix or a specific target.

make all
make x86_64/linux
make x86_64/windows
make i686/linux
make i686/windows
make aarch64/linux
make aarch64/android
make armv7/linux
make armv7/android
make armv7hf/linux
make riscv64/linux
make powerpc64le/linux
make mips/linux
make mipsel/linux
make mips64el/linux
make s390x/linux
make loongarch64/linux

License

GPLv3

This project is distributed under the GNU General Public License version 3 (GPLv3).


Repo

GitHub: kaisarcode/mdp.c