rpeg-multimarkdown2 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (269) hide show
  1. data/LICENSE +96 -0
  2. data/README.markdown +52 -0
  3. data/Rakefile +167 -0
  4. data/bin/rpeg-multimarkdown2 +128 -0
  5. data/ext/extconf.h +3 -0
  6. data/ext/extconf.rb +15 -0
  7. data/ext/markdown.c +102 -0
  8. data/ext/markdown_lib.c +265 -0
  9. data/ext/markdown_lib.h +33 -0
  10. data/ext/markdown_output.c +2832 -0
  11. data/ext/markdown_parser.c +9091 -0
  12. data/ext/markdown_peg.h +144 -0
  13. data/ext/odf.c +183 -0
  14. data/ext/odf.h +3 -0
  15. data/ext/parsing_functions.c +199 -0
  16. data/ext/utility_functions.c +566 -0
  17. data/lib/multimarkdown2.rb +1 -0
  18. data/lib/peg_multimarkdown.rb +74 -0
  19. data/test/MultiMarkdownTest/BeamerTests/Beamer-Tables.html +76 -0
  20. data/test/MultiMarkdownTest/BeamerTests/Beamer-Tables.tex +64 -0
  21. data/test/MultiMarkdownTest/BeamerTests/Beamer-Tables.text +38 -0
  22. data/test/MultiMarkdownTest/CompatibilityTests/Automatic Labels.html +35 -0
  23. data/test/MultiMarkdownTest/CompatibilityTests/Automatic Labels.text +45 -0
  24. data/test/MultiMarkdownTest/CompatibilityTests/Base Header Level.html +14 -0
  25. data/test/MultiMarkdownTest/CompatibilityTests/Base Header Level.text +16 -0
  26. data/test/MultiMarkdownTest/CompatibilityTests/BibTeX.html +9 -0
  27. data/test/MultiMarkdownTest/CompatibilityTests/BibTeX.text +10 -0
  28. data/test/MultiMarkdownTest/CompatibilityTests/Citations.html +40 -0
  29. data/test/MultiMarkdownTest/CompatibilityTests/Citations.text +42 -0
  30. data/test/MultiMarkdownTest/CompatibilityTests/Definition Lists.html +40 -0
  31. data/test/MultiMarkdownTest/CompatibilityTests/Definition Lists.text +39 -0
  32. data/test/MultiMarkdownTest/CompatibilityTests/Dutch.html +17 -0
  33. data/test/MultiMarkdownTest/CompatibilityTests/Dutch.text +17 -0
  34. data/test/MultiMarkdownTest/CompatibilityTests/Email.html +40 -0
  35. data/test/MultiMarkdownTest/CompatibilityTests/Email.text +31 -0
  36. data/test/MultiMarkdownTest/CompatibilityTests/English.html +17 -0
  37. data/test/MultiMarkdownTest/CompatibilityTests/English.text +17 -0
  38. data/test/MultiMarkdownTest/CompatibilityTests/Errors.html +9 -0
  39. data/test/MultiMarkdownTest/CompatibilityTests/Errors.text +11 -0
  40. data/test/MultiMarkdownTest/CompatibilityTests/Footnotes.html +23 -0
  41. data/test/MultiMarkdownTest/CompatibilityTests/Footnotes.text +25 -0
  42. data/test/MultiMarkdownTest/CompatibilityTests/French.html +17 -0
  43. data/test/MultiMarkdownTest/CompatibilityTests/French.text +17 -0
  44. data/test/MultiMarkdownTest/CompatibilityTests/German.html +17 -0
  45. data/test/MultiMarkdownTest/CompatibilityTests/German.text +17 -0
  46. data/test/MultiMarkdownTest/CompatibilityTests/GermanGuillemets.html +17 -0
  47. data/test/MultiMarkdownTest/CompatibilityTests/GermanGuillemets.text +17 -0
  48. data/test/MultiMarkdownTest/CompatibilityTests/Glossary.html +29 -0
  49. data/test/MultiMarkdownTest/CompatibilityTests/Glossary.text +28 -0
  50. data/test/MultiMarkdownTest/CompatibilityTests/Headers.html +42 -0
  51. data/test/MultiMarkdownTest/CompatibilityTests/Headers.text +51 -0
  52. data/test/MultiMarkdownTest/CompatibilityTests/Line Breaks.html +13 -0
  53. data/test/MultiMarkdownTest/CompatibilityTests/Line Breaks.text +15 -0
  54. data/test/MultiMarkdownTest/CompatibilityTests/Link Attributes.html +35 -0
  55. data/test/MultiMarkdownTest/CompatibilityTests/Link Attributes.text +51 -0
  56. data/test/MultiMarkdownTest/CompatibilityTests/List Parsing.html +13 -0
  57. data/test/MultiMarkdownTest/CompatibilityTests/List Parsing.text +11 -0
  58. data/test/MultiMarkdownTest/CompatibilityTests/MarkdownInHTML.html +13 -0
  59. data/test/MultiMarkdownTest/CompatibilityTests/MarkdownInHTML.text +19 -0
  60. data/test/MultiMarkdownTest/CompatibilityTests/Math.html +14 -0
  61. data/test/MultiMarkdownTest/CompatibilityTests/Math.text +15 -0
  62. data/test/MultiMarkdownTest/CompatibilityTests/MetaData.html +14 -0
  63. data/test/MultiMarkdownTest/CompatibilityTests/MetaData.text +14 -0
  64. data/test/MultiMarkdownTest/CompatibilityTests/NotMetaData.html +3 -0
  65. data/test/MultiMarkdownTest/CompatibilityTests/NotMetaData.text +4 -0
  66. data/test/MultiMarkdownTest/CompatibilityTests/Sanity.html +77 -0
  67. data/test/MultiMarkdownTest/CompatibilityTests/Sanity.text +77 -0
  68. data/test/MultiMarkdownTest/CompatibilityTests/SmartQuotes.html +22 -0
  69. data/test/MultiMarkdownTest/CompatibilityTests/SmartQuotes.text +22 -0
  70. data/test/MultiMarkdownTest/CompatibilityTests/Swedish.html +17 -0
  71. data/test/MultiMarkdownTest/CompatibilityTests/Swedish.text +17 -0
  72. data/test/MultiMarkdownTest/CompatibilityTests/Tables.html +65 -0
  73. data/test/MultiMarkdownTest/CompatibilityTests/Tables.text +71 -0
  74. data/test/MultiMarkdownTest/MarkdownTest.pl +182 -0
  75. data/test/MultiMarkdownTest/MemoirTests/Automatic Labels.html +42 -0
  76. data/test/MultiMarkdownTest/MemoirTests/Automatic Labels.tex +47 -0
  77. data/test/MultiMarkdownTest/MemoirTests/Automatic Labels.text +46 -0
  78. data/test/MultiMarkdownTest/MemoirTests/Base Header Level.html +20 -0
  79. data/test/MultiMarkdownTest/MemoirTests/Base Header Level.tex +19 -0
  80. data/test/MultiMarkdownTest/MemoirTests/Base Header Level.text +16 -0
  81. data/test/MultiMarkdownTest/MemoirTests/BibTeX.html +17 -0
  82. data/test/MultiMarkdownTest/MemoirTests/BibTeX.tex +12 -0
  83. data/test/MultiMarkdownTest/MemoirTests/BibTeX.text +11 -0
  84. data/test/MultiMarkdownTest/MemoirTests/Citations.html +63 -0
  85. data/test/MultiMarkdownTest/MemoirTests/Citations.tex +48 -0
  86. data/test/MultiMarkdownTest/MemoirTests/Citations.text +43 -0
  87. data/test/MultiMarkdownTest/MemoirTests/Definition Lists.html +61 -0
  88. data/test/MultiMarkdownTest/MemoirTests/Definition Lists.tex +58 -0
  89. data/test/MultiMarkdownTest/MemoirTests/Definition Lists.text +40 -0
  90. data/test/MultiMarkdownTest/MemoirTests/Dutch.html +23 -0
  91. data/test/MultiMarkdownTest/MemoirTests/Dutch.tex +18 -0
  92. data/test/MultiMarkdownTest/MemoirTests/Dutch.text +17 -0
  93. data/test/MultiMarkdownTest/MemoirTests/Email.html +48 -0
  94. data/test/MultiMarkdownTest/MemoirTests/Email.tex +61 -0
  95. data/test/MultiMarkdownTest/MemoirTests/Email.text +32 -0
  96. data/test/MultiMarkdownTest/MemoirTests/English.html +23 -0
  97. data/test/MultiMarkdownTest/MemoirTests/English.tex +18 -0
  98. data/test/MultiMarkdownTest/MemoirTests/English.text +17 -0
  99. data/test/MultiMarkdownTest/MemoirTests/Footnotes.html +47 -0
  100. data/test/MultiMarkdownTest/MemoirTests/Footnotes.tex +28 -0
  101. data/test/MultiMarkdownTest/MemoirTests/Footnotes.text +26 -0
  102. data/test/MultiMarkdownTest/MemoirTests/French.html +23 -0
  103. data/test/MultiMarkdownTest/MemoirTests/French.tex +18 -0
  104. data/test/MultiMarkdownTest/MemoirTests/French.text +17 -0
  105. data/test/MultiMarkdownTest/MemoirTests/German.html +23 -0
  106. data/test/MultiMarkdownTest/MemoirTests/German.tex +18 -0
  107. data/test/MultiMarkdownTest/MemoirTests/German.text +17 -0
  108. data/test/MultiMarkdownTest/MemoirTests/GermanGuillemets.html +23 -0
  109. data/test/MultiMarkdownTest/MemoirTests/GermanGuillemets.tex +18 -0
  110. data/test/MultiMarkdownTest/MemoirTests/GermanGuillemets.text +17 -0
  111. data/test/MultiMarkdownTest/MemoirTests/Glossary.html +47 -0
  112. data/test/MultiMarkdownTest/MemoirTests/Glossary.tex +30 -0
  113. data/test/MultiMarkdownTest/MemoirTests/Glossary.text +29 -0
  114. data/test/MultiMarkdownTest/MemoirTests/Line Breaks.html +21 -0
  115. data/test/MultiMarkdownTest/MemoirTests/Line Breaks.tex +16 -0
  116. data/test/MultiMarkdownTest/MemoirTests/Line Breaks.text +16 -0
  117. data/test/MultiMarkdownTest/MemoirTests/Link Attributes.html +40 -0
  118. data/test/MultiMarkdownTest/MemoirTests/Link Attributes.tex +61 -0
  119. data/test/MultiMarkdownTest/MemoirTests/Link Attributes.text +51 -0
  120. data/test/MultiMarkdownTest/MemoirTests/Math.html +22 -0
  121. data/test/MultiMarkdownTest/MemoirTests/Math.tex +16 -0
  122. data/test/MultiMarkdownTest/MemoirTests/Math.text +16 -0
  123. data/test/MultiMarkdownTest/MemoirTests/Memoir Mode.html +24 -0
  124. data/test/MultiMarkdownTest/MemoirTests/Memoir Mode.tex +23 -0
  125. data/test/MultiMarkdownTest/MemoirTests/Memoir Mode.text +20 -0
  126. data/test/MultiMarkdownTest/MemoirTests/MetaData.html +22 -0
  127. data/test/MultiMarkdownTest/MemoirTests/MetaData.tex +14 -0
  128. data/test/MultiMarkdownTest/MemoirTests/MetaData.text +15 -0
  129. data/test/MultiMarkdownTest/MemoirTests/Sanity.html +100 -0
  130. data/test/MultiMarkdownTest/MemoirTests/Sanity.tex +101 -0
  131. data/test/MultiMarkdownTest/MemoirTests/Sanity.text +78 -0
  132. data/test/MultiMarkdownTest/MemoirTests/SmartQuotes.html +26 -0
  133. data/test/MultiMarkdownTest/MemoirTests/SmartQuotes.tex +21 -0
  134. data/test/MultiMarkdownTest/MemoirTests/SmartQuotes.text +19 -0
  135. data/test/MultiMarkdownTest/MemoirTests/Swedish.html +23 -0
  136. data/test/MultiMarkdownTest/MemoirTests/Swedish.tex +18 -0
  137. data/test/MultiMarkdownTest/MemoirTests/Swedish.text +17 -0
  138. data/test/MultiMarkdownTest/MemoirTests/Tables.html +221 -0
  139. data/test/MultiMarkdownTest/MemoirTests/Tables.tex +134 -0
  140. data/test/MultiMarkdownTest/MemoirTests/Tables.text +64 -0
  141. data/test/MultiMarkdownTest/MultiMarkdownTests/Automatic Labels.html +43 -0
  142. data/test/MultiMarkdownTest/MultiMarkdownTests/Automatic Labels.tex +46 -0
  143. data/test/MultiMarkdownTest/MultiMarkdownTests/Automatic Labels.text +45 -0
  144. data/test/MultiMarkdownTest/MultiMarkdownTests/Base Header Level.html +22 -0
  145. data/test/MultiMarkdownTest/MultiMarkdownTests/Base Header Level.tex +19 -0
  146. data/test/MultiMarkdownTest/MultiMarkdownTests/Base Header Level.text +16 -0
  147. data/test/MultiMarkdownTest/MultiMarkdownTests/BibTeX.html +18 -0
  148. data/test/MultiMarkdownTest/MultiMarkdownTests/BibTeX.tex +11 -0
  149. data/test/MultiMarkdownTest/MultiMarkdownTests/BibTex.text +10 -0
  150. data/test/MultiMarkdownTest/MultiMarkdownTests/Citations.html +64 -0
  151. data/test/MultiMarkdownTest/MultiMarkdownTests/Citations.tex +47 -0
  152. data/test/MultiMarkdownTest/MultiMarkdownTests/Citations.text +42 -0
  153. data/test/MultiMarkdownTest/MultiMarkdownTests/Definition Lists.html +57 -0
  154. data/test/MultiMarkdownTest/MultiMarkdownTests/Definition Lists.tex +57 -0
  155. data/test/MultiMarkdownTest/MultiMarkdownTests/Definition Lists.text +39 -0
  156. data/test/MultiMarkdownTest/MultiMarkdownTests/Dutch.html +25 -0
  157. data/test/MultiMarkdownTest/MultiMarkdownTests/Dutch.tex +18 -0
  158. data/test/MultiMarkdownTest/MultiMarkdownTests/Dutch.text +17 -0
  159. data/test/MultiMarkdownTest/MultiMarkdownTests/Email.html +49 -0
  160. data/test/MultiMarkdownTest/MultiMarkdownTests/Email.tex +54 -0
  161. data/test/MultiMarkdownTest/MultiMarkdownTests/Email.text +31 -0
  162. data/test/MultiMarkdownTest/MultiMarkdownTests/English.html +25 -0
  163. data/test/MultiMarkdownTest/MultiMarkdownTests/English.tex +18 -0
  164. data/test/MultiMarkdownTest/MultiMarkdownTests/English.text +17 -0
  165. data/test/MultiMarkdownTest/MultiMarkdownTests/Errors.html +18 -0
  166. data/test/MultiMarkdownTest/MultiMarkdownTests/Errors.tex +11 -0
  167. data/test/MultiMarkdownTest/MultiMarkdownTests/Errors.text +11 -0
  168. data/test/MultiMarkdownTest/MultiMarkdownTests/Footnotes.html +48 -0
  169. data/test/MultiMarkdownTest/MultiMarkdownTests/Footnotes.tex +24 -0
  170. data/test/MultiMarkdownTest/MultiMarkdownTests/Footnotes.text +25 -0
  171. data/test/MultiMarkdownTest/MultiMarkdownTests/French.html +25 -0
  172. data/test/MultiMarkdownTest/MultiMarkdownTests/French.tex +18 -0
  173. data/test/MultiMarkdownTest/MultiMarkdownTests/French.text +17 -0
  174. data/test/MultiMarkdownTest/MultiMarkdownTests/German.html +25 -0
  175. data/test/MultiMarkdownTest/MultiMarkdownTests/German.tex +18 -0
  176. data/test/MultiMarkdownTest/MultiMarkdownTests/German.text +17 -0
  177. data/test/MultiMarkdownTest/MultiMarkdownTests/GermanGuillemets.html +25 -0
  178. data/test/MultiMarkdownTest/MultiMarkdownTests/GermanGuillemets.tex +18 -0
  179. data/test/MultiMarkdownTest/MultiMarkdownTests/GermanGuillemets.text +17 -0
  180. data/test/MultiMarkdownTest/MultiMarkdownTests/Glossary.html +48 -0
  181. data/test/MultiMarkdownTest/MultiMarkdownTests/Glossary.tex +26 -0
  182. data/test/MultiMarkdownTest/MultiMarkdownTests/Glossary.text +28 -0
  183. data/test/MultiMarkdownTest/MultiMarkdownTests/Headers.html +50 -0
  184. data/test/MultiMarkdownTest/MultiMarkdownTests/Headers.tex +54 -0
  185. data/test/MultiMarkdownTest/MultiMarkdownTests/Headers.text +51 -0
  186. data/test/MultiMarkdownTest/MultiMarkdownTests/Line Breaks.html +22 -0
  187. data/test/MultiMarkdownTest/MultiMarkdownTests/Line Breaks.tex +15 -0
  188. data/test/MultiMarkdownTest/MultiMarkdownTests/Line Breaks.text +15 -0
  189. data/test/MultiMarkdownTest/MultiMarkdownTests/Link Attributes.html +56 -0
  190. data/test/MultiMarkdownTest/MultiMarkdownTests/Link Attributes.tex +60 -0
  191. data/test/MultiMarkdownTest/MultiMarkdownTests/Link Attributes.text +50 -0
  192. data/test/MultiMarkdownTest/MultiMarkdownTests/List Parsing.html +22 -0
  193. data/test/MultiMarkdownTest/MultiMarkdownTests/List Parsing.tex +17 -0
  194. data/test/MultiMarkdownTest/MultiMarkdownTests/List Parsing.text +11 -0
  195. data/test/MultiMarkdownTest/MultiMarkdownTests/MarkdownInHTML.html +21 -0
  196. data/test/MultiMarkdownTest/MultiMarkdownTests/MarkdownInHTML.tex +13 -0
  197. data/test/MultiMarkdownTest/MultiMarkdownTests/MarkdownInHTML.text +19 -0
  198. data/test/MultiMarkdownTest/MultiMarkdownTests/Math.html +23 -0
  199. data/test/MultiMarkdownTest/MultiMarkdownTests/Math.tex +15 -0
  200. data/test/MultiMarkdownTest/MultiMarkdownTests/Math.text +15 -0
  201. data/test/MultiMarkdownTest/MultiMarkdownTests/MetaData.html +23 -0
  202. data/test/MultiMarkdownTest/MultiMarkdownTests/MetaData.tex +13 -0
  203. data/test/MultiMarkdownTest/MultiMarkdownTests/MetaData.text +14 -0
  204. data/test/MultiMarkdownTest/MultiMarkdownTests/NotMetaData.html +3 -0
  205. data/test/MultiMarkdownTest/MultiMarkdownTests/NotMetaData.tex +3 -0
  206. data/test/MultiMarkdownTest/MultiMarkdownTests/NotMetaData.text +4 -0
  207. data/test/MultiMarkdownTest/MultiMarkdownTests/Sanity.html +106 -0
  208. data/test/MultiMarkdownTest/MultiMarkdownTests/Sanity.tex +100 -0
  209. data/test/MultiMarkdownTest/MultiMarkdownTests/Sanity.text +77 -0
  210. data/test/MultiMarkdownTest/MultiMarkdownTests/SmartQuotes.html +31 -0
  211. data/test/MultiMarkdownTest/MultiMarkdownTests/SmartQuotes.tex +24 -0
  212. data/test/MultiMarkdownTest/MultiMarkdownTests/SmartQuotes.text +22 -0
  213. data/test/MultiMarkdownTest/MultiMarkdownTests/Swedish.html +25 -0
  214. data/test/MultiMarkdownTest/MultiMarkdownTests/Swedish.tex +18 -0
  215. data/test/MultiMarkdownTest/MultiMarkdownTests/Swedish.text +17 -0
  216. data/test/MultiMarkdownTest/MultiMarkdownTests/Tables.html +273 -0
  217. data/test/MultiMarkdownTest/MultiMarkdownTests/Tables.tex +155 -0
  218. data/test/MultiMarkdownTest/MultiMarkdownTests/Tables.text +71 -0
  219. data/test/MultiMarkdownTest/MultiMarkdownTests/bibtex.bib +119 -0
  220. data/test/MultiMarkdownTest/README.md +58 -0
  221. data/test/MultiMarkdownTest/Tests/Amps and angle encoding.html +17 -0
  222. data/test/MultiMarkdownTest/Tests/Amps and angle encoding.text +21 -0
  223. data/test/MultiMarkdownTest/Tests/Auto links.html +18 -0
  224. data/test/MultiMarkdownTest/Tests/Auto links.text +13 -0
  225. data/test/MultiMarkdownTest/Tests/Backslash escapes.html +118 -0
  226. data/test/MultiMarkdownTest/Tests/Backslash escapes.text +120 -0
  227. data/test/MultiMarkdownTest/Tests/Blockquotes with code blocks.html +15 -0
  228. data/test/MultiMarkdownTest/Tests/Blockquotes with code blocks.text +11 -0
  229. data/test/MultiMarkdownTest/Tests/Code Blocks.html +18 -0
  230. data/test/MultiMarkdownTest/Tests/Code Blocks.text +14 -0
  231. data/test/MultiMarkdownTest/Tests/Code Spans.html +6 -0
  232. data/test/MultiMarkdownTest/Tests/Code Spans.text +6 -0
  233. data/test/MultiMarkdownTest/Tests/Compatibility.html +5 -0
  234. data/test/MultiMarkdownTest/Tests/Compatibility.text +9 -0
  235. data/test/MultiMarkdownTest/Tests/Hard-wrapped paragraphs with list-like lines.html +8 -0
  236. data/test/MultiMarkdownTest/Tests/Hard-wrapped paragraphs with list-like lines.text +8 -0
  237. data/test/MultiMarkdownTest/Tests/Horizontal rules.html +71 -0
  238. data/test/MultiMarkdownTest/Tests/Horizontal rules.text +67 -0
  239. data/test/MultiMarkdownTest/Tests/Inline HTML (Advanced).html +15 -0
  240. data/test/MultiMarkdownTest/Tests/Inline HTML (Advanced).text +15 -0
  241. data/test/MultiMarkdownTest/Tests/Inline HTML (Simple).html +72 -0
  242. data/test/MultiMarkdownTest/Tests/Inline HTML (Simple).text +69 -0
  243. data/test/MultiMarkdownTest/Tests/Inline HTML comments.html +13 -0
  244. data/test/MultiMarkdownTest/Tests/Inline HTML comments.text +13 -0
  245. data/test/MultiMarkdownTest/Tests/Links, inline style.html +11 -0
  246. data/test/MultiMarkdownTest/Tests/Links, inline style.text +12 -0
  247. data/test/MultiMarkdownTest/Tests/Links, reference style.html +52 -0
  248. data/test/MultiMarkdownTest/Tests/Links, reference style.text +71 -0
  249. data/test/MultiMarkdownTest/Tests/Links, shortcut references.html +9 -0
  250. data/test/MultiMarkdownTest/Tests/Links, shortcut references.text +20 -0
  251. data/test/MultiMarkdownTest/Tests/Literal quotes in titles.html +3 -0
  252. data/test/MultiMarkdownTest/Tests/Literal quotes in titles.text +7 -0
  253. data/test/MultiMarkdownTest/Tests/Markdown Documentation - Basics.html +314 -0
  254. data/test/MultiMarkdownTest/Tests/Markdown Documentation - Basics.text +306 -0
  255. data/test/MultiMarkdownTest/Tests/Markdown Documentation - Syntax.html +942 -0
  256. data/test/MultiMarkdownTest/Tests/Markdown Documentation - Syntax.text +888 -0
  257. data/test/MultiMarkdownTest/Tests/Nested blockquotes.html +9 -0
  258. data/test/MultiMarkdownTest/Tests/Nested blockquotes.text +5 -0
  259. data/test/MultiMarkdownTest/Tests/Ordered and unordered lists.html +148 -0
  260. data/test/MultiMarkdownTest/Tests/Ordered and unordered lists.text +131 -0
  261. data/test/MultiMarkdownTest/Tests/Strong and em together.html +7 -0
  262. data/test/MultiMarkdownTest/Tests/Strong and em together.text +7 -0
  263. data/test/MultiMarkdownTest/Tests/Tabs.html +25 -0
  264. data/test/MultiMarkdownTest/Tests/Tabs.text +21 -0
  265. data/test/MultiMarkdownTest/Tests/Tidyness.html +8 -0
  266. data/test/MultiMarkdownTest/Tests/Tidyness.text +5 -0
  267. data/test/benchmark.rb +49 -0
  268. data/test/multimarkdown_test.rb +89 -0
  269. metadata +318 -0
data/LICENSE ADDED
@@ -0,0 +1,96 @@
1
+ Ruby PEG MultiMarkdown 2, implemented using peg-multimarkdown
2
+ Copyright (c) 2012 Andor Chen
3
+ Ruby Markdown Extension, implemented using peg-markdown
4
+ Copyright (c) 2008 Ryan Tomayko
5
+ markdown in c, implemented using PEG grammar
6
+ Copyright (c) 2008 John MacFarlane
7
+ Additional MultiMarkdown files
8
+ Copyright (c) 2005-2011 Fletcher T. Penney
9
+ Micro-optparse (included in bin/rpeg-multimarkdown)
10
+ Copyright (c) 2011 Florian Pilz
11
+
12
+ Both peg-markdown and the rpeg-markdown license are released under both the GPL
13
+ and MIT licenses. You may pick the license that best fits your needs.
14
+
15
+ Micro-optparse is released under the MIT license.
16
+
17
+ The GPL
18
+
19
+ This program is free software; you can redistribute it and/or modify
20
+ it under the terms of the GNU General Public License as published by
21
+ the Free Software Foundation; either version 2 of the License, or
22
+ (at your option) any later version.
23
+
24
+ This program is distributed in the hope that it will be useful,
25
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27
+ GNU General Public License for more details.
28
+
29
+ You should have received a copy of the GNU General Public License
30
+ along with this program; if not, write to the Free Software
31
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32
+
33
+ The MIT License
34
+
35
+ Permission is hereby granted, free of charge, to any person obtaining a copy
36
+ of this software and associated documentation files (the "Software"), to deal
37
+ in the Software without restriction, including without limitation the rights
38
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
39
+ copies of the Software, and to permit persons to whom the Software is
40
+ furnished to do so, subject to the following conditions:
41
+
42
+ The above copyright notice and this permission notice shall be included in
43
+ all copies or substantial portions of the Software.
44
+
45
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
46
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
47
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
48
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
49
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
50
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
51
+ THE SOFTWARE.
52
+
53
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
54
+
55
+ peg-0.1.4 (included for convenience - http://piumarta.com/software/peg/)
56
+
57
+ Copyright (c) 2007 by Ian Piumarta
58
+ All rights reserved.
59
+
60
+ Permission is hereby granted, free of charge, to any person obtaining a
61
+ copy of this software and associated documentation files (the 'Software'),
62
+ to deal in the Software without restriction, including without limitation
63
+ the rights to use, copy, modify, merge, publish, distribute, and/or sell
64
+ copies of the Software, and to permit persons to whom the Software is
65
+ furnished to do so, provided that the above copyright notice(s) and this
66
+ permission notice appear in all copies of the Software. Acknowledgement
67
+ of the use of this Software in supporting documentation would be
68
+ appreciated but is not required.
69
+
70
+ THE SOFTWARE IS PROVIDED 'AS IS'. USE ENTIRELY AT YOUR OWN RISK.
71
+
72
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
73
+
74
+ my_getopt (included for convenience - http://www.geocities.com/bsittler/)
75
+
76
+ Copyright 1997, 2000, 2001, 2002, 2006, Benjamin Sittler
77
+
78
+ Permission is hereby granted, free of charge, to any person
79
+ obtaining a copy of this software and associated documentation
80
+ files (the "Software"), to deal in the Software without
81
+ restriction, including without limitation the rights to use, copy,
82
+ modify, merge, publish, distribute, sublicense, and/or sell copies
83
+ of the Software, and to permit persons to whom the Software is
84
+ furnished to do so, subject to the following conditions:
85
+
86
+ The above copyright notice and this permission notice shall be
87
+ included in all copies or substantial portions of the Software.
88
+
89
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
90
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
91
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
92
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
93
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
94
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
95
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
96
+ DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,52 @@
1
+ # Ruby PEG MultiMarkdown 2
2
+
3
+ An extension library around [Fletcher Penney's implementation][1]
4
+ of MultiMarkdown in C. This library is based (almost entirely) on
5
+ [rpeg-multimarkdown][2].
6
+
7
+ [1]: http://github.com/fletcher/peg-multimarkdown/
8
+ [2]: https://github.com/djungelvral/rpeg-multimarkdown
9
+
10
+ ## Synopsis
11
+
12
+ >> require 'multimarkdown2'
13
+
14
+ >> puts MultiMarkdown.new('Hello, world.').to_html
15
+ # <p>Hello, world.</p>
16
+
17
+ >> puts MultiMarkdown.new('_Hello World!_', :smart, :filter_html).to_html
18
+ # <p><em>Hello World!</em></p>
19
+
20
+ >> puts MultiMarkdown.new('_Hello World!_').to_latex
21
+ # \emph{Hello World!}
22
+
23
+ >> puts MultiMarkdown.new("Title: Some document\n\nSome text in the document").extract_metadata("title")
24
+ # Some document
25
+
26
+ >> PEGMultiMarkdown.new('Hello! World!')
27
+
28
+ ## Installation / Hacking
29
+
30
+ This library requires a recent version of glib2. All modern GNU userland
31
+ systems should be fine.
32
+
33
+ Install from GEM:
34
+
35
+ $ sudo gem install rpeg-multimarkdown2
36
+
37
+ Hacking:
38
+
39
+ $ git clone git://github.com/AndorChen/rpeg-multimarkdown2.git
40
+ $ cd rpeg-multimarkdown2
41
+ $ rake test
42
+
43
+ ## Changes
44
+
45
+ * [Version 0.1.1](http://github.com/djungelvral/rpeg-multimarkdown/tree/v0.1.1)
46
+
47
+ ## COPYING
48
+
49
+ The peg-markdown, peg-multimarkdown, and Ruby PEG Markdown extension sources
50
+ are licensed under the GPL and the Ruby PEG MultiMarkdown extension sources
51
+ adopts this license. See the file LICENSE included with this distribution for
52
+ more information.
data/Rakefile ADDED
@@ -0,0 +1,167 @@
1
+ require 'rake/clean'
2
+ require 'rubygems'
3
+ require 'rubygems/package_task'
4
+
5
+ task :default => :test
6
+
7
+ DLEXT = RbConfig::CONFIG['DLEXT']
8
+ VERS = '2.0.1'
9
+
10
+ spec = Gem::Specification.new do |s|
11
+ s.name = "rpeg-multimarkdown2"
12
+ s.version = VERS
13
+ s.summary = "Fast MultiMarkdown implementation"
14
+ s.description =<<-EOF
15
+ A Ruby extension to process MultiMarkdown-formatted
16
+ text, using Fletcher Penney's C peg-multimarkdown
17
+ implementation.
18
+ EOF
19
+ s.files = FileList[
20
+ 'README.markdown','LICENSE','Rakefile',
21
+ '{lib,ext,test}/**.rb','ext/*.{c,h}',
22
+ 'test/MultiMarkdownTest/**/*',
23
+ 'bin/rpeg-multimarkdown2'
24
+ ]
25
+ s.bindir = 'bin'
26
+ s.executables << 'rpeg-multimarkdown2'
27
+ s.require_path = 'lib'
28
+ s.extra_rdoc_files = ['LICENSE']
29
+ s.test_files = FileList['test/multimarkdown_test.rb']
30
+ s.extensions = ['ext/extconf.rb']
31
+
32
+ s.authors = ['Andor Chen']
33
+ s.email = ['andor.chen.27@gmail.com']
34
+ s.homepage = 'http://github.com/AndorChen/rpeg-multimarkdown2'
35
+ end
36
+
37
+ # For Mac OS X -- prevents prevent additional ._* files being added to tarball
38
+ ENV['COPYFILE_DISABLE'] = 'true'
39
+
40
+ Gem::PackageTask.new(spec) do |pkg|
41
+ pkg.need_tar_gz = true
42
+ pkg.need_tar = false
43
+ pkg.need_zip = false
44
+ end
45
+
46
+ namespace :submodule do
47
+ desc 'Init the peg-multimarkdown submodule'
48
+ task :init do |t|
49
+ unless File.exist? 'peg-multimarkdown/markdown.c'
50
+ rm_rf 'peg-multimarkdown'
51
+ sh 'git submodule init peg-multimarkdown'
52
+ sh 'git submodule update peg-multimarkdown'
53
+ end
54
+ end
55
+
56
+ desc 'Update the peg-multimarkdown submodule'
57
+ task :update => :init do
58
+ sh 'git submodule update peg-multimarkdown' unless File.symlink?('peg-multimarkdown')
59
+ end
60
+
61
+ file 'peg-multimarkdown/markdown.c' do
62
+ Rake::Task['submodule:init'].invoke
63
+ end
64
+ task :exist => 'peg-multimarkdown/markdown.c'
65
+ end
66
+
67
+ desc 'Gather required peg-multimarkdown sources into extension directory'
68
+ task :gather => 'submodule:exist' do |t|
69
+ sh 'cd peg-multimarkdown && make markdown_parser.c'
70
+ files =
71
+ FileList[
72
+ 'peg-multimarkdown/markdown_{peg.h,parser.c,output.c,lib.c,lib.h}',
73
+ 'peg-multimarkdown/{utility,parsing}_functions.c',
74
+ 'peg-multimarkdown/odf.{c,h}'
75
+ ]
76
+ cp files, 'ext/',
77
+ :preserve => true,
78
+ :verbose => true
79
+ end
80
+
81
+ file 'ext/Makefile' => FileList['ext/{extconf.rb,*.c,*.h,*.rb}'] do
82
+ chdir('ext') { ruby 'extconf.rb' }
83
+ end
84
+ CLEAN.include 'ext/Makefile'
85
+
86
+ file "ext/peg_multimarkdown.#{DLEXT}" => FileList['ext/Makefile', 'ext/*.{c,h,rb}'] do |f|
87
+ sh 'cd ext && make'
88
+ end
89
+ CLEAN.include 'ext/*.{o,bundle,so}'
90
+
91
+ file "lib/peg_multimarkdown.#{DLEXT}" => "ext/peg_multimarkdown.#{DLEXT}" do |f|
92
+ cp f.prerequisites, "lib/", :preserve => true
93
+ end
94
+ CLEAN.include "lib/*.{so,bundle}"
95
+
96
+ desc 'Build the peg_multimarkdown extension'
97
+ task :build => "lib/peg_multimarkdown.#{DLEXT}"
98
+
99
+ desc 'Run unit and conformance tests'
100
+ task :test => [ 'test:unit', 'test:conformance' ]
101
+
102
+ desc 'Run unit tests'
103
+ task 'test:unit' => [:build] do |t|
104
+ ruby 'test/multimarkdown_test.rb'
105
+ end
106
+
107
+ desc "Run conformance tests"
108
+ task 'test:conformance' => [:build] do |t|
109
+ script = "#{pwd}/bin/rpeg-multimarkdown2"
110
+ chdir("test/MultiMarkdownTest") do
111
+ sh "./MarkdownTest.pl --script='#{script}' --flags='-c' --tidy"
112
+ sh "./MarkdownTest.pl --script='#{script}' --testdir='MultiMarkdownTests'"
113
+ sh "./MarkdownTest.pl --script='#{script}' --testdir='MultiMarkdownTests' --flags='-t latex' --ext='.tex'"
114
+ sh "./MarkdownTest.pl --script='#{script}' --testdir='BeamerTests' --flags='-t latex' --ext='.tex'"
115
+ sh "./MarkdownTest.pl --script='#{script}' --testdir='MemoirTests' --flags='-t latex' --ext='.tex'"
116
+ end
117
+ end
118
+
119
+ desc 'Run conformance suite'
120
+ task 'test:conformance' => [:build] do |t|
121
+ Rake::Task['test:conformance'].invoke
122
+ end
123
+
124
+ desc 'Run unit and conformance tests'
125
+ task :test => %w[test:unit test:conformance]
126
+
127
+ desc 'Run benchmarks'
128
+ task :benchmark => :build do |t|
129
+ $:.unshift 'lib'
130
+ load 'test/benchmark.rb'
131
+ end
132
+
133
+ desc "See how much memory we're losing"
134
+ task 'test:mem' => %w[submodule:exist build] do |t|
135
+ $: << File.join(File.dirname(__FILE__), "lib")
136
+ require 'multimarkdown'
137
+ FileList['test/mem.txt', 'peg-multimarkdown/MarkdownTest/Tests/*.text'].each do |file|
138
+ printf "%s: \n", file
139
+ multimarkdown = MultiMarkdown.new(File.read(file),:compatibility)
140
+ iterations = (ENV['N'] || 100).to_i
141
+ total, growth = [], []
142
+ iterations.times do |i|
143
+ start = Time.now
144
+ GC.start
145
+ multimarkdown.to_html
146
+ duration = Time.now - start
147
+ GC.start
148
+ total << `ps -o rss= -p #{Process.pid}`.to_i
149
+ next if i == 0
150
+ growth << (total.last - (total[-2] || 0))
151
+ # puts "%03d: %06.02f ms / %dK used / %dK growth" % [ i, duration, total.last, growth.last ]
152
+ end
153
+ average = growth.inject(0) { |sum,x| sum + x } / growth.length
154
+ printf " %dK avg growth (per run) / %dK used (after %d runs)\n", average, total.last, iterations
155
+ end
156
+ end
157
+
158
+ # ==========================================================
159
+ # Rubyforge
160
+ # ==========================================================
161
+
162
+ PKGNAME = "pkg/rpeg-multimarkdown2-#{VERS}"
163
+
164
+ desc 'Publish new release to rubyforge'
165
+ task :release => [ "#{PKGNAME}.gem", "#{PKGNAME}.tar.gz" ] do |t|
166
+ sh "gem push #{PKGNAME}.gem"
167
+ end
@@ -0,0 +1,128 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'multimarkdown2'
5
+ rescue LoadError => boom
6
+ local_path = File.expand_path(File.dirname(__FILE__))
7
+ $: << "#{local_path}/../lib"
8
+ require 'multimarkdown2'
9
+ end
10
+
11
+ # Option parser -- http://florianpilz.github.com/micro-optparse/
12
+
13
+ require 'ostruct'
14
+ require 'optparse'
15
+
16
+ class Parser
17
+ attr_accessor :banner, :version
18
+ def initialize
19
+ @options = []
20
+ @used_short = []
21
+ yield self if block_given?
22
+ end
23
+
24
+ def option(name, desc, settings = {})
25
+ @options << [name, desc, settings]
26
+ end
27
+
28
+ def short_from(name)
29
+ name.to_s.chars.each do |c|
30
+ next if @used_short.include?(c) || c == "_"
31
+ return c # returns from short_from method
32
+ end
33
+ end
34
+
35
+ def validate(options) # remove this method if you want fewer lines of code and don't need validations
36
+ options.each_pair do |key, value|
37
+ opt = @options.find_all{ |o| o[0] == key }.first
38
+ key = "--" << key.to_s.gsub("_", "-")
39
+ unless opt[2][:value_in_set].nil? || opt[2][:value_in_set].include?(value)
40
+ puts "Parameter for #{key} must be in [" << opt[2][:value_in_set].join(", ") << "]" ; exit(1)
41
+ end
42
+ unless opt[2][:value_matches].nil? || opt[2][:value_matches] =~ value
43
+ puts "Parameter for #{key} must match /" << opt[2][:value_matches].source << "/" ; exit(1)
44
+ end
45
+ unless opt[2][:value_satisfies].nil? || opt[2][:value_satisfies].call(value)
46
+ puts "Parameter for #{key} must satisfy given conditions (see description)" ; exit(1)
47
+ end
48
+ end
49
+ end
50
+
51
+ def process!(arguments = ARGV)
52
+ @result = (@default_values || {}).clone # reset or new
53
+ @optionparser ||= OptionParser.new do |p| # prepare only once
54
+ @options.each do |o|
55
+ @used_short << short = o[2][:short] || short_from(o[0])
56
+ @result[o[0]] = o[2][:default] || false # set default
57
+ klass = o[2][:default].class == Fixnum ? Integer : o[2][:default].class
58
+ desk = o[1] + (o[2][:nodefault] ? "" : " (default is #{@result[o[0]]})")
59
+ if [TrueClass, FalseClass, NilClass].include?(klass) # boolean switch
60
+ p.on("-" << short, "--[no-]" << o[0].to_s.gsub("_", "-"), desk) {|x| @result[o[0]] = x}
61
+ else # argument with parameter
62
+ p.on("-" << short, "--" << o[0].to_s.gsub("_", "-") << " " << (o[2][:name] ? "[#{o[2][:name].to_s}]" : ""), klass, desk) {|x| @result[o[0]] = x}
63
+ end
64
+ end
65
+
66
+ p.banner = @banner unless @banner.nil?
67
+ p.on_tail("-h", "--help", "Show this message") {puts p ; exit}
68
+ short = @used_short.include?("v") ? "-V" : "-v"
69
+ p.on_tail(short, "--version", "Print version") {puts @version ; exit} unless @version.nil?
70
+ @default_values = @result.clone # save default values to reset @result in subsequent calls
71
+ end
72
+
73
+ begin
74
+ @optionparser.parse!(arguments)
75
+ rescue OptionParser::ParseError => e
76
+ puts e.message ; exit(1)
77
+ end
78
+
79
+ validate(@result) if self.respond_to?("validate")
80
+ @result
81
+ end
82
+ end
83
+
84
+ # Parse options
85
+ options = Parser.new do |p|
86
+ p.banner = "Ruby interface to MultiMarkdown"
87
+ p.version = "rpeg-multimarkdown2 2.0.1"
88
+ p.option :compatibility, "markdown compatibility mode", :default => false
89
+ p.option :filter_html, "filter out raw HTML except styles", :default => false
90
+ p.option :process_html, "process MultiMarkdown inside of raw HTML", :default => false
91
+ p.option :filter_styles, "filter out HTML styles", :default => false
92
+ p.option :smart, "use smart typography extension", :default => true
93
+ p.option :notes, "use notes extension", :default => true
94
+ p.option :output, "send output to FILE (default is stdout)", :name => "FILE", :default => "", :nodefault => true
95
+ p.option :to, "convert to FORMAT", :name => "FORMAT", :default => "html", :value_in_set => ["html","latex","memoir","beamer","odf","opml"]
96
+ p.option :extract, "extract and display metadata specified by KEY", :name => "KEY", :default => "", :nodefault => true
97
+ end.process!
98
+
99
+ # Convert options to MultiMarkdown module's options
100
+ mmopts = []
101
+ mmopts << :filter_html if options[:filter_html]
102
+ mmopts << :filter_styles if options[:filter_styles]
103
+ mmopts << :process_html if options[:process_html]
104
+ mmopts << :smart if options[:smart]
105
+ mmopts << :notes if options[:notes]
106
+ mmopts << :compatibility if options[:compatibility]
107
+
108
+ # ARGV will now only contain input filename, if it contains anything
109
+ STDIN.reopen(ARGV[0], 'rb') if ARGV.any?
110
+ multimarkdown = MultiMarkdown.new(STDIN.read,*mmopts)
111
+ STDOUT.reopen(options[:output], 'w') if options[:output]!=""
112
+
113
+ # Print specified metadata if requested
114
+ if options[:extract]!=""
115
+ puts multimarkdown.extract_metadata(options[:extract])
116
+ exit(0)
117
+ end
118
+
119
+ # Do processing
120
+ case options[:to]
121
+ when "html"
122
+ STDOUT.write(multimarkdown.to_html)
123
+ when "latex"
124
+ STDOUT.write(multimarkdown.to_latex)
125
+ else
126
+ puts "Output other than html & latex not currently supported"
127
+ exit(1)
128
+ end
data/ext/extconf.h ADDED
@@ -0,0 +1,3 @@
1
+ #ifndef EXTCONF_H
2
+ #define EXTCONF_H
3
+ #endif
data/ext/extconf.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'mkmf'
2
+
3
+ dir_config('peg_multimarkdown')
4
+
5
+ $objs = %w[markdown.o markdown_lib.o markdown_output.o markdown_parser.o]
6
+
7
+ if pkg_config = find_executable('pkg-config')
8
+ $CFLAGS = "-fcommon "+`#{pkg_config} --cflags glib-2.0`
9
+ $LDFLAGS = `#{pkg_config} --libs glib-2.0`
10
+ else
11
+ fail "glib2 not found"
12
+ end
13
+
14
+ create_header
15
+ create_makefile('peg_multimarkdown')
data/ext/markdown.c ADDED
@@ -0,0 +1,102 @@
1
+ #include "ruby.h"
2
+ #include "markdown_peg.h"
3
+
4
+ static VALUE rb_cMultiMarkdown;
5
+
6
+ int get_exts(VALUE self)
7
+ {
8
+ int extensions = 0;
9
+ if ( rb_funcall(self, rb_intern("smart"), 0) == Qtrue )
10
+ extensions = extensions | EXT_SMART ;
11
+ if ( rb_funcall(self, rb_intern("notes"), 0) == Qtrue )
12
+ extensions = extensions | EXT_NOTES ;
13
+ if ( rb_funcall(self, rb_intern("filter_html"), 0) == Qtrue )
14
+ extensions = extensions | EXT_FILTER_HTML ;
15
+ if ( rb_funcall(self, rb_intern("filter_styles"), 0) == Qtrue )
16
+ extensions = extensions | EXT_FILTER_STYLES ;
17
+ if ( rb_funcall(self, rb_intern("process_html"), 0) == Qtrue )
18
+ extensions = extensions | EXT_PROCESS_HTML;
19
+ /* Compatibility overwrites all other extensions */
20
+ if ( rb_funcall(self, rb_intern("compatibility"), 0) == Qtrue )
21
+ extensions = EXT_COMPATIBILITY;
22
+ return extensions;
23
+ }
24
+
25
+ static VALUE
26
+ rb_multimarkdown_to_html(int argc, VALUE *argv, VALUE self)
27
+ {
28
+ /* grab char pointer to multimarkdown input text */
29
+ VALUE text = rb_funcall(self, rb_intern("text"), 0);
30
+ Check_Type(text, T_STRING);
31
+ char * ptext = StringValuePtr(text);
32
+
33
+ int extensions = get_exts(self);
34
+
35
+ char *html = markdown_to_string(ptext, extensions, HTML_FORMAT);
36
+ VALUE result = rb_str_new2(html);
37
+ free(html);
38
+
39
+ return result;
40
+ }
41
+
42
+ static VALUE
43
+ rb_multimarkdown_to_latex(int argc, VALUE *argv, VALUE self)
44
+ {
45
+ /* grab char pointer to multimarkdown input text */
46
+ VALUE text = rb_funcall(self, rb_intern("text"), 0);
47
+ Check_Type(text, T_STRING);
48
+ char * ptext = StringValuePtr(text);
49
+
50
+ int extensions = get_exts(self);
51
+
52
+ char *latex = markdown_to_string(ptext, extensions, LATEX_FORMAT);
53
+ VALUE result = rb_str_new2(latex);
54
+ free(latex);
55
+
56
+ return result;
57
+ }
58
+
59
+ static VALUE
60
+ rb_multimarkdown_extract_metadata(VALUE self, VALUE key)
61
+ {
62
+ /* grab char pointer to multimarkdown input text */
63
+ VALUE text = rb_funcall(self, rb_intern("text"), 0);
64
+ Check_Type(text, T_STRING);
65
+ char * ptext = StringValuePtr(text);
66
+
67
+ Check_Type(key, T_STRING);
68
+ char * pkey = StringValuePtr(key);
69
+
70
+ int extensions = get_exts(self);
71
+
72
+ /* Display metadata on request */
73
+ char *metadata = extract_metadata_value(ptext, extensions, pkey);
74
+ VALUE result = rb_str_new2(metadata);
75
+ free(metadata);
76
+
77
+ return result;
78
+ }
79
+
80
+ void Init_peg_multimarkdown()
81
+ {
82
+ rb_cMultiMarkdown = rb_define_class("PEGMultiMarkdown", rb_cObject);
83
+ /*
84
+ * Document-method: PEGMultiMarkdown#to_html
85
+ * Return string containing HTML generated from `text`
86
+ */
87
+ rb_define_method(rb_cMultiMarkdown, "to_html", rb_multimarkdown_to_html, -1);
88
+ /*
89
+ * Document-method: PEGMultiMarkdown#to_latex
90
+ * Return string containing latex generated from `text`
91
+ */
92
+ rb_define_method(rb_cMultiMarkdown, "to_latex", rb_multimarkdown_to_latex, -1);
93
+ /*
94
+ * Document-method: PEGMultiMarkdown#extract_metadata
95
+ * call-seq:
96
+ * extract_metadata(key)
97
+ * Extract metadata specified by `key` from `text`
98
+ */
99
+ rb_define_method(rb_cMultiMarkdown, "extract_metadata", rb_multimarkdown_extract_metadata, 1);
100
+ }
101
+
102
+ // vim: ts=4 sw=4