目录

MoonMark

MoonMark is a deterministic Markdown-to-HTML renderer written in MoonBit. It targets README-style documents, generated reports, and small documentation fragments that need predictable output and safe HTML escaping.

This project is prepared for the MoonBit open-source ecosystem contribution competition.

Features

  • Block rendering for headings, paragraphs, unordered lists, block quotes, and fenced code blocks.
  • Inline rendering for emphasis, strong text, inline code, and links.
  • HTML escaping for text, code, and link attributes.
  • Heading extraction API for table-of-contents generation.
  • A small runnable CLI demo under cmd/main.
  • Snapshot-style tests that cover the public API.

Quick Start

Install the MoonBit toolchain, then run:

moon check
moon test
moon run cmd/main

Use the library from another package:

let html = @moonmark.render("# Title\n\nA **safe** renderer.")
println(html)

Output:

<h1>Title</h1>
<p>A <strong>safe</strong> renderer.</p>

Supported Markdown

MoonMark intentionally implements a compact subset:

Markdown HTML
# Heading through ###### Heading <h1> through <h6>
Plain text separated by blank lines <p>
- item, * item, + item <ul><li>
> quote <blockquote>
Triple-backtick fences <pre><code>
`code` <code>
*em* <em>
**strong** <strong>
[label](url) <a href="url">label</a>

Non-goals for the current release include full CommonMark compatibility, nested block parsing, ordered lists, tables, and raw HTML passthrough. These are tracked as future extensions so the first release remains easy to audit and verify.

API

pub fn render(markdown : String) -> String
pub fn render_inline(text : String) -> String
pub fn escape_html(text : String) -> String
pub fn headings(markdown : String) -> Array[Heading]
pub fn Heading::level(self : Heading) -> Int
pub fn Heading::text(self : Heading) -> String

Heading::level() and Heading::text() expose the parsed heading metadata.

Examples

let markdown = "# Project\n\n- fast\n- safe\n\nUse `moon test`."
let html = @moonmark.render(markdown)
println(html)
<h1>Project</h1>
<ul>
<li>fast</li>
<li>safe</li>
</ul>
<p>Use <code>moon test</code>.</p>

Project Structure

  • moonmark.mbt: library implementation.
  • moonmark_test.mbt: public API tests.
  • cmd/main: runnable demo program.
  • docs/project-proposal.md: one-page competition proposal draft.
  • docs/submission-checklist.md: final submission checklist.

Competition Scope

The current repository is a complete first milestone: parser, renderer, escaping, heading extraction, tests, CLI demo, CI, README, license, and proposal draft. To better match the competition’s suggested 4k-10k LOC project scale, continue with the planned extensions in docs/submission-checklist.md, especially ordered lists, tables, slug generation, more examples, and Mooncakes publication.

Quality Gates

The repository is expected to pass:

moon check
moon test

GitHub Actions runs the same checks on push and pull request.

License

Apache-2.0.

邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9 京公网安备 11010802047560号