Skip to content

Commit

Permalink
Added LaTeX renderer.
Browse files Browse the repository at this point in the history
* New exported function in API: `cmark_render_latex`.
* Added src/latex.hs.
* Updated README and man page.
* Closes swiftlang#31.
  • Loading branch information
jgm committed Jul 5, 2015
1 parent 46e9ed6 commit afc1b89
Show file tree
Hide file tree
Showing 8 changed files with 635 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ $(ALLTESTS): $(SPEC)

leakcheck: $(ALLTESTS)
rc=0; \
for format in html man xml commonmark; do \
for format in html man xml latex commonmark; do \
for opts in "" "--smart" "--normalize"; do \
echo "cmark -t $$format $$opts" ; \
cat $< | valgrind -q --leak-check=full --dsymutil=yes --error-exitcode=1 $(PROG) -t $$format $$opts >/dev/null || rc=1; \
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ rationalized version of Markdown syntax with a [spec][the spec].

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,
the AST, and rendering the document to HTML, groff man, LaTeX,
CommonMark, or an XML representation of the AST. It also provides a
command-line program (`cmark`) for parsing and rendering CommonMark
documents.
Expand Down Expand Up @@ -43,7 +43,7 @@ Advantages of this library:
- **Flexible.** CommonMark input is parsed to an AST which can be
manipulated programatically prior to rendering.

- **Multiple renderers.** Output in HTML, groff man, CommonMark,
- **Multiple renderers.** Output in HTML, groff man, LaTeX, CommonMark,
and a custom XML format is supported. And it is easy to write new
renderers to support other formats.

Expand Down
4 changes: 2 additions & 2 deletions man/man1/cmark.1
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ file*
.SH "DESCRIPTION"
\fBcmark\fR
converts Markdown formatted plain text to either HTML, groff man,
CommonMark XML, or CommonMark, using the conventions
CommonMark XML, LaTeX, or CommonMark, using the conventions
described in the CommonMark spec. It reads input from \fIstdin\fR
or the specified files (concatenating their contents) and writes
output to \fIstdout\fR.
.SH "OPTIONS"
.TP 12n
.B \-\-to, \-t \f[I]FORMAT\f[]
Specify output format (\f[C]html\f[], \f[C]man\f[], \f[C]xml\f[],
\f[C]commonmark\f[]).
\f[C]latex\f[], \f[C]commonmark\f[]).
.TP 12n
.B \-\-width \f[I]WIDTH\f[]
Specify a column width to which to wrap the output. For no wrapping, use
Expand Down
8 changes: 7 additions & 1 deletion man/man3/cmark.3
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH cmark 3 "June 25, 2015" "LOCAL" "Library Functions Manual"
.TH cmark 3 "July 03, 2015" "LOCAL" "Library Functions Manual"
.SH
NAME
.PP
Expand Down Expand Up @@ -479,6 +479,12 @@ Render a \f[I]node\f[] tree as a groff man page, without the header.
.PP
Render a \f[I]node\f[] tree as a commonmark document.

.PP
\fIchar *\f[] \fBcmark_render_latex\f[](\fIcmark_node *root\f[], \fIint options\f[], \fIint width\f[])

.PP
Render a \f[I]node\f[] tree as a LaTeX document.

.PP
.nf
\fC
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ set(LIBRARY_SOURCES
xml.c
html.c
commonmark.c
latex.c
houdini_href_e.c
houdini_html_e.c
houdini_html_u.c
Expand Down
5 changes: 5 additions & 0 deletions src/cmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,11 @@ char *cmark_render_man(cmark_node *root, int options);
CMARK_EXPORT
char *cmark_render_commonmark(cmark_node *root, int options, int width);

/** Render a 'node' tree as a LaTeX document.
*/
CMARK_EXPORT
char *cmark_render_latex(cmark_node *root, int options, int width);

/** Default writer options.
*/
#define CMARK_OPT_DEFAULT 0
Expand Down
Loading

0 comments on commit afc1b89

Please sign in to comment.