diff options
| -rw-r--r-- | Makefile | 87 | ||||
| -rw-r--r-- | README.md | 37 | ||||
| -rw-r--r-- | src/inlines.c | 4 | ||||
| -rw-r--r-- | wrapper.rb | 14 | 
4 files changed, 84 insertions, 58 deletions
@@ -29,49 +29,54 @@ debug:  	cmake .. -DCMAKE_BUILD_TYPE=Debug; \  	cmake --build . -tarball: +tarball: spec.html  	rm -rf $(PKGDIR); \  	mkdir -p $(PKGDIR)/man/man1; \  	cp -r src $(PKGDIR)/; \ +	cp spec.html $(PKGDIR); \  	cp CMakeLists.txt $(PKGDIR); \ +	perl -ne '$$p++ if /^### JavaScript/; print if (!$$p)' Makefile > $(PKGDIR)/Makefile; \  	cp man/man1/cmark.1 $(PKGDIR)/man/man1/; \  	cp README.md LICENSE spec.txt runtests.pl $(PKGDIR)/; \ -	tar cvzf cmark-$(SPECVERSION).tar.gz $(PKGDIR) +	tar czf cmark-$(SPECVERSION).tar.gz $(PKGDIR); \ +	rm -rf $(PKGDIR)  clean:  	rm -rf $(BUILDDIR)  $(PROG): all +$(SRCDIR)/case_fold_switch.inc: $(DATADIR)/CaseFolding-3.2.0.txt +	perl mkcasefold.pl < $< > $@ +  man/man1/cmark.1: man/cmark.1.md  	pandoc $< -o $@ -s -t man -README.html: README.md template.html -	pandoc --template template.html -S -s -t html5 -o $@ $< - -spec: test spec.html +test: $(SPEC) +	perl runtests.pl $< $(PROG) -spec.md: $(SPEC) -	perl spec2md.pl < $< > $@ +testlib: $(SPEC) +	perl runtests.pl $< ./wrapper.py -spec.html: spec.md template.html -	pandoc --no-highlight --number-sections --template template.html -s --toc -S $< | \ -	perl -pe 's/a href="@([^"]*)"/a id="\1" href="#\1" class="definition"/g' | \ -	perl -pe 's/␣/<span class="space"> <\/span>/g' \ -	> $@ +leakcheck: $(PROG) +	cat leakcheck.md | valgrind --leak-check=full --dsymutil=yes $(PROG) +fuzztest: +	{ for i in `seq 1 10`; do \ +	  cat /dev/urandom | head -c $(FUZZCHARS) | iconv -f latin1 -t utf-8 | tee fuzz-$$i.txt | \ +		/usr/bin/env time -p $(PROG) >/dev/null && rm fuzz-$$i.txt ; \ +	done } 2>&1 | grep 'user\|abnormally' -spec.pdf: spec.md template.tex specfilter.hs -	pandoc -s $< --template template.tex \ -	   --filter ./specfilter.hs -o $@ --latex-engine=xelatex --toc \ -	   --number-sections -V documentclass=report -V tocdepth=2 \ -	   -V classoption=twosides +operf: $(PROG) +	operf $(PROG) <$(BENCHINP) >/dev/null -test: $(SPEC) -	perl runtests.pl $< $(PROG) +distclean: clean +	-rm -f js/commonmark.js +	-rm -rf *.dSYM +	-rm -f README.html +	-rm -f spec.md fuzz.txt spec.html -testlib: $(SPEC) -	perl runtests.pl $< ./wrapper.py +### JavaScript ###  js/commonmark.js: js/lib/index.js ${JSMODULES}  	browserify --standalone commonmark $< -o $@ @@ -85,35 +90,33 @@ jshint:  benchjs:  	node js/bench.js ${BENCHINP} -$(SRCDIR)/case_fold_switch.inc: $(DATADIR)/CaseFolding-3.2.0.txt -	perl mkcasefold.pl < $< > $@ +npm: +	cd js; npm publish  dingus: js/commonmark.js  	echo "Starting dingus server at http://localhost:9000" && python -m SimpleHTTPServer 9000 -leakcheck: $(PROG) -	cat leakcheck.md | valgrind --leak-check=full --dsymutil=yes $(PROG) +### Spec ### -operf: $(PROG) -	operf $(PROG) <$(BENCHINP) >/dev/null +spec.md: $(SPEC) +	perl spec2md.pl < $< > $@ -fuzztest: -	{ for i in `seq 1 10`; do \ -	  cat /dev/urandom | head -c $(FUZZCHARS) | iconv -f latin1 -t utf-8 | tee fuzz-$$i.txt | \ -		/usr/bin/env time -p $(PROG) >/dev/null && rm fuzz-$$i.txt ; \ -	done } 2>&1 | grep 'user\|abnormally' +spec.html: spec.md template.html +	pandoc --no-highlight --number-sections --template template.html -s --toc -S $< | \ +	perl -pe 's/a href="@([^"]*)"/a id="\1" href="#\1" class="definition"/g' | \ +	perl -pe 's/␣/<span class="space"> <\/span>/g' \ +	> $@ + +spec.pdf: spec.md template.tex specfilter.hs +	pandoc -s $< --template template.tex \ +	   --filter ./specfilter.hs -o $@ --latex-engine=xelatex --toc \ +	   --number-sections -V documentclass=report -V tocdepth=2 \ +	   -V classoption=twosides + +### Website ###  update-site: spec.html js/commonmark.js  	make -C $(SITE) update  upload-site: spec.html  	make -C $(SITE) upload - -npm: -	cd js; npm publish - -distclean: clean -	-rm -f js/commonmark.js -	-rm -rf *.dSYM -	-rm -f README.html -	-rm -f spec.md fuzz.txt spec.html @@ -10,14 +10,14 @@ implementations in C and JavaScript.  The implementations  ------------------- -The C implementation provides both a library and a standalone program -`cmark` that converts CommonMark to HTML.  It is written in standard C99 -and has no library dependencies.  The parser is very fast, on par with -[sundown](https://github.com/vmg/sundown).  Some benchmarks (on -an ancient Thinkpad running Intel Core 2 Duo at 2GHz, measured using -`time` and parsing a ~500K book, the English version of [*Pro -Git*](https://github.com/progit/progit/tree/master/en) by -Scott Chacon and Ben Straub): +The C implementation provides both a shared library (`libcmark`) and a +standalone program `cmark` that converts CommonMark to HTML.  It is +written in standard C99 and has no library dependencies.  The parser is +very fast, on par with [sundown](https://github.com/vmg/sundown).  Some +benchmarks (on an ancient Thinkpad running Intel Core 2 Duo at 2GHz, +measured using `time` and parsing a ~500K book, the English version of +[*Pro Git*](https://github.com/progit/progit/tree/master/en) by Scott +Chacon and Ben Straub):  |Implementation | Time  |  Factor|  |---------------|-------|--------| @@ -30,6 +30,8 @@ Scott Chacon and Ben Straub):  | **cmark**     | 0.020s|     1.1|  | sundown       | 0.018s|     1.0| +It is easy to use `libcmark` in python or ruby code:  see `wrapper.py` +and `wrapper.rb` in the repository for simple examples.  The JavaScript implementation is a single JavaScript file, with  no dependencies, that can be linked to in an HTML page.  Here @@ -79,13 +81,24 @@ To run tests:      make test -or: +(Or `perl runtests.pl spec.txt build/src/cmark` or, in the cmake +build directory, `ctest -V`.) -    perl runtests.pl spec.txt build/src/cmark +To test the shared library via a python wrapper: -or (in the cmake build directory): +    make testlib -    ctest -V +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 make a release tarball: + +    make tarball  Installing (JavaScript)  ----------------------- diff --git a/src/inlines.c b/src/inlines.c index ecea199..6a4e70c 100644 --- a/src/inlines.c +++ b/src/inlines.c @@ -683,7 +683,6 @@ static node_inl* handle_close_bracket(subject* subj, node_inl **last)  	chunk urlchunk, titlechunk;  	unsigned char *url, *title;  	delimiter_stack *opener; -	delimiter_stack *closer_above;  	delimiter_stack *tempstack;  	node_inl *link_text;  	node_inl *inl; @@ -787,13 +786,10 @@ match:  	// inside links.)  	if (!is_image) {  		opener = subj->delimiters; -		closer_above = NULL;  		while (opener != NULL) {  			tempstack = opener->previous;  			if (opener->delim_char == '[') {  				remove_delimiter(subj, opener); -			} else { -				closer_above = opener;  			}  			opener = tempstack;  		} diff --git a/wrapper.rb b/wrapper.rb new file mode 100644 index 0000000..3ec2186 --- /dev/null +++ b/wrapper.rb @@ -0,0 +1,14 @@ +require 'ffi' + +module CMark +  extend FFI::Library +  ffi_lib ['libcmark', 'cmark'] +  attach_function :cmark_markdown_to_html, [:string, :int], :string +end + +def markdown_to_html(s) +  CMark::cmark_markdown_to_html(s, s.length) +end + +print markdown_to_html(STDIN.read()); +  | 
