maiku 0.6.1.maiku
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/maruku.rb +141 -0
- data/lib/maruku/attributes.rb +175 -0
- data/lib/maruku/defaults.rb +71 -0
- data/lib/maruku/errors_management.rb +92 -0
- data/lib/maruku/ext/div.rb +133 -0
- data/lib/maruku/ext/math.rb +41 -0
- data/lib/maruku/ext/math/elements.rb +27 -0
- data/lib/maruku/ext/math/latex_fix.rb +12 -0
- data/lib/maruku/ext/math/mathml_engines/blahtex.rb +107 -0
- data/lib/maruku/ext/math/mathml_engines/itex2mml.rb +29 -0
- data/lib/maruku/ext/math/mathml_engines/none.rb +20 -0
- data/lib/maruku/ext/math/mathml_engines/ritex.rb +24 -0
- data/lib/maruku/ext/math/parsing.rb +119 -0
- data/lib/maruku/ext/math/to_html.rb +187 -0
- data/lib/maruku/ext/math/to_latex.rb +26 -0
- data/lib/maruku/helpers.rb +260 -0
- data/lib/maruku/input/charsource.rb +326 -0
- data/lib/maruku/input/extensions.rb +69 -0
- data/lib/maruku/input/html_helper.rb +189 -0
- data/lib/maruku/input/linesource.rb +111 -0
- data/lib/maruku/input/parse_block.rb +616 -0
- data/lib/maruku/input/parse_doc.rb +232 -0
- data/lib/maruku/input/parse_span_better.rb +746 -0
- data/lib/maruku/input/rubypants.rb +225 -0
- data/lib/maruku/input/type_detection.rb +147 -0
- data/lib/maruku/input_textile2/t2_parser.rb +163 -0
- data/lib/maruku/maruku.rb +33 -0
- data/lib/maruku/output/s5/fancy.rb +756 -0
- data/lib/maruku/output/s5/to_s5.rb +138 -0
- data/lib/maruku/output/to_html.rb +991 -0
- data/lib/maruku/output/to_latex.rb +590 -0
- data/lib/maruku/output/to_latex_entities.rb +367 -0
- data/lib/maruku/output/to_latex_strings.rb +64 -0
- data/lib/maruku/output/to_markdown.rb +164 -0
- data/lib/maruku/output/to_s.rb +56 -0
- data/lib/maruku/string_utils.rb +201 -0
- data/lib/maruku/structures.rb +167 -0
- data/lib/maruku/structures_inspect.rb +87 -0
- data/lib/maruku/structures_iterators.rb +61 -0
- data/lib/maruku/textile2.rb +1 -0
- data/lib/maruku/toc.rb +199 -0
- data/lib/maruku/usage/example1.rb +33 -0
- data/lib/maruku/version.rb +39 -0
- metadata +167 -0
@@ -0,0 +1,61 @@
|
|
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
|
+
|
24
|
+
class MDElement
|
25
|
+
|
26
|
+
# Yields to each element of specified node_type
|
27
|
+
# All elements if e_node_type is nil.
|
28
|
+
def each_element(e_node_type=nil, &block)
|
29
|
+
@children.each do |c|
|
30
|
+
if c.kind_of? MDElement
|
31
|
+
if (not e_node_type) || (e_node_type == c.node_type)
|
32
|
+
block.call c
|
33
|
+
end
|
34
|
+
c.each_element(e_node_type, &block)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Apply passed block to each String in the hierarchy.
|
40
|
+
def replace_each_string(&block)
|
41
|
+
for c in @children
|
42
|
+
if c.kind_of? MDElement
|
43
|
+
c.replace_each_string(&block)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
processed = []
|
48
|
+
until @children.empty?
|
49
|
+
c = @children.shift
|
50
|
+
if c.kind_of? String
|
51
|
+
result = block.call(c)
|
52
|
+
[*result].each do |e| processed << e end
|
53
|
+
else
|
54
|
+
processed << c
|
55
|
+
end
|
56
|
+
end
|
57
|
+
@children = processed
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'maruku/input_textile2/t2_parser'
|
data/lib/maruku/toc.rb
ADDED
@@ -0,0 +1,199 @@
|
|
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
|
+
|
24
|
+
class MDDocument
|
25
|
+
# an instance of Section (see below)
|
26
|
+
attr_accessor :toc
|
27
|
+
end
|
28
|
+
|
29
|
+
# This represents a section in the TOC.
|
30
|
+
class Section
|
31
|
+
# a Fixnum, is == header_element.level
|
32
|
+
attr_accessor :section_level
|
33
|
+
|
34
|
+
# An array of fixnum, like [1,2,5] for Section 1.2.5
|
35
|
+
attr_accessor :section_number
|
36
|
+
|
37
|
+
# reference to header (header has h.meta[:section] to self)
|
38
|
+
attr_accessor :header_element
|
39
|
+
|
40
|
+
# Array of immediate children of this element
|
41
|
+
attr_accessor :immediate_children
|
42
|
+
|
43
|
+
# Array of Section inside this section
|
44
|
+
attr_accessor :section_children
|
45
|
+
|
46
|
+
def initialize
|
47
|
+
@immediate_children = []
|
48
|
+
@section_children = []
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class Section
|
53
|
+
def inspect(indent=1)
|
54
|
+
s = ""
|
55
|
+
if @header_element
|
56
|
+
s += "\_"*indent + "(#{@section_level})>\t #{@section_number.join('.')} : "
|
57
|
+
s += @header_element.children_to_s +
|
58
|
+
" (id: '#{@header_element.attributes[:id]}')\n"
|
59
|
+
else
|
60
|
+
s += "Master\n"
|
61
|
+
end
|
62
|
+
|
63
|
+
@section_children.each do |c|
|
64
|
+
s+=c.inspect(indent+1)
|
65
|
+
end
|
66
|
+
s
|
67
|
+
end
|
68
|
+
|
69
|
+
# Numerate this section and its children
|
70
|
+
def numerate(a=[])
|
71
|
+
self.section_number = a
|
72
|
+
section_children.each_with_index do |c,i|
|
73
|
+
c.numerate(a.clone.push(i+1))
|
74
|
+
end
|
75
|
+
if h = self.header_element
|
76
|
+
h.attributes[:section_number] = self.section_number
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
include REXML
|
81
|
+
# Creates an HTML toc.
|
82
|
+
# Call this on the root
|
83
|
+
def to_html
|
84
|
+
div = Element.new 'div'
|
85
|
+
div.attributes['class'] = 'maruku_toc'
|
86
|
+
div << create_toc
|
87
|
+
div
|
88
|
+
end
|
89
|
+
|
90
|
+
def create_toc
|
91
|
+
ul = Element.new 'ul'
|
92
|
+
# let's remove the bullets
|
93
|
+
ul.attributes['style'] = 'list-style: none;'
|
94
|
+
@section_children.each do |c|
|
95
|
+
li = Element.new 'li'
|
96
|
+
if span = c.header_element.render_section_number
|
97
|
+
li << span
|
98
|
+
end
|
99
|
+
a = c.header_element.wrap_as_element('a')
|
100
|
+
a.delete_attribute 'id'
|
101
|
+
a.attributes['href'] = "##{c.header_element.attributes[:id]}"
|
102
|
+
li << a
|
103
|
+
li << c.create_toc if c.section_children.size>0
|
104
|
+
ul << li
|
105
|
+
end
|
106
|
+
ul
|
107
|
+
end
|
108
|
+
|
109
|
+
# Creates a latex toc.
|
110
|
+
# Call this on the root
|
111
|
+
def to_latex
|
112
|
+
to_latex_rec + "\n\n"
|
113
|
+
end
|
114
|
+
|
115
|
+
def to_latex_rec
|
116
|
+
s = ""
|
117
|
+
@section_children.each do |c|
|
118
|
+
s += "\\noindent"
|
119
|
+
number = c.header_element.section_number
|
120
|
+
s += number if number
|
121
|
+
text = c.header_element.children_to_latex
|
122
|
+
id = c.header_element.attributes[:id]
|
123
|
+
s += "\\hyperlink{#{id}}{#{text}}"
|
124
|
+
s += "\\dotfill \\pageref*{#{id}} \\linebreak\n"
|
125
|
+
s += c.to_latex_rec if c.section_children.size>0
|
126
|
+
|
127
|
+
end
|
128
|
+
s
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
class MDDocument
|
134
|
+
|
135
|
+
def create_toc
|
136
|
+
each_element(:header) do |h|
|
137
|
+
h.attributes[:id] ||= h.generate_id
|
138
|
+
end
|
139
|
+
|
140
|
+
stack = []
|
141
|
+
|
142
|
+
# the ancestor section
|
143
|
+
s = Section.new
|
144
|
+
s.section_level = 0
|
145
|
+
|
146
|
+
stack.push s
|
147
|
+
|
148
|
+
i = 0;
|
149
|
+
while i < @children.size
|
150
|
+
while i < @children.size
|
151
|
+
if @children[i].node_type == :header
|
152
|
+
level = @children[i].level
|
153
|
+
break if level <= stack.last.section_level+1
|
154
|
+
end
|
155
|
+
|
156
|
+
stack.last.immediate_children.push @children[i]
|
157
|
+
i += 1
|
158
|
+
end
|
159
|
+
|
160
|
+
break if i>=@children.size
|
161
|
+
|
162
|
+
header = @children[i]
|
163
|
+
level = header.level
|
164
|
+
|
165
|
+
if level > stack.last.section_level
|
166
|
+
# this level is inside
|
167
|
+
|
168
|
+
s2 = Section.new
|
169
|
+
s2.section_level = level
|
170
|
+
s2.header_element = header
|
171
|
+
header.instance_variable_set :@section, s2
|
172
|
+
|
173
|
+
stack.last.section_children.push s2
|
174
|
+
stack.push s2
|
175
|
+
|
176
|
+
i+=1
|
177
|
+
elsif level == stack.last.section_level
|
178
|
+
# this level is a sibling
|
179
|
+
stack.pop
|
180
|
+
else
|
181
|
+
# this level is a parent
|
182
|
+
stack.pop
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
# If there is only one big header, then assume
|
188
|
+
# it is the master
|
189
|
+
if s.section_children.size == 1
|
190
|
+
s = s.section_children.first
|
191
|
+
end
|
192
|
+
|
193
|
+
# Assign section numbers
|
194
|
+
s.numerate
|
195
|
+
|
196
|
+
s
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'maruku'
|
2
|
+
|
3
|
+
text = <<EOF
|
4
|
+
Chapter 1
|
5
|
+
=========
|
6
|
+
|
7
|
+
It was a stormy and rainy night.
|
8
|
+
|
9
|
+
EOF
|
10
|
+
|
11
|
+
invalid = <<EOF
|
12
|
+
|
13
|
+
This is a [bad link.
|
14
|
+
|
15
|
+
EOF
|
16
|
+
|
17
|
+
Maruku.new(text).to_html
|
18
|
+
|
19
|
+
s = ""
|
20
|
+
|
21
|
+
begin
|
22
|
+
Maruku.new(invalid, {:on_error => :raise, :error_stream => s})
|
23
|
+
puts "Error! It should have thrown an exception."
|
24
|
+
rescue
|
25
|
+
# puts "ok, got error"
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
Maruku.new(invalid, {:on_error => :warning, :error_stream => s})
|
30
|
+
rescue
|
31
|
+
puts "Error! It should not have thrown an exception."
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,39 @@
|
|
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
|
+
module MaRuKu
|
22
|
+
Version = '0.6.1.maiku'
|
23
|
+
|
24
|
+
MaikuURL = 'http://www.fogus.me/fun/maiku'
|
25
|
+
|
26
|
+
# If true, use also PHP Markdown extra syntax
|
27
|
+
#
|
28
|
+
# Note: it is not guaranteed that if it's false
|
29
|
+
# then no special features will be used.
|
30
|
+
#
|
31
|
+
# So please, ignore it for now.
|
32
|
+
def markdown_extra?
|
33
|
+
true
|
34
|
+
end
|
35
|
+
|
36
|
+
def new_meta_data?
|
37
|
+
true
|
38
|
+
end
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: maiku
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.6.1.maiku
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Fogus
|
9
|
+
autorequire: maruku
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: syntax
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.0.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.0.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: pry
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: guard-rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: simplecov
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: A Maruku superset compiler.
|
95
|
+
email:
|
96
|
+
executables: []
|
97
|
+
extensions: []
|
98
|
+
extra_rdoc_files: []
|
99
|
+
files:
|
100
|
+
- lib/maruku.rb
|
101
|
+
- lib/maruku/attributes.rb
|
102
|
+
- lib/maruku/defaults.rb
|
103
|
+
- lib/maruku/errors_management.rb
|
104
|
+
- lib/maruku/ext/div.rb
|
105
|
+
- lib/maruku/ext/math.rb
|
106
|
+
- lib/maruku/ext/math/elements.rb
|
107
|
+
- lib/maruku/ext/math/latex_fix.rb
|
108
|
+
- lib/maruku/ext/math/mathml_engines/blahtex.rb
|
109
|
+
- lib/maruku/ext/math/mathml_engines/itex2mml.rb
|
110
|
+
- lib/maruku/ext/math/mathml_engines/none.rb
|
111
|
+
- lib/maruku/ext/math/mathml_engines/ritex.rb
|
112
|
+
- lib/maruku/ext/math/parsing.rb
|
113
|
+
- lib/maruku/ext/math/to_html.rb
|
114
|
+
- lib/maruku/ext/math/to_latex.rb
|
115
|
+
- lib/maruku/helpers.rb
|
116
|
+
- lib/maruku/input/charsource.rb
|
117
|
+
- lib/maruku/input/extensions.rb
|
118
|
+
- lib/maruku/input/html_helper.rb
|
119
|
+
- lib/maruku/input/linesource.rb
|
120
|
+
- lib/maruku/input/parse_block.rb
|
121
|
+
- lib/maruku/input/parse_doc.rb
|
122
|
+
- lib/maruku/input/parse_span_better.rb
|
123
|
+
- lib/maruku/input/rubypants.rb
|
124
|
+
- lib/maruku/input/type_detection.rb
|
125
|
+
- lib/maruku/input_textile2/t2_parser.rb
|
126
|
+
- lib/maruku/maruku.rb
|
127
|
+
- lib/maruku/output/s5/fancy.rb
|
128
|
+
- lib/maruku/output/s5/to_s5.rb
|
129
|
+
- lib/maruku/output/to_html.rb
|
130
|
+
- lib/maruku/output/to_latex.rb
|
131
|
+
- lib/maruku/output/to_latex_entities.rb
|
132
|
+
- lib/maruku/output/to_latex_strings.rb
|
133
|
+
- lib/maruku/output/to_markdown.rb
|
134
|
+
- lib/maruku/output/to_s.rb
|
135
|
+
- lib/maruku/string_utils.rb
|
136
|
+
- lib/maruku/structures.rb
|
137
|
+
- lib/maruku/structures_inspect.rb
|
138
|
+
- lib/maruku/structures_iterators.rb
|
139
|
+
- lib/maruku/textile2.rb
|
140
|
+
- lib/maruku/toc.rb
|
141
|
+
- lib/maruku/usage/example1.rb
|
142
|
+
- lib/maruku/version.rb
|
143
|
+
homepage: http://github.com/fogus/maiku
|
144
|
+
licenses: []
|
145
|
+
post_install_message:
|
146
|
+
rdoc_options: []
|
147
|
+
require_paths:
|
148
|
+
- lib
|
149
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
150
|
+
none: false
|
151
|
+
requirements:
|
152
|
+
- - ! '>='
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
|
+
none: false
|
157
|
+
requirements:
|
158
|
+
- - ! '>'
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: 1.3.1
|
161
|
+
requirements: []
|
162
|
+
rubyforge_project: maiku
|
163
|
+
rubygems_version: 1.8.24
|
164
|
+
signing_key:
|
165
|
+
specification_version: 3
|
166
|
+
summary: A Maruku superset compiler.
|
167
|
+
test_files: []
|