GitHub's fork of cmark, a CommonMark parsing and rendering library and program in C
Перейти к файлу
John MacFarlane 520d5a6fc6 Check return status of utf8proc_iterate. Closes #27.
If unicode parsing gives an error condition, we just skip the
rest of the string without rendering anything and proceed.
I'm not sure if that's the best way to handle this, but
garbage in, garbage out.

Note: this bug was found using american fuzzy lop.
2015-04-15 16:11:12 -07:00
api_test Added options parameter to cmark_markdown_to_html. 2015-03-15 16:41:59 -07:00
bench Revised benchmark procedure. 2014-11-22 13:02:01 -08:00
data Initial commit 2014-08-13 22:56:32 -07:00
man Updated man page. 2015-03-30 13:08:30 -07:00
src Check return status of utf8proc_iterate. Closes #27. 2015-04-15 16:11:12 -07:00
test Fixed roundtrip.sh. 2015-03-29 23:17:11 -07:00
tools Removed spec-specific files (DTD, spec generation tools). 2015-01-24 21:10:44 -08:00
wrappers Moved python, rb, lua wrappers to wrappers subdirectory. 2015-01-12 20:30:36 -08:00
.editorconfig Removed JS specific stuff from .editorconfig. 2015-01-24 12:50:02 -08:00
.gitignore Ignore pyc files 2014-12-17 14:17:43 +01:00
.travis.yml Travis: only do roundtrip test on linux. 2015-03-29 23:22:03 -07:00
CMakeLists.txt Bump version to 0.18.3. 2015-04-01 09:26:04 -07:00
COPYING COPYING - added license for test/spec.txt and python code in test/. 2015-01-25 11:22:19 -08:00
FindAsan.cmake Added 'Asan' build type. 2015-02-19 10:34:34 -08:00
Makefile Added afl to .PHONY in Makefile. 2015-04-14 21:08:38 -07:00
Makefile.nmake Added cmark.3 man page to repository and archive. 2015-01-11 10:48:59 -08:00
README.md Update README on output formats. 2015-03-21 17:36:02 -07:00
benchmarks.md Updated benchmarks. 2015-02-18 15:52:21 -08:00
changelog.txt Updated changelog. 2015-04-01 09:25:47 -07:00
nmake.bat Add Makefile and wrapper for nmake 2014-11-16 22:42:27 +01:00
toolchain-mingw32.cmake Added mingw target for compiling windows exe and dll. 2014-11-14 08:28:53 -08:00

README.md

CommonMark

CommonMark is a rationalized version of Markdown syntax, with a spec and BSD-licensed reference implementations in C and JavaScript.

Try it now!

For more information, see http://commonmark.org.

This repository contains the C reference implementation. It provides a shared library (libcmark) with functions for parsing CommonMark documents to an abstract syntax tree (AST), manipulating the AST, and rendering the document to HTML, groff man, CommonMark, or an XML representation of the AST. It also provides a command-line program (cmark) for parsing and rendering CommonMark documents.

The library and program are written in standard C99 and have no library dependencies. The parser is very fast, on par with sundown: see the benchmarks.

It is easy to use libcmark in python, lua, ruby, and other dynamic languages: see the wrappers/ subdirectory for some simple examples.

Installing

Building the C program (cmark) and shared library (libcmark) requires cmake. If you modify scanners.re, then you will also need re2c, which is used to generate scanners.c from scanners.re. We have included a pre-generated scanners.c in the repository to reduce build dependencies.

If you have GNU make, you can simply make, make test, and make install. This calls cmake to create a Makefile in the build directory, then uses that Makefile to create the executable and library. The binaries can be found in build/src. The default installation prefix is /usr/local. To change the installation prefix, pass the INSTALL_PREFIX variable if you run make for the first time: make INSTALL_PREFIX=path.

For a more portable method, you can use cmake manually. cmake knows how to create build environments for many build systems. For example, on FreeBSD:

mkdir build
cd build
cmake ..  # optionally: -DCMAKE_INSTALL_PREFIX=path
make      # executable will be created as build/src/cmark
make test
make install

Or, to create Xcode project files on OSX:

mkdir build
cd build
cmake -G Xcode ..
open cmark.xcodeproj

The GNU Makefile also provides a few other targets for developers. To run a benchmark:

make bench

To run a "fuzz test" against ten long randomly generated inputs:

make fuzztest

To run a test for memory leaks using valgrind:

make leakcheck

To reformat source code using astyle:

make astyle

To make a release tarball and zip archive:

make archive

Installing (Windows)

To compile with MSVC and NMAKE:

nmake

You can cross-compile a Windows binary and dll on linux if you have the mingw32 compiler:

make mingw

The binaries will be in build-mingw/windows/bin.

Usage

Instructions for the use of the command line program and library can be found in the man pages in the man subdirectory.

A note on security: This library does not attempt to sanitize link attributes or raw HTML. If you use it in applications that accept untrusted user input, you must run the output through an HTML sanitizer to protect against XSS attacks.

Contributing

There is a forum for discussing CommonMark; you should use it instead of github issues for questions and possibly open-ended discussions. Use the github issue tracker only for simple, clear, actionable issues.

Authors

John MacFarlane wrote the original library and program. The block parsing algorithm was worked out together with David Greenspan. Vicent Marti optimized the C implementation for performance, increasing its speed tenfold. Kārlis Gaņģis helped work out a better parsing algorithm for links and emphasis, eliminating several worst-case performance issues. Nick Wellnhofer contributed many improvements, including most of the C library's API and its test harness.