cmark

My personal build of CMark ✏️

README.md (6844B)

  1 cmark
  2 =====
  3 
  4 My personal build of CMark ✏️
  5 
  6 `cmark` is the C reference implementation of [CommonMark], a
  7 rationalized version of Markdown syntax with a [spec][the spec].
  8 (For the JavaScript reference implementation, see
  9 [commonmark.js].)
 10 
 11 It provides a shared library (`libcmark`) with functions for parsing
 12 CommonMark documents to an abstract syntax tree (AST), manipulating
 13 the AST, and rendering the document to HTML, groff man, LaTeX,
 14 CommonMark, or an XML representation of the AST.  It also provides a
 15 command-line program (`cmark`) for parsing and rendering CommonMark
 16 documents.
 17 
 18 Advantages of this library:
 19 
 20 - **Portable.**  The library and program are written in standard
 21   C99 and have no external dependencies.  They have been tested with
 22   MSVC, gcc, tcc, and clang.
 23 
 24 - **Fast.** cmark can render a Markdown version of *War and Peace* in
 25   the blink of an eye (127 milliseconds on a ten year old laptop,
 26   vs. 100-400 milliseconds for an eye blink).  In our [benchmarks],
 27   cmark is 10,000 times faster than the original `Markdown.pl`, and
 28   on par with the very fastest available Markdown processors.
 29 
 30 - **Accurate.** The library passes all CommonMark conformance tests.
 31 
 32 - **Standardized.** The library can be expected to parse CommonMark
 33   the same way as any other conforming parser.  So, for example,
 34   you can use `commonmark.js` on the client to preview content that
 35   will be rendered on the server using `cmark`.
 36 
 37 - **Robust.** The library has been extensively fuzz-tested using
 38   [american fuzzy lop].  The test suite includes pathological cases
 39   that bring many other Markdown parsers to a crawl (for example,
 40   thousands-deep nested bracketed text or block quotes).
 41 
 42 - **Flexible.** CommonMark input is parsed to an AST which can be
 43   manipulated programmatically prior to rendering.
 44 
 45 - **Multiple renderers.**  Output in HTML, groff man, LaTeX, CommonMark,
 46   and a custom XML format is supported. And it is easy to write new
 47   renderers to support other formats.
 48 
 49 - **Free.** BSD2-licensed.
 50 
 51 It is easy to use `libcmark` in python, lua, ruby, and other dynamic
 52 languages: see the `wrappers/` subdirectory for some simple examples.
 53 
 54 There are also libraries that wrap `libcmark` for
 55 [Go](https://github.com/rhinoman/go-commonmark),
 56 [Haskell](https://hackage.haskell.org/package/cmark),
 57 [Ruby](https://github.com/gjtorikian/commonmarker),
 58 [Lua](https://github.com/jgm/cmark-lua),
 59 [Perl](https://metacpan.org/release/CommonMark),
 60 [Python](https://pypi.python.org/pypi/paka.cmark),
 61 [R](https://cran.r-project.org/package=commonmark) and
 62 [Scala](https://github.com/sparsetech/cmark-scala).
 63 
 64 Installing
 65 ----------
 66 
 67 Building the C program (`cmark`) and shared library (`libcmark`)
 68 requires [cmake].  If you modify `scanners.re`, then you will also
 69 need [re2c] \(>= 0.14.2\), which is used to generate `scanners.c` from
 70 `scanners.re`.  We have included a pre-generated `scanners.c` in
 71 the repository to reduce build dependencies.
 72 
 73 If you have GNU make, you can simply `make`, `make test`, and `make
 74 install`.  This calls [cmake] to create a `Makefile` in the `build`
 75 directory, then uses that `Makefile` to create the executable and
 76 library.  The binaries can be found in `build/src`.  The default
 77 installation prefix is `/usr/local`.  To change the installation
 78 prefix, pass the `INSTALL_PREFIX` variable if you run `make` for the
 79 first time: `make INSTALL_PREFIX=path`.
 80 
 81 For a more portable method, you can use [cmake] manually. [cmake] knows
 82 how to create build environments for many build systems.  For example,
 83 on FreeBSD:
 84 
 85     mkdir build
 86     cd build
 87     cmake ..  # optionally: -DCMAKE_INSTALL_PREFIX=path
 88     make      # executable will be created as build/src/cmark
 89     make test
 90     make install
 91 
 92 Or, to create Xcode project files on OSX:
 93 
 94     mkdir build
 95     cd build
 96     cmake -G Xcode ..
 97     open cmark.xcodeproj
 98 
 99 The GNU Makefile also provides a few other targets for developers.
100 To run a benchmark:
101 
102     make bench
103 
104 For more detailed benchmarks:
105 
106     make newbench
107 
108 To run a test for memory leaks using `valgrind`:
109 
110     make leakcheck
111 
112 To reformat source code using `clang-format`:
113 
114     make format
115 
116 To run a "fuzz test" against ten long randomly generated inputs:
117 
118     make fuzztest
119 
120 To do a more systematic fuzz test with [american fuzzy lop]:
121 
122     AFL_PATH=/path/to/afl_directory make afl
123 
124 Fuzzing with [libFuzzer] is also supported but, because libFuzzer is still
125 under active development, may not work with your system-installed version of
126 clang. Assuming LLVM has been built in `$HOME/src/llvm/build` the fuzzer can be
127 run with:
128 
129     CC="$HOME/src/llvm/build/bin/clang" LIB_FUZZER_PATH="$HOME/src/llvm/lib/Fuzzer/libFuzzer.a" make libFuzzer
130 
131 To make a release tarball and zip archive:
132 
133     make archive
134 
135 Installing (Windows)
136 --------------------
137 
138 To compile with MSVC and NMAKE:
139 
140     nmake
141 
142 You can cross-compile a Windows binary and dll on linux if you have the
143 `mingw32` compiler:
144 
145     make mingw
146 
147 The binaries will be in `build-mingw/windows/bin`.
148 
149 Usage
150 -----
151 
152 Instructions for the use of the command line program and library can
153 be found in the man pages in the `man` subdirectory.
154 
155 Security
156 --------
157 
158 By default, the library will scrub raw HTML and potentially
159 dangerous links (`javascript:`, `vbscript:`, `data:`, `file:`).
160 
161 To allow these, use the option `CMARK_OPT_UNSAFE` (or
162 `--unsafe`) with the command line program. If doing so, we
163 recommend you use a HTML sanitizer specific to your needs to
164 protect against [XSS
165 attacks](http://en.wikipedia.org/wiki/Cross-site_scripting).
166 
167 Contributing
168 ------------
169 
170 There is a [forum for discussing
171 CommonMark](http://talk.commonmark.org); you should use it instead of
172 github issues for questions and possibly open-ended discussions.
173 Use the [github issue tracker](http://github.com/commonmark/CommonMark/issues)
174 only for simple, clear, actionable issues.
175 
176 Authors
177 -------
178 
179 John MacFarlane wrote the original library and program.
180 The block parsing algorithm was worked out together with David
181 Greenspan. Vicent Marti optimized the C implementation for
182 performance, increasing its speed tenfold.  Kārlis Gaņģis helped
183 work out a better parsing algorithm for links and emphasis,
184 eliminating several worst-case performance issues.
185 Nick Wellnhofer contributed many improvements, including
186 most of the C library's API and its test harness.
187 
188 [benchmarks]: benchmarks.md
189 [the spec]: http://spec.commonmark.org
190 [CommonMark]: http://commonmark.org
191 [cmake]: http://www.cmake.org/download/
192 [re2c]: http://re2c.org
193 [commonmark.js]: https://github.com/commonmark/commonmark.js
194 [Build Status]: https://img.shields.io/travis/commonmark/cmark/master.svg?style=flat
195 [Windows Build Status]: https://ci.appveyor.com/api/projects/status/h3fd91vtd1xfmp69?svg=true
196 [american fuzzy lop]: http://lcamtuf.coredump.cx/afl/
197 [libFuzzer]: http://llvm.org/docs/LibFuzzer.html