Skip to content

Commit 870e63b

Browse files
committed
Initial commit
1 parent 650ad87 commit 870e63b

File tree

184 files changed

+27304
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

184 files changed

+27304
-3
lines changed

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,13 @@
2121
*.i*86
2222
*.x86_64
2323
*.hex
24+
25+
*~
26+
*.bak
27+
*.diff
28+
*#
29+
scanners.c
30+
*.zip
31+
bstrlib.txt
32+
stmd.dSYM/*
33+
stmd

LICENSE

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Copyright (c) 2014, John MacFarlane
2+
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
* Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
11+
* Redistributions in binary form must reproduce the above
12+
copyright notice, this list of conditions and the following
13+
disclaimer in the documentation and/or other materials provided
14+
with the distribution.
15+
16+
* Neither the name of John MacFarlane nor the names of other
17+
contributors may be used to endorse or promote products derived
18+
from this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Makefile

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
CFLAGS=-g -O3 -Wall -Wextra -std=c99 -Isrc $(OPTFLAGS)
2+
LDFLAGS=-g -O3 -Wall -Werror
3+
SRCDIR=src
4+
DATADIR=data
5+
6+
PROG=./stmd
7+
8+
.PHONY: all oldtests test spec benchjs testjs
9+
all: $(SRCDIR)/case_fold_switch.c $(PROG)
10+
11+
spec: test spec.html
12+
13+
spec.md: spec.txt
14+
perl spec2md.pl < $< > $@
15+
16+
spec.html: spec.md template.html
17+
pandoc --no-highlight --number-sections --template template.html -s --toc -S $< > $@ # | perl -pe 's/␣/<span class="space"> <\/span>/g' > $@
18+
19+
spec.pdf: spec.md template.tex specfilter.hs
20+
pandoc -s $< --template template.tex \
21+
--filter ./specfilter.hs -o $@ --latex-engine=xelatex --toc \
22+
--number-sections -V documentclass=report -V tocdepth=2 \
23+
-V classoption=twosides
24+
25+
oldtests:
26+
make -C oldtests --quiet clean all
27+
28+
test: spec.txt
29+
perl runtests.pl $(PROG) $<
30+
31+
testjs: spec.txt
32+
node js/test.js
33+
# perl runtests.pl js/markdown $<
34+
35+
benchjs:
36+
node js/bench.js
37+
38+
$(PROG): $(SRCDIR)/main.c $(SRCDIR)/inlines.o $(SRCDIR)/blocks.o $(SRCDIR)/detab.o $(SRCDIR)/bstrlib.o $(SRCDIR)/scanners.o $(SRCDIR)/print.o $(SRCDIR)/html.o $(SRCDIR)/utf8.o
39+
$(CC) $(LDFLAGS) -o $@ $^
40+
41+
$(SRCDIR)/scanners.c: $(SRCDIR)/scanners.re
42+
re2c --case-insensitive -bis $< > $@
43+
44+
$(SRCDIR)/case_fold_switch.c: $(DATADIR)/CaseFolding-3.2.0.txt
45+
perl mkcasefold.pl < $< > $@
46+
47+
.PHONY: leakcheck clean fuzztest dingus
48+
49+
dingus:
50+
cd js && echo "Starting dingus server at http://localhost:9000" && python -m SimpleHTTPServer 9000
51+
52+
leakcheck: $(PROG)
53+
cat oldtests/*/*.markdown | valgrind --leak-check=full --dsymutil=yes $(PROG)
54+
55+
fuzztest:
56+
for i in `seq 1 10`; do \
57+
time cat /dev/urandom | head -c 100000 | iconv -f latin1 -t utf-8 | $(PROG) >/dev/null; done
58+
59+
clean:
60+
-rm test $(SRCDIR)/*.o $(SRCDIR)/scanners.c
61+
-rm -r *.dSYM
62+
-rm spec.md fuzz.txt spec.html

README.md

+38-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,39 @@
1-
stmd
2-
====
1+
Standard markdown
2+
=================
3+
4+
Standard markdown is a specification of markdown syntax, together
5+
with implementations (`stmd`) in C and javascript.
6+
7+
The C implementation provides both a library and a standalone program
8+
that converts markdown to HTML. It is written in standard C99 and has
9+
no library dependencies. (However, if you check it out from the
10+
repository, you'll need `re2c` to generate `scanners.c` from
11+
`scanners.re`. This is only a build dependency for developers, since
12+
`scanners.c` can be provided in a released source tarball.)
13+
14+
The javascript implementation is a single javascript file
15+
that can be linked to an HTML page. A standalone version (using
16+
`node.js`) is also provided (`js/markdown`), and there is a
17+
"dingus" for playing with it interactively. (`make dingus` will start
18+
this.)
19+
20+
The spec contains over 400 embedded examples which serve as
21+
conformance tests. To run the tests for `stmd`, do `make test`.
22+
To run them for another markdown program, say `myprog`,
23+
do `make test PROG=myprog`. To run the tests for `stmd.js`,
24+
do `make testjs`.
25+
26+
The source of the spec is `spec.txt`. This is basically a markdown
27+
file, with code examples written in a shorthand form:
28+
29+
.
30+
markdown source
31+
.
32+
expected HTML output
33+
.
34+
35+
To build an HTML version of the spec, do `make spec.html`.
36+
To build a PDF version, do `make spec.pdf`. Both these commands
37+
require that pandoc is installed, and creating a PDF requires
38+
a latex installation.
339

4-
a spec for "standard markdown," with matching C and javascript implementations

TODO

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- add library function to convert a string
2+
- add README/library documentation
3+
- add man page for prog and library
4+
- document/clean up code
5+

0 commit comments

Comments
 (0)