maruku 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/bin/{maruku0.3 → marudown} +6 -14
  2. data/bin/maruku +1 -1
  3. data/bin/marutest +37 -9
  4. data/docs/TOFIX.html +22 -0
  5. data/docs/TOFIX.md +3 -0
  6. data/docs/changelog-0.2.13.html +30 -0
  7. data/docs/changelog-0.2.13.md +6 -0
  8. data/docs/changelog-0.3.html +19 -5
  9. data/docs/faq.html +51 -40
  10. data/docs/faq.md +3 -3
  11. data/docs/hidden_o_n_squared.md +10 -0
  12. data/docs/index.html +84 -396
  13. data/docs/markdown_syntax.html +139 -330
  14. data/docs/markdown_syntax.md +80 -93
  15. data/docs/maruku.html +84 -396
  16. data/docs/maruku.md +88 -158
  17. data/docs/proposal.html +13 -106
  18. data/docs/proposal.md +3 -3
  19. data/docs/todo.html +38 -28
  20. data/lib/maruku.rb +77 -11
  21. data/lib/maruku/attributes.rb +186 -0
  22. data/lib/maruku/defaults.rb +40 -0
  23. data/lib/maruku/errors_management.rb +55 -39
  24. data/lib/maruku/helpers.rb +156 -72
  25. data/lib/maruku/input/charsource.rb +319 -0
  26. data/lib/maruku/{html_helper.rb → input/html_helper.rb} +30 -9
  27. data/lib/maruku/input/linesource.rb +111 -0
  28. data/lib/maruku/input/parse_block.rb +562 -0
  29. data/lib/maruku/{parse_doc.rb → input/parse_doc.rb} +60 -28
  30. data/lib/maruku/{parse_span_better.rb → input/parse_span_better.rb} +226 -256
  31. data/lib/maruku/input/type_detection.rb +137 -0
  32. data/lib/maruku/maruku.rb +33 -0
  33. data/lib/maruku/{to_html.rb → output/to_html.rb} +151 -132
  34. data/lib/maruku/{to_latex.rb → output/to_latex.rb} +31 -35
  35. data/lib/maruku/{to_latex_entities.rb → output/to_latex_entities.rb} +25 -3
  36. data/lib/maruku/output/to_latex_strings.rb +64 -0
  37. data/lib/maruku/output/to_markdown.rb +164 -0
  38. data/lib/maruku/{to_s.rb → output/to_s.rb} +6 -0
  39. data/lib/maruku/string_utils.rb +12 -181
  40. data/lib/maruku/structures.rb +91 -67
  41. data/lib/maruku/structures_inspect.rb +78 -0
  42. data/lib/maruku/structures_iterators.rb +24 -2
  43. data/lib/maruku/tests/benchmark.rb +41 -9
  44. data/lib/maruku/tests/new_parser.rb +317 -286
  45. data/lib/maruku/tests/tests.rb +20 -0
  46. data/lib/maruku/toc.rb +64 -64
  47. data/lib/maruku/usage/example1.rb +33 -0
  48. data/lib/maruku/version.rb +8 -2
  49. data/tests/unittest/abbreviations.md +27 -16
  50. data/tests/unittest/attributes/attributes.md +89 -0
  51. data/tests/unittest/attributes/circular.md +51 -0
  52. data/tests/unittest/attributes/default.md +47 -0
  53. data/tests/unittest/blank.md +10 -6
  54. data/tests/unittest/blanks_in_code.md +26 -26
  55. data/tests/unittest/code.md +9 -9
  56. data/tests/unittest/code2.md +12 -13
  57. data/tests/unittest/code3.md +34 -34
  58. data/tests/unittest/easy.md +9 -7
  59. data/tests/unittest/email.md +9 -7
  60. data/tests/unittest/encoding/iso-8859-1.md +41 -4
  61. data/tests/unittest/encoding/utf-8.md +6 -5
  62. data/tests/unittest/entities.md +52 -80
  63. data/tests/unittest/escaping.md +47 -35
  64. data/tests/unittest/extra_dl.md +19 -29
  65. data/tests/unittest/extra_header_id.md +31 -24
  66. data/tests/unittest/extra_table1.md +14 -32
  67. data/tests/unittest/footnotes.md +58 -42
  68. data/tests/unittest/headers.md +11 -11
  69. data/tests/unittest/hrule.md +14 -24
  70. data/tests/unittest/images.md +41 -26
  71. data/tests/unittest/inline_html.md +104 -56
  72. data/tests/unittest/inline_html2.md +38 -0
  73. data/tests/unittest/links.md +74 -33
  74. data/tests/unittest/list1.md +18 -15
  75. data/tests/unittest/list2.md +31 -13
  76. data/tests/unittest/list3.md +29 -28
  77. data/tests/unittest/list4.md +103 -12
  78. data/tests/unittest/lists.md +86 -53
  79. data/tests/unittest/lists6.md +53 -0
  80. data/tests/unittest/lists7.md +31 -0
  81. data/tests/unittest/lists_after_paragraph.md +105 -71
  82. data/tests/unittest/lists_ol.md +149 -73
  83. data/tests/unittest/misc_sw.md +366 -326
  84. data/tests/unittest/notyet/escape.md +10 -10
  85. data/tests/unittest/notyet/header_after_par.md +20 -14
  86. data/tests/unittest/notyet/ticks.md +8 -35
  87. data/tests/unittest/notyet/triggering.md +72 -45
  88. data/tests/unittest/olist.md +78 -0
  89. data/tests/unittest/one.md +5 -3
  90. data/tests/unittest/paragraph.md +5 -3
  91. data/tests/unittest/paragraph_rules/dont_merge_ref.md +15 -9
  92. data/tests/unittest/paragraph_rules/tab_is_blank.md +9 -5
  93. data/tests/unittest/paragraphs.md +21 -26
  94. data/tests/unittest/recover/recover_links.md +6 -5
  95. data/tests/unittest/references/long_example.md +39 -30
  96. data/tests/unittest/references/spaces_and_numbers.md +2 -2
  97. data/tests/unittest/syntax_hl.md +33 -31
  98. data/tests/unittest/test.md +4 -6
  99. data/tests/unittest/wrapping.md +43 -26
  100. metadata +160 -139
  101. data/docs/markdown_extra2.html +0 -87
  102. data/docs/markdown_extra2.md +0 -83
  103. data/docs/markdown_syntax_2.html +0 -152
  104. data/lib/maruku/parse_block.rb +0 -564
  105. data/lib/maruku/parse_span.rb +0 -451
  106. data/lib/maruku/to_latex_strings.rb +0 -59
  107. data/lib/maruku/to_markdown.rb +0 -110
  108. data/lib/test.rb +0 -29
data/docs/proposal.md CHANGED
@@ -14,9 +14,9 @@ Last updated **January 2nd, 2007**: integrated topics
14
14
  discussed in mailing list.
15
15
 
16
16
  *Table of contents:*
17
- > @toc
18
- > * Table of contents
19
17
 
18
+ > * Table of contents
19
+ > {toc}
20
20
 
21
21
  Overview
22
22
  --------
@@ -113,7 +113,6 @@ So this is not legal:
113
113
 
114
114
  Attribute lists may be indented up to 3 spaces:
115
115
 
116
- @ code_show_spaces
117
116
  Paragraph1
118
117
  {ok}
119
118
 
@@ -122,6 +121,7 @@ Attribute lists may be indented up to 3 spaces:
122
121
 
123
122
  Paragraph2
124
123
  {ok}
124
+ {code_show_spaces}
125
125
 
126
126
  ### For headers ###
127
127
 
data/docs/todo.html CHANGED
@@ -1,30 +1,40 @@
1
- <?xml version='1.0' ?>
1
+ <?xml version='1.0' encoding='utf-8'?>
2
2
  <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
3
3
  'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
4
- <html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'
5
- ><head
6
- ><title></title
7
- ></head
8
- ><head
9
- ><title></title
10
- ></head
11
- ><body
12
- ><ul
13
- ><li
14
- ><p>Export to HTML * Include RubyPants</p
15
- ></li
16
- ><li
17
- ><p>Export to PDF * support for images</p
18
- ></li
19
- ><li
20
- ><p>Export to Markdown (pretty-printing)</p
21
- ></li
22
- ></ul
23
- ><div class='maruku_signature'
24
- ><hr
25
- /><span style='font-size: small; font-style: italic'>Created by <a href='http://maruku.rubyforge.org' title='Maruku: a Markdown interpreter'>Maruku</a
26
- > at 17:47 on Sunday, December 31st, 2006.</span
27
- ></div
28
- ></body
29
- ></html
30
- >
4
+ <html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'>
5
+ <head><meta content='text/html; charset=utf-8' http-equiv='Content-type' />
6
+ <title></title>
7
+ </head>
8
+ <body>
9
+ <ul>
10
+ <li>
11
+ <p>Export to HTML</p>
12
+
13
+ <ul>
14
+ <li>Include RubyPants</li>
15
+ </ul>
16
+ </li>
17
+
18
+ <li>
19
+ <p>Export to PDF</p>
20
+
21
+ <ul>
22
+ <li>support for images</li>
23
+ </ul>
24
+ </li>
25
+
26
+ <li>
27
+ <p>Export to Markdown (pretty-printing)</p>
28
+ </li>
29
+ </ul>
30
+
31
+ <div class='footnotes'>
32
+ <hr />
33
+
34
+ <ol />
35
+ </div>
36
+
37
+ <div class='maruku_signature'>
38
+ <hr />
39
+ <span style='font-size: small; font-style: italic'>Created by <a href='http://maruku.rubyforge.org' title='Maruku: a Markdown interpreter'>Maruku</a> at 20:36 on Friday, January 05th, 2007.</span></div>
40
+ </body></html>
data/lib/maruku.rb CHANGED
@@ -1,3 +1,4 @@
1
+ #--
1
2
  # Copyright (C) 2006 Andrea Censi <andrea (at) rubyforge.org>
2
3
  #
3
4
  # This file is part of Maruku.
@@ -15,32 +16,94 @@
15
16
  # You should have received a copy of the GNU General Public License
16
17
  # along with Maruku; if not, write to the Free Software
17
18
  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #++
20
+
21
+ # :include:MaRuKu.txt
22
+ module MaRuKu
23
+
24
+ module In
25
+ module Markdown
26
+ module SpanLevelParser; end
27
+ module BlockLevelParser; end
28
+ end
29
+ # more to come?
30
+ end
31
+
32
+ module Out
33
+ # Functions for exporting to MarkDown.
34
+ module Markdown; end
35
+ # Functions for exporting to HTML.
36
+ module HTML; end
37
+ # Functions for exporting to Latex
38
+ module Latex; end
39
+ end
40
+
41
+ # These are strings utilities.
42
+ module Strings; end
43
+
44
+ module Helpers; end
45
+
46
+ module Errors; end
47
+
48
+ module Defaults; end
49
+
50
+ class MDElement
51
+ include Defaults
52
+ include MaRuKu
53
+ include Out::Markdown
54
+ include Out::HTML
55
+ include Out::Latex
56
+ include Strings
57
+ include Helpers
58
+ include Errors
59
+ end
60
+
61
+
62
+ class MDDocument < MDElement
63
+ include In::Markdown::SpanLevelParser
64
+ include In::Markdown::BlockLevelParser
65
+ end
66
+ end
67
+
68
+ # This is the public interface
69
+ class Maruku < MaRuKu::MDDocument; end
70
+
71
+
72
+
73
+ require 'rexml/document'
18
74
 
19
75
  # Structures definition
20
76
  require 'maruku/structures'
77
+ require 'maruku/structures_inspect'
78
+
79
+ require 'maruku/defaults'
21
80
  # Less typing
22
81
  require 'maruku/helpers'
23
82
 
24
83
  # Code for parsing whole Markdown documents
25
- require 'maruku/parse_doc'
84
+ require 'maruku/input/parse_doc'
26
85
 
27
86
  # Ugly things kept in a closet
28
87
  require 'maruku/string_utils'
88
+ require 'maruku/input/linesource'
89
+ require 'maruku/input/type_detection'
29
90
 
30
91
  # A class for reading and sanitizing inline HTML
31
- require 'maruku/html_helper'
92
+ require 'maruku/input/html_helper'
32
93
 
33
94
  # Code for parsing Markdown block-level elements
34
- require 'maruku/parse_block'
95
+ require 'maruku/input/parse_block'
35
96
 
36
97
  # Code for parsing Markdown span-level elements
37
- require 'maruku/parse_span_better'
98
+ require 'maruku/input/charsource'
99
+ require 'maruku/input/parse_span_better'
100
+
101
+ require 'maruku/attributes'
38
102
 
39
103
  require 'maruku/structures_iterators'
40
104
 
41
105
  require 'maruku/errors_management'
42
106
 
43
-
44
107
  # Code for creating a table of contents
45
108
  require 'maruku/toc'
46
109
 
@@ -49,15 +112,18 @@ require 'maruku/version'
49
112
 
50
113
 
51
114
  # Exporting to html
52
- require 'maruku/to_html'
115
+ require 'maruku/output/to_html'
53
116
 
54
117
  # Exporting to latex
55
- require 'maruku/to_latex'
56
- require 'maruku/to_latex_strings'
57
- require 'maruku/to_latex_entities'
118
+ require 'maruku/output/to_latex'
119
+ require 'maruku/output/to_latex_strings'
120
+ require 'maruku/output/to_latex_entities'
58
121
 
59
122
  # Pretty print
60
- require 'maruku/to_markdown'
123
+ require 'maruku/output/to_markdown'
61
124
 
62
125
  # Exporting to text: strips all formatting (not complete)
63
- require 'maruku/to_s'
126
+ require 'maruku/output/to_s'
127
+
128
+ # class Maruku is the global interface
129
+ require 'maruku/maruku'
@@ -0,0 +1,186 @@
1
+ #--
2
+ # Copyright (C) 2006 Andrea Censi <andrea (at) rubyforge.org>
3
+ #
4
+ # This file is part of Maruku.
5
+ #
6
+ # Maruku is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation; either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Maruku is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Maruku; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #++
20
+
21
+
22
+ class String
23
+ def quote_if_needed
24
+ if /[\s\'\"]/.match self
25
+ inspect
26
+ else
27
+ self
28
+ end
29
+ end
30
+ end
31
+
32
+ module MaRuKu;
33
+
34
+ class AttributeList < Array
35
+
36
+ # An attribute list becomes
37
+ # {#id .cl key="val" ref}
38
+ # [ [:id, 'id'], [:class, 'id'], ['key', 'val'], [ :ref, 'ref' ]]
39
+
40
+ private :push
41
+
42
+ def push_key_val(key, val);
43
+ raise "Bad #{key.inspect}=#{val.inspect}" if not key and val
44
+ push [key, val]
45
+ end
46
+ def push_ref(ref_id);
47
+ raise "Bad :ref #{ref_id.inspect}" if not ref_id
48
+ push [:ref, ref_id]
49
+ end
50
+ def push_class(val);
51
+ raise "Bad :id #{val.inspect}" if not val
52
+ push [:class, val]
53
+ end
54
+ def push_id(val);
55
+ raise "Bad :id #{val.inspect}" if not val
56
+ push [:id, val]
57
+ end
58
+
59
+ def to_s
60
+ map do |k,v|
61
+ case k
62
+ when :id; "#" + v.quote_if_needed
63
+ when :class; "." + v.quote_if_needed
64
+ when :ref; v.quote_if_needed
65
+ else k.quote_if_needed + "=" + v.quote_if_needed
66
+ end
67
+ end . join(' ')
68
+ end
69
+ alias to_md to_s
70
+ end
71
+
72
+ end
73
+
74
+ module MaRuKu; module In; module Markdown; module SpanLevelParser
75
+
76
+ def unit_tests_for_attribute_lists
77
+ [
78
+ [ "", [], "Empty lists are allowed" ],
79
+ [ "=", :throw, "Bad char to begin a list with." ],
80
+ [ "a =b", :throw, "No whitespace before `=`." ],
81
+ [ "a= b", :throw, "No whitespace after `=`." ],
82
+
83
+ [ "'a'", [[:ref, 'a']], "Quoted value." ],
84
+ [ '"a"' ],
85
+
86
+ [ "a=b", [['a','b']], "Simple key/val" ],
87
+ [ "'a'=b" ],
88
+ [ "'a'='b'" ],
89
+ [ "a='b'" ],
90
+
91
+ [ 'a="b\'"', [['a',"b\'"]], "Key/val with quotes" ],
92
+ [ 'a=b\''],
93
+ [ 'a="\\\'b\'"', [['a',"\'b\'"]], "Key/val with quotes" ],
94
+
95
+ ['"', :throw, "Unclosed quotes"],
96
+ ["'"],
97
+ ["'a "],
98
+ ['"a '],
99
+
100
+ [ "#a", [[:id, 'a']], "Simple ID" ],
101
+ [ "#'a'" ],
102
+ [ '#"a"' ],
103
+
104
+ [ "#", :throw, "Unfinished '#'." ],
105
+ [ ".", :throw, "Unfinished '.'." ],
106
+ [ "# a", :throw, "No white-space after '#'." ],
107
+ [ ". a", :throw, "No white-space after '.' ." ],
108
+
109
+ [ "a=b c=d", [['a','b'],['c','d']], "Tabbing" ],
110
+ [ " \ta=b \tc='d' "],
111
+ [ "\t a=b\t c='d'\t\t"],
112
+
113
+ [ ".\"a'", :throw, "Mixing quotes is bad." ],
114
+
115
+ ].map { |s, expected, comment|
116
+ @expected = (expected ||= @expected)
117
+ @comment = (comment ||= (last=@comment) )
118
+ (comment == last && (comment += (@count+=1).to_s)) || @count = 1
119
+ expected = [md_ial(expected)] if expected.kind_of? Array
120
+ ["{#{s}}", expected, "Attributes: #{comment}"]
121
+ }
122
+ end
123
+
124
+ def md_al(s=[]); AttributeList.new(s) end
125
+
126
+ # returns nil or an AttributeList
127
+ def read_attribute_list(src, con, break_on_chars)
128
+ separators = break_on_chars + [?=,?\ ,?\t]
129
+ escaped = Maruku::EscapedCharInQuotes
130
+
131
+ al = AttributeList.new
132
+ while true
133
+ src.consume_whitespace
134
+ break if break_on_chars.include? src.cur_char
135
+
136
+ case src.cur_char
137
+ when nil
138
+ maruku_error "Attribute list terminated by EOF:\n "+
139
+ "#{al.inspect}" , src, con
140
+ tell_user "I try to continue and return partial attribute list:\n"+
141
+ al.inspect
142
+ break
143
+ when ?= # error
144
+ maruku_error "In attribute lists, cannot start identifier with `=`."
145
+ tell_user "I try to continue"
146
+ src.ignore_char
147
+ when ?# # id definition
148
+ src.ignore_char
149
+ if id = read_quoted_or_unquoted(src, con, escaped, separators)
150
+ al.push_id id
151
+ else
152
+ maruku_error 'Could not read `id` attribute.', src, con
153
+ tell_user 'Trying to ignore bad `id` attribute.'
154
+ end
155
+ when ?. # class definition
156
+ src.ignore_char
157
+ if klass = read_quoted_or_unquoted(src, con, escaped, separators)
158
+ al.push_class klass
159
+ else
160
+ maruku_error 'Could not read `class` attribute.', src, con
161
+ tell_user 'Trying to ignore bad `class` attribute.'
162
+ end
163
+ else
164
+ if key = read_quoted_or_unquoted(src, con, escaped, separators)
165
+ if src.cur_char == ?=
166
+ src.ignore_char # skip the =
167
+ if val = read_quoted_or_unquoted(src, con, escaped, separators)
168
+ al.push_key_val(key, val)
169
+ else
170
+ maruku_error "Could not read value for key #{key.inspect}.",
171
+ src, con
172
+ tell_user "Ignoring key #{key.inspect}."
173
+ end
174
+ else
175
+ al.push_ref key
176
+ end
177
+ else
178
+ maruku_error 'Could not read key or reference.'
179
+ end
180
+ end # case
181
+ end # while true
182
+ al
183
+ end
184
+
185
+ end end end end
186
+ #module MaRuKu; module In; module Markdown; module SpanLevelParser
@@ -0,0 +1,40 @@
1
+ #--
2
+ # Copyright (C) 2006 Andrea Censi <andrea (at) rubyforge.org>
3
+ #
4
+ # This file is part of Maruku.
5
+ #
6
+ # Maruku is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation; either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Maruku is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Maruku; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #++
20
+
21
+
22
+ module MaRuKu
23
+ module Defaults
24
+ DEFAULT_CODE_COLOR = '#ffaaff'
25
+
26
+ DefaultAttributes = <<EOF
27
+
28
+ {header}: .mrk-header
29
+ {paragraph}: .mrk-par
30
+ {strong}: .mrk-strong
31
+ {emphasis}: .mrk-em
32
+ {code}: .mrk-code
33
+ {code_block}: .mrk-code_block
34
+
35
+ {example}: pre_filter=""
36
+
37
+ EOF
38
+
39
+ end
40
+ end