Permalink
Browse files

Initial commit

  • Loading branch information...
1 parent 650ad87 commit 870e63be7360b5a0097a27656048e853bc720464 @jgm committed Jul 22, 2014
Showing with 27,304 additions and 3 deletions.
  1. +10 −0 .gitignore
  2. +30 −0 LICENSE
  3. +62 −0 Makefile
  4. +38 −3 README.md
  5. +5 −0 TODO
  6. +247 −0 alternative-html-blocks.txt
  7. +912 −0 data/CaseFolding-3.2.0.txt
  8. +30 −0 js/LICENSE
  9. +35 −0 js/bench.js
  10. +15 −0 js/markdown
  11. +1,540 −0 js/stmd.js
  12. +79 −0 js/test.js
  13. +29 −0 license.bstrlib.txt
  14. +21 −0 license.uthash.txt
  15. +21 −0 mkcasefold.pl
  16. +12 −0 oldtests/Blockquotes/Indents.html
  17. +5 −0 oldtests/Blockquotes/Indents.markdown
  18. +32 −0 oldtests/Blockquotes/Nesting.html
  19. +22 −0 oldtests/Blockquotes/Nesting.markdown
  20. +39 −0 oldtests/Blockquotes/Separation.html
  21. +29 −0 oldtests/Blockquotes/Separation.markdown
  22. +33 −0 oldtests/Code/BlankLines.html
  23. +28 −0 oldtests/Code/BlankLines.markdown
  24. +14 −0 oldtests/Code/BlankLinesAtEnd.html
  25. +14 −0 oldtests/Code/BlankLinesAtEnd.markdown
  26. +8 −0 oldtests/Code/FenceMatching.html
  27. +10 −0 oldtests/Code/FenceMatching.markdown
  28. +24 −0 oldtests/Code/FencedCodeBlocks.html
  29. +35 −0 oldtests/Code/FencedCodeBlocks.markdown
  30. +22 −0 oldtests/Code/IndentedCodeBlocks.html
  31. +22 −0 oldtests/Code/IndentedCodeBlocks.markdown
  32. +20 −0 oldtests/Code/IndentedFences.html
  33. +26 −0 oldtests/Code/IndentedFences.markdown
  34. +22 −0 oldtests/Code/IndentedInLists.html
  35. +17 −0 oldtests/Code/IndentedInLists.markdown
  36. +13 −0 oldtests/Code/Inline.html
  37. +13 −0 oldtests/Code/Inline.markdown
  38. +30 −0 oldtests/Code/ListBreakAfter.html
  39. +26 −0 oldtests/Code/ListBreakAfter.markdown
  40. +7 −0 oldtests/Code/WhiteLines.html
  41. +9 −0 oldtests/Code/WhiteLines.markdown
  42. +1 −0 oldtests/Emphasis/Escapes.html
  43. +1 −0 oldtests/Emphasis/Escapes.markdown
  44. +66 −0 oldtests/Emphasis/NestedEmphAndStrong.html
  45. +69 −0 oldtests/Emphasis/NestedEmphAndStrong.markdown
  46. +24 −0 oldtests/Emphasis/Pathological.html
  47. +26 −0 oldtests/Emphasis/Pathological.markdown
  48. +10 −0 oldtests/Emphasis/Punctuation.html
  49. +19 −0 oldtests/Emphasis/Punctuation.markdown
  50. +18 −0 oldtests/HTML/Blocks.html
  51. +26 −0 oldtests/HTML/Blocks.markdown
  52. +8 −0 oldtests/HTML/Inline.html
  53. +8 −0 oldtests/HTML/Inline.markdown
  54. +4 −0 oldtests/HTML/UppercaseTags.html
  55. +5 −0 oldtests/HTML/UppercaseTags.markdown
  56. +14 −0 oldtests/Headers/ATX.html
  57. +20 −0 oldtests/Headers/ATX.markdown
  58. +9 −0 oldtests/Headers/Setext.html
  59. +17 −0 oldtests/Headers/Setext.markdown
  60. +3 −0 oldtests/Links/AngleBrackets.html
  61. +7 −0 oldtests/Links/AngleBrackets.markdown
  62. +7 −0 oldtests/Links/AutoLinks.html
  63. +7 −0 oldtests/Links/AutoLinks.markdown
  64. +1 −0 oldtests/Links/BackticksInLinks.html
  65. +1 −0 oldtests/Links/BackticksInLinks.markdown
  66. +1 −0 oldtests/Links/CaseInsensitiveReferences.html
  67. +3 −0 oldtests/Links/CaseInsensitiveReferences.markdown
  68. +2 −0 oldtests/Links/Entities.html
  69. +3 −0 oldtests/Links/Entities.markdown
  70. +10 −0 oldtests/Links/InlineLinks.html
  71. +9 −0 oldtests/Links/InlineLinks.markdown
  72. +6 −0 oldtests/Links/ParensInURLs.html
  73. +14 −0 oldtests/Links/ParensInURLs.markdown
  74. +7 −0 oldtests/Links/ReferenceLinks.html
  75. +10 −0 oldtests/Links/ReferenceLinks.markdown
  76. +14 −0 oldtests/Lists/CodeBlocksInLists.html
  77. +18 −0 oldtests/Lists/CodeBlocksInLists.markdown
  78. +20 −0 oldtests/Lists/ConsecutiveLists.html
  79. +10 −0 oldtests/Lists/ConsecutiveLists.markdown
  80. +10 −0 oldtests/Lists/EmptyListItem.html
  81. +7 −0 oldtests/Lists/EmptyListItem.markdown
  82. +22 −0 oldtests/Lists/InBlockquote.html
  83. +12 −0 oldtests/Lists/InBlockquote.markdown
  84. +22 −0 oldtests/Lists/Indents.html
  85. +17 −0 oldtests/Lists/Indents.markdown
  86. +7 −0 oldtests/Lists/ListsAndHRs.html
  87. +3 −0 oldtests/Lists/ListsAndHRs.markdown
  88. +6 −0 oldtests/Lists/ListsAndSetextHeaders.html
  89. +4 −0 oldtests/Lists/ListsAndSetextHeaders.markdown
  90. +56 −0 oldtests/Lists/MultipleBlankLines.html
  91. +37 −0 oldtests/Lists/MultipleBlankLines.markdown
  92. +11 −0 oldtests/Lists/Start.html
  93. +7 −0 oldtests/Lists/Start.markdown
  94. +49 −0 oldtests/Lists/Sublists.html
  95. +24 −0 oldtests/Lists/Sublists.markdown
  96. +49 −0 oldtests/Lists/TightAndLoose.html
  97. +45 −0 oldtests/Lists/TightAndLoose.markdown
  98. +32 −0 oldtests/Lists/TightLooseBlockquote.html
  99. +25 −0 oldtests/Lists/TightLooseBlockquote.markdown
  100. +7 −0 oldtests/Lists/TightLooseMore.html
  101. +4 −0 oldtests/Lists/TightLooseMore.markdown
  102. +21 −0 oldtests/Lists/TwoBlankLinesEndList.html
  103. +20 −0 oldtests/Lists/TwoBlankLinesEndList.markdown
  104. +55 −0 oldtests/Makefile
  105. +14 −0 oldtests/Misc/BackslashEscapes.html
  106. +19 −0 oldtests/Misc/BackslashEscapes.markdown
  107. +22 −0 oldtests/Misc/Laziness.html
  108. +14 −0 oldtests/Misc/Laziness.markdown
  109. +11 −0 oldtests/Misc/LineBreaks.html
  110. +18 −0 oldtests/Misc/LineBreaks.markdown
  111. +26 −0 oldtests/Misc/Transitions.html
  112. +20 −0 oldtests/Misc/Transitions.markdown
  113. +9 −0 oldtests/Original/Amps_and_angle_encoding.html
  114. +21 −0 oldtests/Original/Amps_and_angle_encoding.markdown
  115. +13 −0 oldtests/Original/Auto_links.html
  116. +13 −0 oldtests/Original/Auto_links.markdown
  117. +75 −0 oldtests/Original/Backslash_escapes.html
  118. +120 −0 oldtests/Original/Backslash_escapes.markdown
  119. +12 −0 oldtests/Original/Blockquotes_with_code_blocks.html
  120. +11 −0 oldtests/Original/Blockquotes_with_code_blocks.markdown
  121. +12 −0 oldtests/Original/Code_Blocks.html
  122. +14 −0 oldtests/Original/Code_Blocks.markdown
  123. +3 −0 oldtests/Original/Code_Spans.html
  124. +5 −0 oldtests/Original/Code_Spans.markdown
  125. +39 −0 oldtests/Original/Horizontal_rules.html
  126. +67 −0 oldtests/Original/Horizontal_rules.markdown
  127. +11 −0 oldtests/Original/Images.html
  128. +26 −0 oldtests/Original/Images.markdown
  129. +23 −0 oldtests/Original/Inline_HTML_Advanced.html
  130. +30 −0 oldtests/Original/Inline_HTML_Advanced.markdown
  131. +45 −0 oldtests/Original/Inline_HTML_Simple.html
  132. +69 −0 oldtests/Original/Inline_HTML_Simple.markdown
  133. +8 −0 oldtests/Original/Inline_HTML_comments.html
  134. +13 −0 oldtests/Original/Inline_HTML_comments.markdown
  135. +12 −0 oldtests/Original/Links_inline_style.html
  136. +24 −0 oldtests/Original/Links_inline_style.markdown
  137. +28 −0 oldtests/Original/Links_reference_style.html
  138. +71 −0 oldtests/Original/Links_reference_style.markdown
  139. +6 −0 oldtests/Original/Links_shortcut_references.html
  140. +20 −0 oldtests/Original/Links_shortcut_references.markdown
  141. +2 −0 oldtests/Original/Literal_quotes_in_titles.html
  142. +7 −0 oldtests/Original/Literal_quotes_in_titles.markdown
  143. +242 −0 oldtests/Original/Markdown_Documentation_Basics.html
  144. +306 −0 oldtests/Original/Markdown_Documentation_Basics.markdown
  145. +708 −0 oldtests/Original/Markdown_Documentation_Syntax.html
  146. +888 −0 oldtests/Original/Markdown_Documentation_Syntax.markdown
  147. +7 −0 oldtests/Original/Nested_blockquotes.html
  148. +5 −0 oldtests/Original/Nested_blockquotes.markdown
  149. +112 −0 oldtests/Original/Ordered_and_unordered_lists.html
  150. +131 −0 oldtests/Original/Ordered_and_unordered_lists.markdown
  151. +15 −0 oldtests/Original/README
  152. +4 −0 oldtests/Original/Strong_and_em_together.html
  153. +7 −0 oldtests/Original/Strong_and_em_together.markdown
  154. +19 −0 oldtests/Original/Tabs.html
  155. +21 −0 oldtests/Original/Tabs.markdown
  156. +8 −0 oldtests/Original/Tidyness.html
  157. +5 −0 oldtests/Original/Tidyness.markdown
  158. +1 −0 oldtests/Tabs/TabConversionUnicode.html
  159. +1 −0 oldtests/Tabs/TabConversionUnicode.markdown
  160. +159 −0 runtests.pl
  161. +6,044 −0 spec.txt
  162. +17 −0 spec2js.js
  163. +36 −0 spec2md.pl
  164. +37 −0 specfilter.hs
  165. +747 −0 src/blocks.c
  166. +2,979 −0 src/bstrlib.c
  167. +304 −0 src/bstrlib.h
  168. +2,637 −0 src/case_fold_switch.c
  169. +2,699 −0 src/casefold.c
  170. +36 −0 src/debug.h
  171. +48 −0 src/detab.c
  172. +199 −0 src/getopt.c
  173. +276 −0 src/html.c
  174. +998 −0 src/inlines.c
  175. +102 −0 src/main.c
  176. +168 −0 src/print.c
  177. +15 −0 src/scanners.h
  178. +238 −0 src/scanners.re
  179. +121 −0 src/stmd.h
  180. +106 −0 src/utf8.c
  181. +6 −0 src/utf8.h
  182. +948 −0 src/uthash.h
  183. +66 −0 template.html
  184. +229 −0 template.tex
View
@@ -21,3 +21,13 @@
*.i*86
*.x86_64
*.hex
+
+*~
+*.bak
+*.diff
+*#
+scanners.c
+*.zip
+bstrlib.txt
+stmd.dSYM/*
+stmd
View
@@ -0,0 +1,30 @@
+Copyright (c) 2014, John MacFarlane
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of John MacFarlane nor the names of other
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
@@ -0,0 +1,62 @@
+CFLAGS=-g -O3 -Wall -Wextra -std=c99 -Isrc $(OPTFLAGS)
+LDFLAGS=-g -O3 -Wall -Werror
+SRCDIR=src
+DATADIR=data
+
+PROG=./stmd
+
+.PHONY: all oldtests test spec benchjs testjs
+all: $(SRCDIR)/case_fold_switch.c $(PROG)
+
+spec: test spec.html
+
+spec.md: spec.txt
+ perl spec2md.pl < $< > $@
+
+spec.html: spec.md template.html
+ pandoc --no-highlight --number-sections --template template.html -s --toc -S $< > $@ # | 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
+
+oldtests:
+ make -C oldtests --quiet clean all
+
+test: spec.txt
+ perl runtests.pl $(PROG) $<
+
+testjs: spec.txt
+ node js/test.js
+# perl runtests.pl js/markdown $<
+
+benchjs:
+ node js/bench.js
+
+$(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
+ $(CC) $(LDFLAGS) -o $@ $^
+
+$(SRCDIR)/scanners.c: $(SRCDIR)/scanners.re
+ re2c --case-insensitive -bis $< > $@
+
+$(SRCDIR)/case_fold_switch.c: $(DATADIR)/CaseFolding-3.2.0.txt
+ perl mkcasefold.pl < $< > $@
+
+.PHONY: leakcheck clean fuzztest dingus
+
+dingus:
+ cd js && echo "Starting dingus server at http://localhost:9000" && python -m SimpleHTTPServer 9000
+
+leakcheck: $(PROG)
+ cat oldtests/*/*.markdown | valgrind --leak-check=full --dsymutil=yes $(PROG)
+
+fuzztest:
+ for i in `seq 1 10`; do \
+ time cat /dev/urandom | head -c 100000 | iconv -f latin1 -t utf-8 | $(PROG) >/dev/null; done
+
+clean:
+ -rm test $(SRCDIR)/*.o $(SRCDIR)/scanners.c
+ -rm -r *.dSYM
+ -rm spec.md fuzz.txt spec.html
View
@@ -1,4 +1,39 @@
-stmd
-====
+Standard markdown
+=================
+
+Standard markdown is a specification of markdown syntax, together
+with implementations (`stmd`) in C and javascript.
+
+The C implementation provides both a library and a standalone program
+that converts markdown to HTML. It is written in standard C99 and has
+no library dependencies. (However, if you check it out from the
+repository, you'll need `re2c` to generate `scanners.c` from
+`scanners.re`. This is only a build dependency for developers, since
+`scanners.c` can be provided in a released source tarball.)
+
+The javascript implementation is a single javascript file
+that can be linked to an HTML page. A standalone version (using
+`node.js`) is also provided (`js/markdown`), and there is a
+"dingus" for playing with it interactively. (`make dingus` will start
+this.)
+
+The spec contains over 400 embedded examples which serve as
+conformance tests. To run the tests for `stmd`, do `make test`.
+To run them for another markdown program, say `myprog`,
+do `make test PROG=myprog`. To run the tests for `stmd.js`,
+do `make testjs`.
+
+The source of the spec is `spec.txt`. This is basically a markdown
+file, with code examples written in a shorthand form:
+
+ .
+ markdown source
+ .
+ expected HTML output
+ .
+
+To build an HTML version of the spec, do `make spec.html`.
+To build a PDF version, do `make spec.pdf`. Both these commands
+require that pandoc is installed, and creating a PDF requires
+a latex installation.
-a spec for "standard markdown," with matching C and javascript implementations
View
@@ -0,0 +1,5 @@
+- add library function to convert a string
+- add README/library documentation
+- add man page for prog and library
+- document/clean up code
+
Oops, something went wrong.

0 comments on commit 870e63b

Please sign in to comment.