All Projects → sparsetech → cmark-scala

sparsetech / cmark-scala

Licence: other
Parse, manipulate and render CommonMark in Scala Native

Programming Languages

scala
5932 projects

Projects that are alternatives of or similar to cmark-scala

koino
CommonMark + GFM compatible Markdown parser and renderer
Stars: ✭ 81 (+523.08%)
Mutual labels:  commonmark
swift-markdownkit
A framework for parsing and transforming text in Markdown format written in Swift 5 for macOS, iOS, and Linux. The supported syntax is based on the CommonMark specification. The framework defines an abstract syntax for Markdown, provides a parser for parsing strings into abstract syntax trees, and comes with generators for creating HTML and attr…
Stars: ✭ 64 (+392.31%)
Mutual labels:  commonmark
comark
Comark is CommonMark (Markdown) library for Haxe
Stars: ✭ 14 (+7.69%)
Mutual labels:  commonmark
motion-markdown-it
Ruby/RubyMotion version of Markdown-it (CommonMark compliant parser and extendable)
Stars: ✭ 42 (+223.08%)
Mutual labels:  commonmark
clj-pdf-markdown
Library for rendering markdown to clj-pdf data-structure syntax.
Stars: ✭ 20 (+53.85%)
Mutual labels:  commonmark
front-matter
The most featured front matter (yaml, json, neon, toml) parser and dumper for PHP.
Stars: ✭ 23 (+76.92%)
Mutual labels:  commonmark
Markdownlint
A Node.js style checker and lint tool for Markdown/CommonMark files.
Stars: ✭ 2,828 (+21653.85%)
Mutual labels:  commonmark
smu
Simple MarkUp - markdown/commonmark like syntax
Stars: ✭ 21 (+61.54%)
Mutual labels:  commonmark
paka.cmark
Lightweight CFFI-based Python bindings to cmark library (CommonMark implementation in C).
Stars: ✭ 23 (+76.92%)
Mutual labels:  commonmark
CommonMarkEmoji
CommonMark extension adds UTF-8 emoji with Github tag for the `league/commonmark` PHP Markdown parsing engine, based on the CommonMark spec.
Stars: ✭ 17 (+30.77%)
Mutual labels:  commonmark
markdig.wpf
A WPF library for xoofx/markdig https://github.com/xoofx/markdig
Stars: ✭ 133 (+923.08%)
Mutual labels:  commonmark
markdown-toolbar
A clone of GitHub's markdown toolbar
Stars: ✭ 19 (+46.15%)
Mutual labels:  commonmark
laravel-etched-blade
A package that uses blade templates to control how markdown is converted to HTML inside Laravel, as well as providing support for markdown files to Laravel views.
Stars: ✭ 19 (+46.15%)
Mutual labels:  commonmark
markdown
The first generation of Markdown rendering for R (born in 2012). Now R Markdown usually means the *r*markdown package instead of *markdown*. The repo for the former is at https://github.com/rstudio/rmarkdown
Stars: ✭ 64 (+392.31%)
Mutual labels:  commonmark
thegreatmarkdown
《了不起的 Markdown》
Stars: ✭ 44 (+238.46%)
Mutual labels:  commonmark
Lute
🎼 一款对中文语境优化的 Markdown 引擎,支持 Go 和 JavaScript。A structured Markdown engine that supports Go and JavaScript.
Stars: ✭ 222 (+1607.69%)
Mutual labels:  commonmark
markdom
A markdown parser for laravel for making beautiful html
Stars: ✭ 42 (+223.08%)
Mutual labels:  commonmark
guile-commonmark
Implementation of CommonMark for Guile
Stars: ✭ 31 (+138.46%)
Mutual labels:  commonmark
Publish.jl
A universal document authoring package for Julia.
Stars: ✭ 86 (+561.54%)
Mutual labels:  commonmark
commonmark-attributes-extension
The Attributes extension adds a syntax to define attributes on the various HTML elements in markdown’s output.
Stars: ✭ 32 (+146.15%)
Mutual labels:  commonmark

cmark-scala provides Scala Native bindings for cmark. cmark allows to parse, manipulate and render CommonMark documents.

The bindings were directly derived from cmark.h. Comments were retained and adapted if necessary. The naming of functions and their encapsulation follows Scala's conventions. Note that *_new functions were renamed to create as to prevent name collisions with the eponymous Scala keyword.

Example

import cmark._
import scalanative.unsafe._
import scalanative.unsigned._

var level = -1
def onNode(eventType: EventType, node: Ptr[Node]): Unit = {
  eventType match {
    case EventType.Enter => level += 1
    case EventType.Exit  => level -= 1
  }

  val levelStr = "  " * level
  val startLine = Node.getStartLine(node)
  val endLine   = Node.getEndLine(node)

  Node.getType(node) match {
    case NodeType.Text =>
      val text = fromCString(Node.getLiteral(node))
      println(s"${levelStr}text node @ line $startLine-$endLine: $text")

    case _ =>
      val nodeTypeStr = fromCString(Node.getTypeString(node))
      println(s"$levelStr$nodeTypeStr node @ $startLine-$endLine")
  }
}

val test =
  """# Chapter
    |## Section
    |### Sub-section
    |
    |Hello World from *cmark-scala*!
  """.stripMargin

println("cmark version: " + fromCString(cmark.versionString()))
println()

val docNode = Parser.parseDocument(
  toCString(test), test.length.toULong, Options.SourcePosition)
val iter = Iter.create(docNode)
var evType = Iter.next(iter)
while (evType != EventType.Done) {
  onNode(evType, Iter.getNode(iter))
  evType = Iter.next(iter)
}
Iter.free(iter)

val html = fromCString(Render.html(docNode, Options.Default))
println()
println(html)

Node.free(docNode)

Output:

cmark version: 0.27.1

document node @ 1-6
  heading node @ 1-1
    text node @ line 0-0: Chapter
  heading node @ 1-1
    heading node @ 2-2
      text node @ line 0-0: Section
    heading node @ 2-2
      heading node @ 3-3
        text node @ line 0-0: Sub-section
      heading node @ 3-3
        paragraph node @ 5-5
          text node @ line 0-0: Hello World from 
            emph node @ 0-0
              text node @ line 0-0: cmark-scala
            emph node @ 0-0
              text node @ line 0-0: !
            paragraph node @ 5-5
          document node @ 1-6

<h1>Chapter</h1>
<h2>Section</h2>
<h3>Sub-section</h3>
<p>Hello World from <em>cmark-scala</em>!</p>

Dependency

libraryDependencies += "tech.sparse" %%  "cmark-scala" % "0.2.0-SNAPSHOT"

Install Native Library

In order to use this library you need to install cmark which installs libcmark.

  • macOS users can use the following command.
$ brew install cmark
  • Linux/Ubuntu users can use the following commands.
$ sudo apt update
$ sudo apt install cmark

License

cmark-scala is licensed under the terms of the Apache v2.0 license. Its function interfaces and comments were derived from cmark.h, which is licensed under BSD-2-Clause.

Authors

  • Tim Nieradzik
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].