rpeg-multimarkdown 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. data/LICENSE +94 -0
  2. data/README.markdown +58 -0
  3. data/Rakefile +171 -0
  4. data/bin/rpeg-multimarkdown +128 -0
  5. data/ext/extconf.h +3 -0
  6. data/ext/extconf.rb +15 -0
  7. data/ext/markdown.c +88 -0
  8. data/ext/markdown_lib.c +211 -0
  9. data/ext/markdown_lib.h +28 -0
  10. data/ext/markdown_output.c +2704 -0
  11. data/ext/markdown_parser.c +8275 -0
  12. data/ext/markdown_peg.h +142 -0
  13. data/ext/odf.c +179 -0
  14. data/ext/odf.h +3 -0
  15. data/ext/parsing_functions.c +182 -0
  16. data/ext/utility_functions.c +535 -0
  17. data/lib/multimarkdown.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/MarkdownTest.pl +182 -0
  23. data/test/MultiMarkdownTest/MemoirTests/Automatic Labels.html +42 -0
  24. data/test/MultiMarkdownTest/MemoirTests/Automatic Labels.tex +47 -0
  25. data/test/MultiMarkdownTest/MemoirTests/Automatic Labels.text +46 -0
  26. data/test/MultiMarkdownTest/MemoirTests/Base Header Level.html +20 -0
  27. data/test/MultiMarkdownTest/MemoirTests/Base Header Level.tex +19 -0
  28. data/test/MultiMarkdownTest/MemoirTests/Base Header Level.text +16 -0
  29. data/test/MultiMarkdownTest/MemoirTests/BibTeX.html +17 -0
  30. data/test/MultiMarkdownTest/MemoirTests/BibTeX.tex +12 -0
  31. data/test/MultiMarkdownTest/MemoirTests/BibTeX.text +11 -0
  32. data/test/MultiMarkdownTest/MemoirTests/Citations.html +63 -0
  33. data/test/MultiMarkdownTest/MemoirTests/Citations.tex +48 -0
  34. data/test/MultiMarkdownTest/MemoirTests/Citations.text +43 -0
  35. data/test/MultiMarkdownTest/MemoirTests/Definition Lists.html +61 -0
  36. data/test/MultiMarkdownTest/MemoirTests/Definition Lists.tex +63 -0
  37. data/test/MultiMarkdownTest/MemoirTests/Definition Lists.text +40 -0
  38. data/test/MultiMarkdownTest/MemoirTests/Dutch.html +23 -0
  39. data/test/MultiMarkdownTest/MemoirTests/Dutch.tex +18 -0
  40. data/test/MultiMarkdownTest/MemoirTests/Dutch.text +17 -0
  41. data/test/MultiMarkdownTest/MemoirTests/Email.html +48 -0
  42. data/test/MultiMarkdownTest/MemoirTests/Email.tex +61 -0
  43. data/test/MultiMarkdownTest/MemoirTests/Email.text +32 -0
  44. data/test/MultiMarkdownTest/MemoirTests/English.html +23 -0
  45. data/test/MultiMarkdownTest/MemoirTests/English.tex +18 -0
  46. data/test/MultiMarkdownTest/MemoirTests/English.text +17 -0
  47. data/test/MultiMarkdownTest/MemoirTests/Footnotes.html +47 -0
  48. data/test/MultiMarkdownTest/MemoirTests/Footnotes.tex +28 -0
  49. data/test/MultiMarkdownTest/MemoirTests/Footnotes.text +26 -0
  50. data/test/MultiMarkdownTest/MemoirTests/French.html +23 -0
  51. data/test/MultiMarkdownTest/MemoirTests/French.tex +18 -0
  52. data/test/MultiMarkdownTest/MemoirTests/French.text +17 -0
  53. data/test/MultiMarkdownTest/MemoirTests/German.html +23 -0
  54. data/test/MultiMarkdownTest/MemoirTests/German.tex +18 -0
  55. data/test/MultiMarkdownTest/MemoirTests/German.text +17 -0
  56. data/test/MultiMarkdownTest/MemoirTests/GermanGuillemets.html +23 -0
  57. data/test/MultiMarkdownTest/MemoirTests/GermanGuillemets.tex +18 -0
  58. data/test/MultiMarkdownTest/MemoirTests/GermanGuillemets.text +17 -0
  59. data/test/MultiMarkdownTest/MemoirTests/Glossary.html +47 -0
  60. data/test/MultiMarkdownTest/MemoirTests/Glossary.tex +30 -0
  61. data/test/MultiMarkdownTest/MemoirTests/Glossary.text +29 -0
  62. data/test/MultiMarkdownTest/MemoirTests/Line Breaks.html +21 -0
  63. data/test/MultiMarkdownTest/MemoirTests/Line Breaks.tex +16 -0
  64. data/test/MultiMarkdownTest/MemoirTests/Line Breaks.text +16 -0
  65. data/test/MultiMarkdownTest/MemoirTests/Link Attributes.html +40 -0
  66. data/test/MultiMarkdownTest/MemoirTests/Link Attributes.tex +61 -0
  67. data/test/MultiMarkdownTest/MemoirTests/Link Attributes.text +51 -0
  68. data/test/MultiMarkdownTest/MemoirTests/Math.html +22 -0
  69. data/test/MultiMarkdownTest/MemoirTests/Math.tex +16 -0
  70. data/test/MultiMarkdownTest/MemoirTests/Math.text +16 -0
  71. data/test/MultiMarkdownTest/MemoirTests/Memoir Mode.html +24 -0
  72. data/test/MultiMarkdownTest/MemoirTests/Memoir Mode.tex +23 -0
  73. data/test/MultiMarkdownTest/MemoirTests/Memoir Mode.text +20 -0
  74. data/test/MultiMarkdownTest/MemoirTests/MetaData.html +22 -0
  75. data/test/MultiMarkdownTest/MemoirTests/MetaData.tex +14 -0
  76. data/test/MultiMarkdownTest/MemoirTests/MetaData.text +15 -0
  77. data/test/MultiMarkdownTest/MemoirTests/Sanity.html +100 -0
  78. data/test/MultiMarkdownTest/MemoirTests/Sanity.tex +101 -0
  79. data/test/MultiMarkdownTest/MemoirTests/Sanity.text +78 -0
  80. data/test/MultiMarkdownTest/MemoirTests/SmartQuotes.html +26 -0
  81. data/test/MultiMarkdownTest/MemoirTests/SmartQuotes.tex +21 -0
  82. data/test/MultiMarkdownTest/MemoirTests/SmartQuotes.text +19 -0
  83. data/test/MultiMarkdownTest/MemoirTests/Swedish.html +23 -0
  84. data/test/MultiMarkdownTest/MemoirTests/Swedish.tex +18 -0
  85. data/test/MultiMarkdownTest/MemoirTests/Swedish.text +17 -0
  86. data/test/MultiMarkdownTest/MemoirTests/Tables.html +221 -0
  87. data/test/MultiMarkdownTest/MemoirTests/Tables.tex +134 -0
  88. data/test/MultiMarkdownTest/MemoirTests/Tables.text +64 -0
  89. data/test/MultiMarkdownTest/MultiMarkdownTests/Automatic Labels.html +41 -0
  90. data/test/MultiMarkdownTest/MultiMarkdownTests/Automatic Labels.tex +46 -0
  91. data/test/MultiMarkdownTest/MultiMarkdownTests/Automatic Labels.text +45 -0
  92. data/test/MultiMarkdownTest/MultiMarkdownTests/Base Header Level.html +20 -0
  93. data/test/MultiMarkdownTest/MultiMarkdownTests/Base Header Level.tex +19 -0
  94. data/test/MultiMarkdownTest/MultiMarkdownTests/Base Header Level.text +16 -0
  95. data/test/MultiMarkdownTest/MultiMarkdownTests/BibTeX.html +16 -0
  96. data/test/MultiMarkdownTest/MultiMarkdownTests/BibTeX.tex +11 -0
  97. data/test/MultiMarkdownTest/MultiMarkdownTests/BibTex.text +10 -0
  98. data/test/MultiMarkdownTest/MultiMarkdownTests/Citations.html +62 -0
  99. data/test/MultiMarkdownTest/MultiMarkdownTests/Citations.tex +47 -0
  100. data/test/MultiMarkdownTest/MultiMarkdownTests/Citations.text +42 -0
  101. data/test/MultiMarkdownTest/MultiMarkdownTests/Definition Lists.html +60 -0
  102. data/test/MultiMarkdownTest/MultiMarkdownTests/Definition Lists.tex +62 -0
  103. data/test/MultiMarkdownTest/MultiMarkdownTests/Definition Lists.text +39 -0
  104. data/test/MultiMarkdownTest/MultiMarkdownTests/Dutch.html +23 -0
  105. data/test/MultiMarkdownTest/MultiMarkdownTests/Dutch.tex +18 -0
  106. data/test/MultiMarkdownTest/MultiMarkdownTests/Dutch.text +17 -0
  107. data/test/MultiMarkdownTest/MultiMarkdownTests/Email.html +47 -0
  108. data/test/MultiMarkdownTest/MultiMarkdownTests/Email.tex +54 -0
  109. data/test/MultiMarkdownTest/MultiMarkdownTests/Email.text +31 -0
  110. data/test/MultiMarkdownTest/MultiMarkdownTests/English.html +23 -0
  111. data/test/MultiMarkdownTest/MultiMarkdownTests/English.tex +18 -0
  112. data/test/MultiMarkdownTest/MultiMarkdownTests/English.text +17 -0
  113. data/test/MultiMarkdownTest/MultiMarkdownTests/Errors.html +16 -0
  114. data/test/MultiMarkdownTest/MultiMarkdownTests/Errors.tex +11 -0
  115. data/test/MultiMarkdownTest/MultiMarkdownTests/Errors.text +11 -0
  116. data/test/MultiMarkdownTest/MultiMarkdownTests/Footnotes.html +46 -0
  117. data/test/MultiMarkdownTest/MultiMarkdownTests/Footnotes.tex +24 -0
  118. data/test/MultiMarkdownTest/MultiMarkdownTests/Footnotes.text +25 -0
  119. data/test/MultiMarkdownTest/MultiMarkdownTests/French.html +23 -0
  120. data/test/MultiMarkdownTest/MultiMarkdownTests/French.tex +18 -0
  121. data/test/MultiMarkdownTest/MultiMarkdownTests/French.text +17 -0
  122. data/test/MultiMarkdownTest/MultiMarkdownTests/German.html +23 -0
  123. data/test/MultiMarkdownTest/MultiMarkdownTests/German.tex +18 -0
  124. data/test/MultiMarkdownTest/MultiMarkdownTests/German.text +17 -0
  125. data/test/MultiMarkdownTest/MultiMarkdownTests/GermanGuillemets.html +23 -0
  126. data/test/MultiMarkdownTest/MultiMarkdownTests/GermanGuillemets.tex +18 -0
  127. data/test/MultiMarkdownTest/MultiMarkdownTests/GermanGuillemets.text +17 -0
  128. data/test/MultiMarkdownTest/MultiMarkdownTests/Glossary.html +46 -0
  129. data/test/MultiMarkdownTest/MultiMarkdownTests/Glossary.tex +26 -0
  130. data/test/MultiMarkdownTest/MultiMarkdownTests/Glossary.text +28 -0
  131. data/test/MultiMarkdownTest/MultiMarkdownTests/Headers.html +46 -0
  132. data/test/MultiMarkdownTest/MultiMarkdownTests/Headers.tex +52 -0
  133. data/test/MultiMarkdownTest/MultiMarkdownTests/Headers.text +49 -0
  134. data/test/MultiMarkdownTest/MultiMarkdownTests/Line Breaks.html +20 -0
  135. data/test/MultiMarkdownTest/MultiMarkdownTests/Line Breaks.tex +15 -0
  136. data/test/MultiMarkdownTest/MultiMarkdownTests/Line Breaks.text +15 -0
  137. data/test/MultiMarkdownTest/MultiMarkdownTests/Link Attributes.html +54 -0
  138. data/test/MultiMarkdownTest/MultiMarkdownTests/Link Attributes.tex +60 -0
  139. data/test/MultiMarkdownTest/MultiMarkdownTests/Link Attributes.text +50 -0
  140. data/test/MultiMarkdownTest/MultiMarkdownTests/List Parsing.html +20 -0
  141. data/test/MultiMarkdownTest/MultiMarkdownTests/List Parsing.tex +17 -0
  142. data/test/MultiMarkdownTest/MultiMarkdownTests/List Parsing.text +11 -0
  143. data/test/MultiMarkdownTest/MultiMarkdownTests/MarkdownInHTML.html +19 -0
  144. data/test/MultiMarkdownTest/MultiMarkdownTests/MarkdownInHTML.tex +13 -0
  145. data/test/MultiMarkdownTest/MultiMarkdownTests/MarkdownInHTML.text +19 -0
  146. data/test/MultiMarkdownTest/MultiMarkdownTests/Math.html +21 -0
  147. data/test/MultiMarkdownTest/MultiMarkdownTests/Math.tex +15 -0
  148. data/test/MultiMarkdownTest/MultiMarkdownTests/Math.text +15 -0
  149. data/test/MultiMarkdownTest/MultiMarkdownTests/MetaData.html +21 -0
  150. data/test/MultiMarkdownTest/MultiMarkdownTests/MetaData.tex +13 -0
  151. data/test/MultiMarkdownTest/MultiMarkdownTests/MetaData.text +14 -0
  152. data/test/MultiMarkdownTest/MultiMarkdownTests/Sanity.html +104 -0
  153. data/test/MultiMarkdownTest/MultiMarkdownTests/Sanity.tex +100 -0
  154. data/test/MultiMarkdownTest/MultiMarkdownTests/Sanity.text +77 -0
  155. data/test/MultiMarkdownTest/MultiMarkdownTests/SmartQuotes.html +29 -0
  156. data/test/MultiMarkdownTest/MultiMarkdownTests/SmartQuotes.tex +24 -0
  157. data/test/MultiMarkdownTest/MultiMarkdownTests/SmartQuotes.text +22 -0
  158. data/test/MultiMarkdownTest/MultiMarkdownTests/Swedish.html +23 -0
  159. data/test/MultiMarkdownTest/MultiMarkdownTests/Swedish.tex +18 -0
  160. data/test/MultiMarkdownTest/MultiMarkdownTests/Swedish.text +17 -0
  161. data/test/MultiMarkdownTest/MultiMarkdownTests/Tables.html +230 -0
  162. data/test/MultiMarkdownTest/MultiMarkdownTests/Tables.tex +133 -0
  163. data/test/MultiMarkdownTest/MultiMarkdownTests/Tables.text +63 -0
  164. data/test/MultiMarkdownTest/MultiMarkdownTests/bibtex.bib +119 -0
  165. data/test/MultiMarkdownTest/README.md +58 -0
  166. data/test/MultiMarkdownTest/Tests/Amps and angle encoding.html +17 -0
  167. data/test/MultiMarkdownTest/Tests/Amps and angle encoding.text +21 -0
  168. data/test/MultiMarkdownTest/Tests/Auto links.html +18 -0
  169. data/test/MultiMarkdownTest/Tests/Auto links.text +13 -0
  170. data/test/MultiMarkdownTest/Tests/Backslash escapes.html +118 -0
  171. data/test/MultiMarkdownTest/Tests/Backslash escapes.text +120 -0
  172. data/test/MultiMarkdownTest/Tests/Blockquotes with code blocks.html +15 -0
  173. data/test/MultiMarkdownTest/Tests/Blockquotes with code blocks.text +11 -0
  174. data/test/MultiMarkdownTest/Tests/Code Blocks.html +18 -0
  175. data/test/MultiMarkdownTest/Tests/Code Blocks.text +14 -0
  176. data/test/MultiMarkdownTest/Tests/Code Spans.html +6 -0
  177. data/test/MultiMarkdownTest/Tests/Code Spans.text +6 -0
  178. data/test/MultiMarkdownTest/Tests/Compatibility.html +5 -0
  179. data/test/MultiMarkdownTest/Tests/Compatibility.text +9 -0
  180. data/test/MultiMarkdownTest/Tests/Hard-wrapped paragraphs with list-like lines.html +8 -0
  181. data/test/MultiMarkdownTest/Tests/Hard-wrapped paragraphs with list-like lines.text +8 -0
  182. data/test/MultiMarkdownTest/Tests/Horizontal rules.html +71 -0
  183. data/test/MultiMarkdownTest/Tests/Horizontal rules.text +67 -0
  184. data/test/MultiMarkdownTest/Tests/Inline HTML (Advanced).html +15 -0
  185. data/test/MultiMarkdownTest/Tests/Inline HTML (Advanced).text +15 -0
  186. data/test/MultiMarkdownTest/Tests/Inline HTML (Simple).html +72 -0
  187. data/test/MultiMarkdownTest/Tests/Inline HTML (Simple).text +69 -0
  188. data/test/MultiMarkdownTest/Tests/Inline HTML comments.html +13 -0
  189. data/test/MultiMarkdownTest/Tests/Inline HTML comments.text +13 -0
  190. data/test/MultiMarkdownTest/Tests/Links, inline style.html +11 -0
  191. data/test/MultiMarkdownTest/Tests/Links, inline style.text +12 -0
  192. data/test/MultiMarkdownTest/Tests/Links, reference style.html +52 -0
  193. data/test/MultiMarkdownTest/Tests/Links, reference style.text +71 -0
  194. data/test/MultiMarkdownTest/Tests/Links, shortcut references.html +9 -0
  195. data/test/MultiMarkdownTest/Tests/Links, shortcut references.text +20 -0
  196. data/test/MultiMarkdownTest/Tests/Literal quotes in titles.html +3 -0
  197. data/test/MultiMarkdownTest/Tests/Literal quotes in titles.text +7 -0
  198. data/test/MultiMarkdownTest/Tests/Markdown Documentation - Basics.html +314 -0
  199. data/test/MultiMarkdownTest/Tests/Markdown Documentation - Basics.text +306 -0
  200. data/test/MultiMarkdownTest/Tests/Markdown Documentation - Syntax.html +942 -0
  201. data/test/MultiMarkdownTest/Tests/Markdown Documentation - Syntax.text +888 -0
  202. data/test/MultiMarkdownTest/Tests/Nested blockquotes.html +9 -0
  203. data/test/MultiMarkdownTest/Tests/Nested blockquotes.text +5 -0
  204. data/test/MultiMarkdownTest/Tests/Ordered and unordered lists.html +148 -0
  205. data/test/MultiMarkdownTest/Tests/Ordered and unordered lists.text +131 -0
  206. data/test/MultiMarkdownTest/Tests/Strong and em together.html +7 -0
  207. data/test/MultiMarkdownTest/Tests/Strong and em together.text +7 -0
  208. data/test/MultiMarkdownTest/Tests/Tabs.html +25 -0
  209. data/test/MultiMarkdownTest/Tests/Tabs.text +21 -0
  210. data/test/MultiMarkdownTest/Tests/Tidyness.html +8 -0
  211. data/test/MultiMarkdownTest/Tests/Tidyness.text +5 -0
  212. data/test/benchmark.rb +49 -0
  213. data/test/multimarkdown_test.rb +89 -0
  214. metadata +280 -0
@@ -0,0 +1,142 @@
1
+ /* markdown_peg.h */
2
+ #include "markdown_lib.h"
3
+ #include <glib.h>
4
+
5
+ extern char *strdup(const char *string);
6
+
7
+ /* Information (label, URL and title) for a link. */
8
+ struct Link {
9
+ struct Element *label;
10
+ char *url;
11
+ char *title;
12
+ struct Element *attr;
13
+ char *identifier;
14
+ };
15
+
16
+ typedef struct Link link;
17
+
18
+ /* Union for contents of an Element (string, list, or link). */
19
+ union Contents {
20
+ char *str;
21
+ struct Link *link;
22
+ };
23
+
24
+ /* Types of semantic values returned by parsers. */
25
+ enum keys { LIST, /* A generic list of values. For ordered and bullet lists, see below. */
26
+ RAW, /* Raw markdown to be processed further */
27
+ SPACE,
28
+ LINEBREAK,
29
+ ELLIPSIS,
30
+ EMDASH,
31
+ ENDASH,
32
+ APOSTROPHE,
33
+ SINGLEQUOTED,
34
+ DOUBLEQUOTED,
35
+ STR,
36
+ LINK,
37
+ IMAGE,
38
+ IMAGEBLOCK,
39
+ CODE,
40
+ HTML,
41
+ EMPH,
42
+ STRONG,
43
+ PLAIN,
44
+ PARA,
45
+ LISTITEM,
46
+ BULLETLIST,
47
+ ORDEREDLIST,
48
+ H1, H2, H3, H4, H5, H6, H7, /* Code assumes that these are in order. */
49
+ BLOCKQUOTE,
50
+ VERBATIM,
51
+ HTMLBLOCK,
52
+ HRULE,
53
+ REFERENCE,
54
+ NOTE,
55
+ CITATION,
56
+ NOCITATION,
57
+ LOCATOR,
58
+ NOTELABEL,
59
+ DEFLIST,
60
+ TERM,
61
+ DEFINITION,
62
+ METAKEY,
63
+ METAVALUE,
64
+ METADATA,
65
+ FOOTER,
66
+ LABEL,
67
+ HEADINGSECTION,
68
+ ENDHTML,
69
+ TABLE,
70
+ TABLEHEAD,
71
+ TABLEBODY,
72
+ TABLEROW,
73
+ TABLECELL,
74
+ CELLSPAN,
75
+ TABLECAPTION,
76
+ TABLELABEL,
77
+ TABLESEPARATOR,
78
+ AUTOLABEL,
79
+ ATTRIBUTE,
80
+ ATTRKEY,
81
+ ATTRVALUE,
82
+ GLOSSARY,
83
+ GLOSSARYTERM,
84
+ GLOSSARYSORTKEY,
85
+ MATHSPAN
86
+ };
87
+
88
+ /* constants for managing Smart Typography */
89
+ enum smartelements {
90
+ LSQUOTE,
91
+ RSQUOTE,
92
+ LDQUOTE,
93
+ RDQUOTE,
94
+ NDASH,
95
+ MDASH,
96
+ ELLIP,
97
+ APOS,
98
+ };
99
+
100
+ enum smartoutput {
101
+ HTMLOUT,
102
+ LATEXOUT,
103
+ };
104
+
105
+ enum language {
106
+ DUTCH,
107
+ ENGLISH,
108
+ FRENCH,
109
+ GERMAN,
110
+ SWEDISH,
111
+ GERMANGUILL,
112
+ };
113
+
114
+ /* Semantic value of a parsing action. */
115
+ struct Element {
116
+ int key;
117
+ union Contents contents;
118
+ struct Element *children;
119
+ struct Element *next;
120
+ };
121
+
122
+
123
+
124
+ typedef struct Element element;
125
+
126
+ element * parse_references(char *string, int extensions);
127
+ element * parse_notes(char *string, int extensions, element *reference_list);
128
+ element * parse_labels(char *string, int extensions, element *reference_list, element *note_list);
129
+
130
+ element * parse_markdown(char *string, int extensions, element *reference_list, element *note_list, element *label_list);
131
+ element * parse_markdown_with_metadata(char *string, int extensions, element *reference_list, element *note_list, element *label_list);
132
+ void free_element_list(element * elt);
133
+ void free_element(element *elt);
134
+ void print_element_list(GString *out, element *elt, int format, int exts);
135
+
136
+
137
+ element * parse_metadata_only(char *string, int extensions);
138
+ char * extract_metadata_value(char *text, int extensions, char *key);
139
+
140
+ char * metavalue_for_key(char *key, element *list);
141
+
142
+ element * parse_markdown_for_opml(char *string, int extensions);
data/ext/odf.c ADDED
@@ -0,0 +1,179 @@
1
+ /**********************************************************************
2
+
3
+ odf.c - Utility routines to enable ODF support in peg-multimarkdown.
4
+ (c) 2011 Fletcher T. Penney (http://fletcherpenney.net/).
5
+
6
+ This program is free software; you can redistribute it and/or modify
7
+ it under the terms of the GNU General Public License or the MIT
8
+ license. See LICENSE for details.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ ***********************************************************************/
16
+
17
+
18
+ void print_odf_header(GString *out){
19
+
20
+ /* Insert required XML header */
21
+ g_string_append_printf(out,
22
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" \
23
+ "<office:document xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"\n" \
24
+ " xmlns:style=\"urn:oasis:names:tc:opendocument:xmlns:style:1.0\"\n" \
25
+ " xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\"\n" \
26
+ " xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\"\n" \
27
+ " xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\"\n" \
28
+ " xmlns:fo=\"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0\"\n" \
29
+ " xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n" \
30
+ " xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n" \
31
+ " xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"\n" \
32
+ " xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\"\n" \
33
+ " xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\"\n" \
34
+ " xmlns:chart=\"urn:oasis:names:tc:opendocument:xmlns:chart:1.0\"\n" \
35
+ " xmlns:dr3d=\"urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0\"\n" \
36
+ " xmlns:math=\"http://www.w3.org/1998/Math/MathML\"\n" \
37
+ " xmlns:form=\"urn:oasis:names:tc:opendocument:xmlns:form:1.0\"\n" \
38
+ " xmlns:script=\"urn:oasis:names:tc:opendocument:xmlns:script:1.0\"\n" \
39
+ " xmlns:config=\"urn:oasis:names:tc:opendocument:xmlns:config:1.0\"\n" \
40
+ " xmlns:ooo=\"http://openoffice.org/2004/office\"\n" \
41
+ " xmlns:ooow=\"http://openoffice.org/2004/writer\"\n" \
42
+ " xmlns:oooc=\"http://openoffice.org/2004/calc\"\n" \
43
+ " xmlns:dom=\"http://www.w3.org/2001/xml-events\"\n" \
44
+ " xmlns:xforms=\"http://www.w3.org/2002/xforms\"\n" \
45
+ " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n" \
46
+ " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" \
47
+ " xmlns:rpt=\"http://openoffice.org/2005/report\"\n" \
48
+ " xmlns:of=\"urn:oasis:names:tc:opendocument:xmlns:of:1.2\"\n" \
49
+ " xmlns:xhtml=\"http://www.w3.org/1999/xhtml\"\n" \
50
+ " xmlns:grddl=\"http://www.w3.org/2003/g/data-view#\"\n" \
51
+ " xmlns:tableooo=\"http://openoffice.org/2009/table\"\n" \
52
+ " xmlns:field=\"urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0\"\n" \
53
+ " xmlns:formx=\"urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0\"\n" \
54
+ " xmlns:css3t=\"http://www.w3.org/TR/css3-text/\"\n" \
55
+ " office:version=\"1.2\"\n" \
56
+ " grddl:transformation=\"http://docs.oasis-open.org/office/1.2/xslt/odf2rdf.xsl\"\n" \
57
+ " office:mimetype=\"application/vnd.oasis.opendocument.text\">\n");
58
+
59
+ /* Font Declarations */
60
+ g_string_append_printf(out, "<office:font-face-decls>\n" \
61
+ " <style:font-face style:name=\"Courier New\" svg:font-family=\"'Courier New'\"\n" \
62
+ " style:font-adornments=\"Regular\"\n" \
63
+ " style:font-family-generic=\"modern\"\n" \
64
+ " style:font-pitch=\"fixed\"/>\n" \
65
+ "</office:font-face-decls>\n");
66
+
67
+ /* Append basic style information */
68
+ g_string_append_printf(out, "<office:styles>\n" \
69
+ "<style:style style:name=\"Standard\" style:family=\"paragraph\" style:class=\"text\">\n" \
70
+ " <style:paragraph-properties fo:margin-top=\"0in\" fo:margin-bottom=\"0.15in\"" \
71
+ " fo:text-align=\"justify\" style:justify-single-word=\"false\"/>\n" \
72
+ " </style:style>\n" \
73
+ "<style:style style:name=\"Preformatted_20_Text\" style:display-name=\"Preformatted Text\"\n" \
74
+ " style:family=\"paragraph\"\n" \
75
+ " style:parent-style-name=\"Standard\"\n" \
76
+ " style:class=\"html\">\n" \
77
+ " <style:paragraph-properties fo:margin-top=\"0in\" fo:margin-bottom=\"0in\" fo:text-align=\"start\"\n" \
78
+ " style:justify-single-word=\"false\"/>\n" \
79
+ " <style:text-properties style:font-name=\"Courier New\" fo:font-size=\"11pt\"\n" \
80
+ " style:font-name-asian=\"Courier New\"\n" \
81
+ " style:font-size-asian=\"11pt\"\n" \
82
+ " style:font-name-complex=\"Courier New\"\n" \
83
+ " style:font-size-complex=\"11pt\"/>\n" \
84
+ "</style:style>\n" \
85
+ "<style:style style:name=\"Source_20_Text\" style:display-name=\"Source Text\"\n" \
86
+ " style:family=\"text\">\n" \
87
+ " <style:text-properties style:font-name=\"Courier New\" style:font-name-asian=\"Courier New\"\n" \
88
+ " style:font-name-complex=\"Courier New\"\n" \
89
+ " fo:font-size=\"11pt\"/>\n" \
90
+ "</style:style>\n" \
91
+ "<style:style style:name=\"List\" style:family=\"paragraph\"\n" \
92
+ " style:parent-style-name=\"Standard\"\n" \
93
+ " style:class=\"list\">\n" \
94
+ " <style:paragraph-properties fo:text-align=\"start\" style:justify-single-word=\"false\"/>\n" \
95
+ " <style:text-properties style:font-size-asian=\"12pt\"/>\n" \
96
+ "</style:style>\n" \
97
+ "<style:style style:name=\"Quotations\" style:family=\"paragraph\"\n" \
98
+ " style:parent-style-name=\"Standard\"\n" \
99
+ " style:class=\"html\">\n" \
100
+ " <style:paragraph-properties fo:margin-left=\"0.3937in\" fo:margin-right=\"0.3937in\" fo:margin-top=\"0in\"\n" \
101
+ " fo:margin-bottom=\"0.1965in\"\n" \
102
+ " fo:text-align=\"justify\"" \
103
+ " style:justify-single-word=\"false\"" \
104
+ " fo:text-indent=\"0in\"\n" \
105
+ " style:auto-text-indent=\"false\"/>\n" \
106
+ "</style:style>\n" \
107
+ "<style:style style:name=\"Table_20_Heading\" style:display-name=\"Table Heading\"\n" \
108
+ " style:family=\"paragraph\"\n" \
109
+ " style:parent-style-name=\"Table_20_Contents\"\n" \
110
+ " style:class=\"extra\">\n" \
111
+ " <style:paragraph-properties fo:text-align=\"center\" style:justify-single-word=\"false\"\n" \
112
+ " text:number-lines=\"false\"\n" \
113
+ " text:line-number=\"0\"/>\n" \
114
+ " <style:text-properties fo:font-weight=\"bold\" style:font-weight-asian=\"bold\"\n" \
115
+ " style:font-weight-complex=\"bold\"/>\n" \
116
+ "</style:style>\n" \
117
+ "<style:style style:name=\"Horizontal_20_Line\" style:display-name=\"Horizontal Line\"\n" \
118
+ " style:family=\"paragraph\"\n" \
119
+ " style:parent-style-name=\"Standard\"\n" \
120
+ " style:class=\"html\">\n" \
121
+ " <style:paragraph-properties fo:margin-top=\"0in\" fo:margin-bottom=\"0.1965in\"\n" \
122
+ " style:border-line-width-bottom=\"0.0008in 0.0138in 0.0008in\"\n" \
123
+ " fo:padding=\"0in\"\n" \
124
+ " fo:border-left=\"none\"\n" \
125
+ " fo:border-right=\"none\"\n" \
126
+ " fo:border-top=\"none\"\n" \
127
+ " fo:border-bottom=\"0.0154in double #808080\"\n" \
128
+ " text:number-lines=\"false\"\n" \
129
+ " text:line-number=\"0\"\n" \
130
+ " style:join-border=\"false\"/>\n" \
131
+ " <style:text-properties fo:font-size=\"6pt\" style:font-size-asian=\"6pt\" style:font-size-complex=\"6pt\"/>\n" \
132
+ "</style:style>\n" \
133
+ "</office:styles>\n");
134
+
135
+ /* Automatic style information */
136
+ g_string_append_printf(out, "<office:automatic-styles>" \
137
+ " <style:style style:name=\"MMD-Italic\" style:family=\"text\">\n" \
138
+ " <style:text-properties fo:font-style=\"italic\" style:font-style-asian=\"italic\"\n" \
139
+ " style:font-style-complex=\"italic\"/>\n" \
140
+ " </style:style>\n" \
141
+ " <style:style style:name=\"MMD-Bold\" style:family=\"text\">\n" \
142
+ " <style:text-properties fo:font-weight=\"bold\" style:font-weight-asian=\"bold\"\n" \
143
+ " style:font-weight-complex=\"bold\"/>\n" \
144
+ " </style:style>\n" \
145
+ "<style:style style:name=\"MMD-Table\" style:family=\"paragraph\" style:parent-style-name=\"Standard\">\n" \
146
+ " <style:paragraph-properties fo:margin-top=\"0in\" fo:margin-bottom=\"0.05in\"/>\n" \
147
+ "</style:style>\n" \
148
+ "<style:style style:name=\"MMD-Table-Center\" style:family=\"paragraph\" style:parent-style-name=\"MMD-Table\">\n" \
149
+ " <style:paragraph-properties fo:text-align=\"center\" style:justify-single-word=\"false\"/>\n" \
150
+ "</style:style>\n" \
151
+ "<style:style style:name=\"MMD-Table-Right\" style:family=\"paragraph\" style:parent-style-name=\"MMD-Table\">\n" \
152
+ " <style:paragraph-properties fo:text-align=\"right\" style:justify-single-word=\"false\"/>\n" \
153
+ "</style:style>\n" \
154
+ "<style:style style:name=\"P2\" style:family=\"paragraph\" style:parent-style-name=\"Standard\"\n" \
155
+ " style:list-style-name=\"L2\">\n" \
156
+ "<style:paragraph-properties fo:text-align=\"start\" style:justify-single-word=\"false\"/>\n" \
157
+ "</style:style>\n" \
158
+ "<style:style style:name=\"fr1\" style:family=\"graphic\" style:parent-style-name=\"Frame\">\n" \
159
+ " <style:graphic-properties style:print-content=\"false\" style:vertical-pos=\"top\"\n" \
160
+ " style:vertical-rel=\"baseline\"\n" \
161
+ " fo:padding=\"0in\"\n" \
162
+ " fo:border=\"none\"\n" \
163
+ " style:shadow=\"none\"/>\n" \
164
+ "</style:style>\n" \
165
+ "</office:automatic-styles>\n" \
166
+ "<style:style style:name=\"P1\" style:family=\"paragraph\" style:parent-style-name=\"Standard\"\n" \
167
+ " style:list-style-name=\"L1\"/>\n" \
168
+ "<text:list-style style:name=\"L1\">\n" \
169
+ " <text:list-level-style-bullet />\n" \
170
+ "</text:list-style>\n" \
171
+ "<text:list-style style:name=\"L2\">\n" \
172
+ " <text:list-level-style-number />\n" \
173
+ "</text:list-style>\n");
174
+ }
175
+
176
+ void print_odf_footer(GString *out) {
177
+ g_string_append_printf(out, "</office:text>\n</office:body>\n</office:document>");
178
+ }
179
+
data/ext/odf.h ADDED
@@ -0,0 +1,3 @@
1
+ #include <stdlib.h>
2
+ #include <stdio.h>
3
+ #include <glib.h>
@@ -0,0 +1,182 @@
1
+ /* parsing_functions.c - Functions for parsing markdown and
2
+ * freeing element lists. */
3
+
4
+ int yyparse(void);
5
+
6
+ static void free_element_contents(element elt);
7
+
8
+ /* free_element_list - free list of elements recursively */
9
+ void free_element_list(element * elt) {
10
+ element * next = NULL;
11
+ while (elt != NULL) {
12
+ next = elt->next;
13
+ free_element_contents(*elt);
14
+ if (elt->children != NULL) {
15
+ free_element_list(elt->children);
16
+ elt->children = NULL;
17
+ }
18
+ free(elt);
19
+ elt = next;
20
+ }
21
+ }
22
+
23
+ /* free_element_contents - free element contents depending on type */
24
+ static void free_element_contents(element elt) {
25
+ switch (elt.key) {
26
+ case STR:
27
+ case SPACE:
28
+ case RAW:
29
+ case HTMLBLOCK:
30
+ case HTML:
31
+ case VERBATIM:
32
+ case CODE:
33
+ case NOTE:
34
+ case AUTOLABEL:
35
+ case CITATION:
36
+ case TERM:
37
+ case METAKEY:
38
+ case METAVALUE:
39
+ case TABLESEPARATOR:
40
+ case ATTRKEY:
41
+ case GLOSSARY:
42
+ case GLOSSARYTERM:
43
+ case NOTELABEL:
44
+ free(elt.contents.str);
45
+ elt.contents.str = NULL;
46
+ break;
47
+ case LINK:
48
+ case IMAGE:
49
+ case REFERENCE:
50
+ free(elt.contents.link->url);
51
+ elt.contents.link->url = NULL;
52
+ free(elt.contents.link->title);
53
+ elt.contents.link->title = NULL;
54
+ free_element_list(elt.contents.link->label);
55
+ free(elt.contents.link->identifier);
56
+ elt.contents.link->identifier = NULL;
57
+ /* free_element_list(elt.contents.link->attr);*/
58
+ free(elt.contents.link);
59
+ elt.contents.link = NULL;
60
+ break;
61
+ default:
62
+ ;
63
+ }
64
+ }
65
+
66
+ /* free_element - free element and contents */
67
+ void free_element(element *elt) {
68
+ free_element_contents(*elt);
69
+ free(elt);
70
+ }
71
+
72
+ element * parse_references(char *string, int extensions) {
73
+
74
+ char *oldcharbuf;
75
+ syntax_extensions = extensions;
76
+
77
+ oldcharbuf = charbuf;
78
+ charbuf = string;
79
+ yyparsefrom(yy_References); /* first pass, just to collect references */
80
+ charbuf = oldcharbuf;
81
+
82
+ return references;
83
+ }
84
+
85
+ element * parse_notes(char *string, int extensions, element *reference_list) {
86
+
87
+ char *oldcharbuf;
88
+ notes = NULL;
89
+ syntax_extensions = extensions;
90
+
91
+ if (extension(EXT_NOTES)) {
92
+ references = reference_list;
93
+ oldcharbuf = charbuf;
94
+ charbuf = string;
95
+ yyparsefrom(yy_Notes); /* second pass for notes */
96
+ charbuf = oldcharbuf;
97
+ }
98
+
99
+ return notes;
100
+ }
101
+
102
+ element * parse_labels(char *string, int extensions, element *reference_list, element *note_list) {
103
+
104
+ char *oldcharbuf;
105
+ syntax_extensions = extensions;
106
+ references = reference_list;
107
+ notes = note_list;
108
+ labels = NULL;
109
+
110
+ oldcharbuf = charbuf;
111
+ charbuf = string;
112
+ yyparsefrom(yy_AutoLabels); /* third pass, to collect labels */
113
+ charbuf = oldcharbuf;
114
+
115
+ return labels;
116
+ }
117
+
118
+ element * parse_markdown(char *string, int extensions, element *reference_list, element *note_list, element *label_list) {
119
+
120
+ char *oldcharbuf;
121
+ syntax_extensions = extensions;
122
+ references = reference_list;
123
+ notes = note_list;
124
+ labels = label_list;
125
+
126
+ oldcharbuf = charbuf;
127
+ charbuf = string;
128
+
129
+ yyparsefrom(yy_Doc);
130
+
131
+ charbuf = oldcharbuf; /* restore charbuf to original value */
132
+ return parse_result;
133
+
134
+ }
135
+
136
+ element * parse_markdown_with_metadata(char *string, int extensions, element *reference_list, element *note_list, element *label_list) {
137
+
138
+ char *oldcharbuf;
139
+ syntax_extensions = extensions;
140
+ references = reference_list;
141
+ notes = note_list;
142
+ labels = label_list;
143
+
144
+ oldcharbuf = charbuf;
145
+ charbuf = string;
146
+
147
+ yyparsefrom(yy_DocWithMetaData);
148
+
149
+ charbuf = oldcharbuf; /* restore charbuf to original value */
150
+ return parse_result;
151
+
152
+ }
153
+
154
+ element * parse_metadata_only(char *string, int extensions) {
155
+
156
+ char *oldcharbuf;
157
+ syntax_extensions = extensions;
158
+
159
+ oldcharbuf = charbuf;
160
+ charbuf = string;
161
+
162
+ yyparsefrom(yy_MetaDataOnly);
163
+
164
+ charbuf = oldcharbuf; /* restore charbuf to original value */
165
+ return parse_result;
166
+
167
+ }
168
+
169
+ element * parse_markdown_for_opml(char *string, int extensions) {
170
+
171
+ char *oldcharbuf;
172
+ syntax_extensions = extensions;
173
+
174
+ oldcharbuf = charbuf;
175
+ charbuf = string;
176
+
177
+ yyparsefrom(yy_DocForOPML);
178
+
179
+ charbuf = oldcharbuf; /* restore charbuf to original value */
180
+ return parse_result;
181
+
182
+ }