A fast, minimal Scala 3 library for parsing CommonMark 0.31.2 Markdown.
Cross‑platform support: JVM, Scala.js, and Scala Native.
- Core CommonMark 0.31.2 compliance: ATX & Setext headings, lists, block quotes, fenced & indented code, HTML blocks, thematic breaks, reference definitions
- Inline parsing: emphasis, strong, code spans, inline & reference links/images, autolinks, raw HTML, entity references
- HTML entity decoding outside of code, with literal preservation inside code spans/blocks
- HTML rendering: safe escaping for
<
,>
,&
, and"
; outputs standard tags (<p>
,<h1–6>
,<ul>
,<ol>
,<pre><code>
,<blockquote>
,<a>
,<img>
, etc.) - Zero runtime dependencies and lightweight API
Try out the Markdown parser in your browser using the Dingus.
Add to your build.sbt
:
libraryDependencies += "io.github.edadma" %% "markdown" % "0.0.21"
import io.github.edadma.markdown._
val md = """
# Hello, CommonMark!
This is **bold**, *italic*, and `code`.
"""
val html = renderToHTML(md)
println(html)
The core AST is defined by:
sealed trait Node
case class Document(children: List[Block]) extends Node
sealed trait Block extends Node
case class Paragraph(inlines: List[Inline]) extends Block
case class Heading(level: Int, inlines: List[Inline]) extends Block
case class Code(content: String, info: Option[String]) extends Block
case class BlockQuote(children: List[Block]) extends Block
case class ListBlock(data: ListData, items: List[ListItem]) extends Block
// … Inline types: Text, Emphasis, Strong, CodeSpan, Link, Image, AutoLink, RawHTML, etc.
- Multi-line link reference definitions (v0.0.2)
- Extensions: footnotes, tables, task lists
- Fork this repository
- Create a branch (
git checkout -b feat/awesome
) - Commit changes (
git commit -m "Add awesome feature"
) - Push and open a Pull Request
Please run sbt test
and add tests for any new functionality.
This project is licensed under the ISC License. See LICENSE for details.