Bayeux 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.hgrc +2 -0
- data/.rvmrc +27 -0
- data/Gemfile +42 -0
- data/Gemfile.lock +42 -0
- data/HISTORY +63 -0
- data/README.rdoc +19 -0
- data/Rakefile +89 -0
- data/VERSION +1 -0
- data/bib/Modules.bib +21 -0
- data/code/render/latex/active4d.render +132 -0
- data/code/render/latex/all_hallows_eve.render +96 -0
- data/code/render/latex/amy.render +171 -0
- data/code/render/latex/blackboard.render +111 -0
- data/code/render/latex/brilliance_black.render +552 -0
- data/code/render/latex/brilliance_dull.render +561 -0
- data/code/render/latex/cobalt.render +162 -0
- data/code/render/latex/dawn.render +126 -0
- data/code/render/latex/eiffel.render +132 -0
- data/code/render/latex/espresso_libre.render +123 -0
- data/code/render/latex/idle.render +93 -0
- data/code/render/latex/iplastic.render +99 -0
- data/code/render/latex/lazy.render +96 -0
- data/code/render/latex/mac_classic.render +135 -0
- data/code/render/latex/magicwb_amiga.render +117 -0
- data/code/render/latex/pastels_on_dark.render +204 -0
- data/code/render/latex/slush_poppies.render +123 -0
- data/code/render/latex/spacecadet.render +81 -0
- data/code/render/latex/sunburst.render +186 -0
- data/code/render/latex/twilight.render +153 -0
- data/code/render/latex/zenburnesque.render +126 -0
- data/code/render/old/txt2tags.render +131 -0
- data/code/render/xhtml/active4d.render +140 -0
- data/code/render/xhtml/all_hallows_eve.render +104 -0
- data/code/render/xhtml/amy.render +179 -0
- data/code/render/xhtml/blackboard.render +119 -0
- data/code/render/xhtml/brilliance_black.render +560 -0
- data/code/render/xhtml/brilliance_dull.render +569 -0
- data/code/render/xhtml/cobalt.render +170 -0
- data/code/render/xhtml/dawn.render +134 -0
- data/code/render/xhtml/eiffel.render +140 -0
- data/code/render/xhtml/espresso_libre.render +131 -0
- data/code/render/xhtml/files/css/active4d.css +114 -0
- data/code/render/xhtml/files/css/all_hallows_eve.css +72 -0
- data/code/render/xhtml/files/css/amy.css +147 -0
- data/code/render/xhtml/files/css/blackboard.css +88 -0
- data/code/render/xhtml/files/css/brilliance_black.css +605 -0
- data/code/render/xhtml/files/css/brilliance_dull.css +599 -0
- data/code/render/xhtml/files/css/cobalt.css +149 -0
- data/code/render/xhtml/files/css/dawn.css +121 -0
- data/code/render/xhtml/files/css/eiffel.css +121 -0
- data/code/render/xhtml/files/css/espresso_libre.css +109 -0
- data/code/render/xhtml/files/css/idle.css +62 -0
- data/code/render/xhtml/files/css/iplastic.css +80 -0
- data/code/render/xhtml/files/css/lazy.css +73 -0
- data/code/render/xhtml/files/css/mac_classic.css +123 -0
- data/code/render/xhtml/files/css/magicwb_amiga.css +104 -0
- data/code/render/xhtml/files/css/pastels_on_dark.css +188 -0
- data/code/render/xhtml/files/css/slush_poppies.css +85 -0
- data/code/render/xhtml/files/css/spacecadet.css +51 -0
- data/code/render/xhtml/files/css/sunburst.css +180 -0
- data/code/render/xhtml/files/css/twilight.css +137 -0
- data/code/render/xhtml/files/css/zenburnesque.css +91 -0
- data/code/render/xhtml/idle.render +101 -0
- data/code/render/xhtml/iplastic.render +107 -0
- data/code/render/xhtml/lazy.render +104 -0
- data/code/render/xhtml/mac_classic.render +143 -0
- data/code/render/xhtml/magicwb_amiga.render +125 -0
- data/code/render/xhtml/pastels_on_dark.render +212 -0
- data/code/render/xhtml/slush_poppies.render +131 -0
- data/code/render/xhtml/spacecadet.render +89 -0
- data/code/render/xhtml/sunburst.render +194 -0
- data/code/render/xhtml/twilight.render +161 -0
- data/code/render/xhtml/zenburnesque.render +134 -0
- data/code/syntax/actionscript.syntax +97 -0
- data/code/syntax/active4d.syntax +276 -0
- data/code/syntax/active4d_html.syntax +311 -0
- data/code/syntax/active4d_ini.syntax +50 -0
- data/code/syntax/active4d_library.syntax +21 -0
- data/code/syntax/ada.syntax +33 -0
- data/code/syntax/antlr.syntax +151 -0
- data/code/syntax/apache.syntax +191 -0
- data/code/syntax/applescript.syntax +384 -0
- data/code/syntax/asp.syntax +70 -0
- data/code/syntax/asp_vb.net.syntax +129 -0
- data/code/syntax/bibtex.syntax +151 -0
- data/code/syntax/blog_html.syntax +41 -0
- data/code/syntax/blog_markdown.syntax +42 -0
- data/code/syntax/blog_text.syntax +27 -0
- data/code/syntax/blog_textile.syntax +27 -0
- data/code/syntax/build.syntax +53 -0
- data/code/syntax/bulletin_board.syntax +287 -0
- data/code/syntax/cake.syntax +55 -0
- data/code/syntax/camlp4.syntax +36 -0
- data/code/syntax/cm.syntax +32 -0
- data/code/syntax/coldfusion.syntax +119 -0
- data/code/syntax/context_free.syntax +176 -0
- data/code/syntax/cs.syntax +59 -0
- data/code/syntax/css.syntax +195 -0
- data/code/syntax/css_experimental.syntax +1925 -0
- data/code/syntax/csv.syntax +68 -0
- data/code/syntax/d.syntax +142 -0
- data/code/syntax/diff.syntax +81 -0
- data/code/syntax/dokuwiki.syntax +204 -0
- data/code/syntax/dot.syntax +47 -0
- data/code/syntax/doxygen.syntax +43 -0
- data/code/syntax/dylan.syntax +62 -0
- data/code/syntax/eiffel.syntax +78 -0
- data/code/syntax/erlang.syntax +922 -0
- data/code/syntax/f-script.syntax +80 -0
- data/code/syntax/fortran.syntax +141 -0
- data/code/syntax/fxscript.syntax +142 -0
- data/code/syntax/greasemonkey.syntax +34 -0
- data/code/syntax/gri.syntax +83 -0
- data/code/syntax/groovy.syntax +191 -0
- data/code/syntax/gtd.syntax +22 -0
- data/code/syntax/gtdalt.syntax +143 -0
- data/code/syntax/haml.syntax +88 -0
- data/code/syntax/haskell.syntax +88 -0
- data/code/syntax/html-asp.syntax +27 -0
- data/code/syntax/html.syntax +362 -0
- data/code/syntax/html_django.syntax +36 -0
- data/code/syntax/html_for_asp.net.syntax +424 -0
- data/code/syntax/html_mason.syntax +119 -0
- data/code/syntax/html_rails.syntax +40 -0
- data/code/syntax/html_tcl.syntax +26 -0
- data/code/syntax/icalendar.syntax +32 -0
- data/code/syntax/inform.syntax +48 -0
- data/code/syntax/ini.syntax +55 -0
- data/code/syntax/installer_distribution_script.syntax +77 -0
- data/code/syntax/io.syntax +81 -0
- data/code/syntax/java.syntax +211 -0
- data/code/syntax/javaproperties.syntax +20 -0
- data/code/syntax/javascript.syntax +256 -0
- data/code/syntax/javascript_+_prototype.syntax +72 -0
- data/code/syntax/javascript_+_prototype_bracketed.syntax +140 -0
- data/code/syntax/jquery_javascript.syntax +114 -0
- data/code/syntax/json.syntax +136 -0
- data/code/syntax/languagedefinition.syntax +708 -0
- data/code/syntax/latex.syntax +566 -0
- data/code/syntax/latex_beamer.syntax +41 -0
- data/code/syntax/latex_log.syntax +50 -0
- data/code/syntax/latex_memoir.syntax +64 -0
- data/code/syntax/lexflex.syntax +219 -0
- data/code/syntax/lighttpd.syntax +54 -0
- data/code/syntax/lilypond.syntax +492 -0
- data/code/syntax/lisp.syntax +61 -0
- data/code/syntax/literate_haskell.syntax +24 -0
- data/code/syntax/logo.syntax +29 -0
- data/code/syntax/logtalk.syntax +152 -0
- data/code/syntax/lua.syntax +86 -0
- data/code/syntax/m.syntax +142 -0
- data/code/syntax/macports_portfile.syntax +163 -0
- data/code/syntax/makefile.syntax +36 -0
- data/code/syntax/man.syntax +17 -0
- data/code/syntax/mediawiki.syntax +567 -0
- data/code/syntax/mips.syntax +66 -0
- data/code/syntax/mod_perl.syntax +50 -0
- data/code/syntax/modula-3.syntax +47 -0
- data/code/syntax/moinmoin.syntax +189 -0
- data/code/syntax/mootools.syntax +572 -0
- data/code/syntax/movable_type.syntax +162 -0
- data/code/syntax/multimarkdown.syntax +39 -0
- data/code/syntax/objective-c++.syntax +18 -0
- data/code/syntax/objective-c.syntax +233 -0
- data/code/syntax/ocaml.syntax +764 -0
- data/code/syntax/ocamllex.syntax +167 -0
- data/code/syntax/ocamlyacc.syntax +184 -0
- data/code/syntax/opengl.syntax +14 -0
- data/code/syntax/pascal.syntax +77 -0
- data/code/syntax/perl.syntax +1115 -0
- data/code/syntax/plain_text.syntax +32 -0
- data/code/syntax/postscript.syntax +114 -0
- data/code/syntax/processing.syntax +106 -0
- data/code/syntax/prolog.syntax +40 -0
- data/code/syntax/property_list.syntax +635 -0
- data/code/syntax/python.syntax +868 -0
- data/code/syntax/python_django.syntax +21 -0
- data/code/syntax/qmake_project.syntax +114 -0
- data/code/syntax/qt_c++.syntax +26 -0
- data/code/syntax/quake3_config.syntax +32 -0
- data/code/syntax/r.syntax +81 -0
- data/code/syntax/r_console.syntax +16 -0
- data/code/syntax/ragel.syntax +201 -0
- data/code/syntax/rd_r_documentation.syntax +91 -0
- data/code/syntax/regexp.syntax +50 -0
- data/code/syntax/release_notes.syntax +46 -0
- data/code/syntax/remind.syntax +253 -0
- data/code/syntax/restructuredtext.syntax +250 -0
- data/code/syntax/rez.syntax +80 -0
- data/code/syntax/ruby.syntax +1035 -0
- data/code/syntax/ruby_experimental.syntax +145 -0
- data/code/syntax/ruby_on_rails.syntax +88 -0
- data/code/syntax/s5.syntax +69 -0
- data/code/syntax/scheme.syntax +347 -0
- data/code/syntax/scilab.syntax +41 -0
- data/code/syntax/setext.syntax +147 -0
- data/code/syntax/shell-unix-generic.syntax +384 -0
- data/code/syntax/slate.syntax +149 -0
- data/code/syntax/sql.syntax +237 -0
- data/code/syntax/sql_rails.syntax +18 -0
- data/code/syntax/ssh-config.syntax +33 -0
- data/code/syntax/standard_ml.syntax +121 -0
- data/code/syntax/strings_file.syntax +39 -0
- data/code/syntax/subversion_commit_message.syntax +36 -0
- data/code/syntax/sweave.syntax +84 -0
- data/code/syntax/swig.syntax +57 -0
- data/code/syntax/tcl.syntax +152 -0
- data/code/syntax/template_toolkit.syntax +121 -0
- data/code/syntax/tex.syntax +86 -0
- data/code/syntax/tex_math.syntax +49 -0
- data/code/syntax/textile.syntax +215 -0
- data/code/syntax/tsv.syntax +50 -0
- data/code/syntax/twiki.syntax +241 -0
- data/code/syntax/txt2tags.syntax +79 -0
- data/code/syntax/vectorscript.syntax +57 -0
- data/code/syntax/xhtml_1.0.syntax +4027 -0
- data/code/syntax/xml.syntax +180 -0
- data/code/syntax/xml_strict.syntax +92 -0
- data/code/syntax/xsl.syntax +60 -0
- data/code/syntax/yaml.syntax +160 -0
- data/code/syntax/yui_javascript.syntax +176 -0
- data/lib/bayeux/bayeux.rb +727 -0
- data/lib/bayeux/html_gen.rb +506 -0
- data/lib/bayeux/latex_gen.rb +333 -0
- data/lib/bayeux/para_block.rb +201 -0
- data/lib/bayeux/text_gen.rb +307 -0
- data/lib/bayeux/tree_walker.rb +166 -0
- data/lib/filters/bayeux.rb +44 -0
- data/lib/filters/pandoc.rb +23 -0
- data/lib/filters/section_id.rb +105 -0
- data/lib/helpers/breadcrumbs.rb +64 -0
- data/lib/helpers/site_toc.rb +11 -0
- data/lib/lib/uv.rb +92 -0
- data/lib/lib/uv/render_processor.rb +146 -0
- data/lib/lib/uv/utility.rb +67 -0
- data/lib/refs/Doc_Blocks.rb +2 -0
- data/lib/refs/References.rb +104 -0
- metadata +415 -0
@@ -0,0 +1,506 @@
|
|
1
|
+
require 'tidy_ffi'
|
2
|
+
require 'uv'
|
3
|
+
|
4
|
+
require 'log4r'
|
5
|
+
include Log4r
|
6
|
+
|
7
|
+
class BayeuxHTMLGen
|
8
|
+
|
9
|
+
# Default Constructor
|
10
|
+
def initialize(syntax_tree)
|
11
|
+
@syntax_tree = syntax_tree
|
12
|
+
@html_string = String.new
|
13
|
+
end
|
14
|
+
|
15
|
+
# Return the AST as an HTML string (stored in @html_string)
|
16
|
+
def generate
|
17
|
+
|
18
|
+
# Set-up the logger
|
19
|
+
@html_gen_log = Logger.new('bayex_html_gen')
|
20
|
+
@html_gen_log.outputters = Outputter.stdout
|
21
|
+
|
22
|
+
# Create a walker for the trees in the forest
|
23
|
+
walker = TreeWalker.new
|
24
|
+
|
25
|
+
walker.on_before_down = self.method(:generate_node_start)
|
26
|
+
walker.on_after_up = self.method(:generate_node_end)
|
27
|
+
|
28
|
+
walker.on_no_siblings = self.method(:generate_full_node)
|
29
|
+
walker.on_no_children = self.method(:generate_full_node)
|
30
|
+
|
31
|
+
# Clear the internal HTML representation
|
32
|
+
@html_string.clear
|
33
|
+
|
34
|
+
# Walk the forest
|
35
|
+
@syntax_tree.block_forest.each{|tree|
|
36
|
+
walker.walk_tree(tree)
|
37
|
+
}
|
38
|
+
|
39
|
+
#@html_gen_log.debug {@syntax_tree.to_s}
|
40
|
+
#@html_gen_log.info {@html_string}
|
41
|
+
|
42
|
+
# Remove extra spaces between entities and tags
|
43
|
+
@html_string.gsub!(/;[\s]+</,';<')
|
44
|
+
|
45
|
+
# Return the generated string to the caller
|
46
|
+
tidy = TidyFFI::Tidy.new(@html_string)
|
47
|
+
|
48
|
+
tidy.options.fix_uri = 1
|
49
|
+
tidy.options.indent = 1
|
50
|
+
tidy.options.join_classes = 1
|
51
|
+
tidy.options.markup = 1
|
52
|
+
tidy.options.output_html = 1
|
53
|
+
tidy.options.punctuation_wrap = 1
|
54
|
+
tidy.options.show_body_only = 1
|
55
|
+
|
56
|
+
return tidy.clean
|
57
|
+
end
|
58
|
+
|
59
|
+
# Return the table of contents, extract from the AST
|
60
|
+
def doc_toc
|
61
|
+
|
62
|
+
# ToC to return to the caller
|
63
|
+
toc = String.new
|
64
|
+
|
65
|
+
# The current heading level
|
66
|
+
current_level = 0
|
67
|
+
|
68
|
+
# The last heading level
|
69
|
+
# Note: The very top level is provided
|
70
|
+
# by the enclosing template. Effectivly
|
71
|
+
# we are skipping the enclosures for the L1
|
72
|
+
# headers
|
73
|
+
last_level = 2
|
74
|
+
|
75
|
+
# Set containing valid header tags (ignore level 1 tags)
|
76
|
+
header_tags = Set.new [:h2, :h3, :h4, :h5, :h6]
|
77
|
+
|
78
|
+
# Walk the forest
|
79
|
+
@syntax_tree.block_forest.each{|tree|
|
80
|
+
|
81
|
+
# Ignore if not a header
|
82
|
+
if header_tags.include?(tree.content.type) then
|
83
|
+
|
84
|
+
# Set the current level based on the header
|
85
|
+
case tree.content.type
|
86
|
+
when :h1
|
87
|
+
current_level = 1
|
88
|
+
when :h2
|
89
|
+
current_level = 2
|
90
|
+
when :h3
|
91
|
+
current_level = 3
|
92
|
+
when :h4
|
93
|
+
current_level = 4
|
94
|
+
when :h5
|
95
|
+
current_level = 5
|
96
|
+
when :h6
|
97
|
+
current_level = 6
|
98
|
+
end
|
99
|
+
|
100
|
+
# Write out the toc
|
101
|
+
if current_level < last_level then
|
102
|
+
|
103
|
+
# Moving up: so close off the last level,
|
104
|
+
# create a new level, and record the current
|
105
|
+
# item
|
106
|
+
|
107
|
+
unless last_level == 0 then
|
108
|
+
toc << "</ul>"
|
109
|
+
end
|
110
|
+
|
111
|
+
toc << "#{indent(last_level)}<ul>\n"
|
112
|
+
toc << "#{indent(current_level)}<li><a href=\"##{header_id(tree.content.content)}\">#{tree.content.content}</a></li>\n"
|
113
|
+
|
114
|
+
elsif current_level > last_level then
|
115
|
+
|
116
|
+
# Moving down: so add a new list as a sub-list of
|
117
|
+
# the current list, and record the current item
|
118
|
+
|
119
|
+
toc << "#{indent(last_level)}<ul>\n"
|
120
|
+
toc << "#{indent(current_level)}<li><a href=\"##{header_id(tree.content.content)}\">#{tree.content.content}</a></li>\n"
|
121
|
+
|
122
|
+
else
|
123
|
+
# This header is at the same level, so just output the
|
124
|
+
# list item
|
125
|
+
toc << "#{indent(current_level)}<li><a href=\"##{header_id(tree.content.content)}\">#{tree.content.content}</a></li>\n"
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
# Record the current level
|
130
|
+
last_level = current_level
|
131
|
+
end
|
132
|
+
}
|
133
|
+
|
134
|
+
# Close off the lists
|
135
|
+
current_level.downto(3){|index|
|
136
|
+
toc << "#{indent(index)}</ul>\n"
|
137
|
+
}
|
138
|
+
|
139
|
+
return toc
|
140
|
+
end
|
141
|
+
|
142
|
+
###
|
143
|
+
### Walker Hooks. These are called by the tree walker on specific
|
144
|
+
### events
|
145
|
+
###
|
146
|
+
|
147
|
+
# Output the full contents of the node, properly bracketed as an
|
148
|
+
# HTML expression. This is only called if we have no sub-nodes to
|
149
|
+
# deal with
|
150
|
+
def generate_full_node(block)
|
151
|
+
|
152
|
+
# Check if we need to add a space
|
153
|
+
# Check if we need to add a space
|
154
|
+
if not block.content[0] =~ /\s|[:;.,?!]/
|
155
|
+
@html_string << " "
|
156
|
+
end
|
157
|
+
|
158
|
+
case block.type
|
159
|
+
|
160
|
+
# Headers
|
161
|
+
when :h1
|
162
|
+
@html_string << "<h1 id=\"#{header_id(block.content)}\">#{block.content}</h1>"
|
163
|
+
when :h2
|
164
|
+
@html_string << "<h2 id=\"#{header_id(block.content)}\">#{block.content}</h2>"
|
165
|
+
when :h3
|
166
|
+
@html_string << "<h3 id=\"#{header_id(block.content)}\">#{block.content}</h3>"
|
167
|
+
when :h4
|
168
|
+
@html_string << "<h4 id=\"#{header_id(block.content)}\">#{block.content}</h4>"
|
169
|
+
when :h5
|
170
|
+
@html_string << "<h5 id=\"#{header_id(block.content)}\">#{block.content}</h5>"
|
171
|
+
when :h5
|
172
|
+
@html_string << "<h6 id=\"#{header_id(block.content)}\">#{block.content}</h6>"
|
173
|
+
|
174
|
+
# Ordinary paragraphs
|
175
|
+
when :paragraph
|
176
|
+
@html_string << "<p>#{typeset(block.content)}</p>"
|
177
|
+
|
178
|
+
when :none
|
179
|
+
@html_string << "#{typeset(block.content)}"
|
180
|
+
|
181
|
+
# Special paragraphs
|
182
|
+
when :block_quote
|
183
|
+
@html_string << "<blockquote>#{typeset(block.content)}</blockquote>"
|
184
|
+
when :single_quote
|
185
|
+
@html_string << "‘ #{typeset(block.content)} ’"
|
186
|
+
when :double_quote
|
187
|
+
@html_string << "“ #{typeset(block.content)} ”"
|
188
|
+
|
189
|
+
when :note
|
190
|
+
@html_string << "<p class=\"note\"><span class=\"note_header\">Note:</span>#{typeset(block.content)}</span></p>"
|
191
|
+
|
192
|
+
when :command
|
193
|
+
@html_string << "<p class=\"command\">#{block.content}</span>"
|
194
|
+
|
195
|
+
when :code_language
|
196
|
+
@code_language = block.content
|
197
|
+
when :code_start_number
|
198
|
+
@code_start_number = block.content
|
199
|
+
|
200
|
+
when :file
|
201
|
+
@html_string << "<pre class=\"file\">#{block.content}</pre>"
|
202
|
+
when :output
|
203
|
+
@html_string << "<pre class=\"output\">#{block.content}</pre>"
|
204
|
+
|
205
|
+
# Special Characters
|
206
|
+
when :em_dash
|
207
|
+
@html_string << "—"
|
208
|
+
when :en_dash
|
209
|
+
@html_string << "–"
|
210
|
+
when :elipses
|
211
|
+
@html_string << " .  .  . "
|
212
|
+
when :elipses_stop
|
213
|
+
@html_string << " .  .  . ."
|
214
|
+
|
215
|
+
# Links
|
216
|
+
when :link_target
|
217
|
+
@link_target = block.content
|
218
|
+
when :link_text
|
219
|
+
@link_text = block.content
|
220
|
+
|
221
|
+
# Lists
|
222
|
+
when :item
|
223
|
+
@html_string << "<li>#{typeset(block.content)}</li>"
|
224
|
+
|
225
|
+
when :dl_header
|
226
|
+
@html_string << "<dt>#{block.content}</dt>"
|
227
|
+
when :dl_text
|
228
|
+
@html_string << "<dd>#{block.content}</dd>"
|
229
|
+
|
230
|
+
# Tags
|
231
|
+
when :ac
|
232
|
+
# Do we know anything about this acronymn?
|
233
|
+
if $reference.acronym_list.include?(block.content) then
|
234
|
+
|
235
|
+
# Assemble from the reference list
|
236
|
+
if $reference.acronym_list[block.content].include?('text_html') then
|
237
|
+
acronym = $reference.acronym_list[block.content]['text_html']
|
238
|
+
else
|
239
|
+
acronym = $reference.acronym_list[block.content]['text']
|
240
|
+
end
|
241
|
+
|
242
|
+
definition = $reference.acronym_list[block.content]['def']
|
243
|
+
|
244
|
+
@html_string << "<acronym title=\"#{definition}\">#{acronym}</acronym>"
|
245
|
+
else
|
246
|
+
# Do what we can
|
247
|
+
@html_string << "<acronym>#{block.content}</acronym>"
|
248
|
+
end
|
249
|
+
|
250
|
+
when :emph
|
251
|
+
@html_string << "<em>#{block.content}</em>"
|
252
|
+
|
253
|
+
when :tt
|
254
|
+
@html_string << "<tt>#{block.content}</tt>"
|
255
|
+
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
# Output only the start of a node
|
260
|
+
def generate_node_start(block)
|
261
|
+
|
262
|
+
# Check if we need to add a space
|
263
|
+
if not block.content[0] =~ /\s|[:;.,?!]/
|
264
|
+
@html_string << " "
|
265
|
+
end
|
266
|
+
|
267
|
+
case block.type
|
268
|
+
|
269
|
+
# Headers
|
270
|
+
when :h1
|
271
|
+
@html_string << "<h1 id=\"#{header_id(block.content)}\">"
|
272
|
+
when :h2
|
273
|
+
@html_string << "<h2 id=\"#{header_id(block.content)}\">"
|
274
|
+
when :h3
|
275
|
+
@html_string << "<h3 id=\"#{header_id(block.content)}\">"
|
276
|
+
when :h4
|
277
|
+
@html_string << "<h4 id=\"#{header_id(block.content)}\">"
|
278
|
+
when :h5
|
279
|
+
@html_string << "<h5 id=\"#{header_id(block.content)}\">"
|
280
|
+
when :h5
|
281
|
+
@html_string << "<h6 id=\"#{header_id(block.content)}\">"
|
282
|
+
|
283
|
+
# Ordinary paragraphs
|
284
|
+
when :paragraph
|
285
|
+
@html_string << "<p>#{typeset(block.content)}"
|
286
|
+
|
287
|
+
when :none
|
288
|
+
@html_string << "#{block.content}"
|
289
|
+
|
290
|
+
# Special paragraphs
|
291
|
+
when :block_quote
|
292
|
+
@html_string << "<blockquote>#{typeset(block.content)}"
|
293
|
+
when :single_quote
|
294
|
+
@html_string << "‘ #{typeset(block.content)}"
|
295
|
+
when :double_quote
|
296
|
+
@html_string << "“ #{typeset(block.content)}"
|
297
|
+
|
298
|
+
when :note
|
299
|
+
@html_string << "<p class=\"note\"><span class=\"note_header\">Note:</span>#{typeset(block.content)}"
|
300
|
+
|
301
|
+
when :command
|
302
|
+
@html_string << "<p class=\"command\">#{typeset(block.content)}"
|
303
|
+
|
304
|
+
when :code_language
|
305
|
+
@code_language = block.content
|
306
|
+
when :code_start_number
|
307
|
+
@code_start_number = block.content
|
308
|
+
|
309
|
+
# Special Characters
|
310
|
+
when :em_dash
|
311
|
+
@html_string << "—"
|
312
|
+
when :en_dash
|
313
|
+
@html_string << "–"
|
314
|
+
when :elipses
|
315
|
+
@html_string << " .  .  . "
|
316
|
+
when :elipses_stop
|
317
|
+
@html_string << " .  .  . ."
|
318
|
+
|
319
|
+
# Links
|
320
|
+
when :link_target
|
321
|
+
@link_target = block.content
|
322
|
+
when :link_text
|
323
|
+
@link_text = block.content
|
324
|
+
|
325
|
+
# Lists
|
326
|
+
when :ol
|
327
|
+
@html_string << "<ol>"
|
328
|
+
when :ul
|
329
|
+
@html_string << "<ul>"
|
330
|
+
when :item
|
331
|
+
@html_string << "<li>#{block.content}"
|
332
|
+
|
333
|
+
when :dl
|
334
|
+
@html_string << "<dl>"
|
335
|
+
when :dl_header
|
336
|
+
@html_string << "<dt>#{block.content}"
|
337
|
+
when :dl_text
|
338
|
+
@html_string << "<dd>#{block.content}"
|
339
|
+
|
340
|
+
# Tags
|
341
|
+
when :ac
|
342
|
+
# Do we know anything about this acronymn?
|
343
|
+
if $reference.acronym_list.include?(block.content) then
|
344
|
+
|
345
|
+
# Assemble from the reference list
|
346
|
+
if $reference.acronym_list[block.content].include?('text_html') then
|
347
|
+
acronym = $reference.acronym_list[block.content]['text_html']
|
348
|
+
else
|
349
|
+
acronym = $reference.acronym_list[block.content]['text']
|
350
|
+
end
|
351
|
+
|
352
|
+
definition = $reference.acronym_list[block.content]['def']
|
353
|
+
|
354
|
+
@html_string << "<acronym title=\"#{definition}\">#{acronym}"
|
355
|
+
else
|
356
|
+
# Do what we can
|
357
|
+
@html_string << "<acronym>#{block.content}"
|
358
|
+
end
|
359
|
+
|
360
|
+
when :emph
|
361
|
+
@html_string << "<em>#{block.content}"
|
362
|
+
|
363
|
+
when :tt
|
364
|
+
@html_string << "<tt>#{block.content}"
|
365
|
+
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
369
|
+
def generate_node_end(block)
|
370
|
+
|
371
|
+
case block.type
|
372
|
+
|
373
|
+
# Headers
|
374
|
+
when :h1
|
375
|
+
@html_string << "</h1>"
|
376
|
+
when :h2
|
377
|
+
@html_string << "</h2>"
|
378
|
+
when :h3
|
379
|
+
@html_string << "</h3>"
|
380
|
+
when :h4
|
381
|
+
@html_string << "</h4>"
|
382
|
+
when :h5
|
383
|
+
@html_string << "</h5>"
|
384
|
+
when :h6
|
385
|
+
@html_string << "</h6>"
|
386
|
+
|
387
|
+
# Ordinary paragraphs
|
388
|
+
when :paragraph
|
389
|
+
@html_string << "</p>"
|
390
|
+
|
391
|
+
# Special paragraphs
|
392
|
+
when :block_quote
|
393
|
+
@html_string << "</blockquote>"
|
394
|
+
when :single_quote
|
395
|
+
@html_string << " ’"
|
396
|
+
when :double_quote
|
397
|
+
@html_string << " ”"
|
398
|
+
|
399
|
+
when :note, :command
|
400
|
+
@html_string << "</p>"
|
401
|
+
|
402
|
+
when :code
|
403
|
+
# Assemble the code block from the sub-tree nodes
|
404
|
+
begin
|
405
|
+
pretty_code = Uv.parse(block.content, "xhtml", @code_language, @code_start_number.to_i, "dawn")
|
406
|
+
@html_string << pretty_code
|
407
|
+
rescue
|
408
|
+
pretty_code = Uv.parse(block.content, "xhtml", "plain_text", @code_start_number.to_i, "dawn")
|
409
|
+
@html_string << pretty_code
|
410
|
+
end
|
411
|
+
|
412
|
+
# Special Characters
|
413
|
+
when :em_dash
|
414
|
+
@html_string << "—"
|
415
|
+
when :en_dash
|
416
|
+
@html_string << "–"
|
417
|
+
when :elipses
|
418
|
+
@html_string << " .  .  . "
|
419
|
+
when :elipses_stop
|
420
|
+
@html_string << " .  .  . ."
|
421
|
+
|
422
|
+
# Links
|
423
|
+
when :link
|
424
|
+
# Assemble the link from the sub-tree nodes
|
425
|
+
@html_string << "<a href=\"#{@link_target}\">#{@link_text}</a>"
|
426
|
+
when :link_target
|
427
|
+
@link_target = block.content
|
428
|
+
when :link_text
|
429
|
+
@link_text = block.content
|
430
|
+
|
431
|
+
# Lists
|
432
|
+
when :ol
|
433
|
+
@html_string << "</ol>"
|
434
|
+
when :ul
|
435
|
+
@html_string << "</ul>"
|
436
|
+
when :item
|
437
|
+
@html_string << "</li>"
|
438
|
+
|
439
|
+
when :dl
|
440
|
+
@html_string << "</dl>"
|
441
|
+
when :dl_header
|
442
|
+
@html_string << "</dt>"
|
443
|
+
when :dl_text
|
444
|
+
@html_string << "</dd>"
|
445
|
+
|
446
|
+
# Tags
|
447
|
+
when :ac
|
448
|
+
@html_string << "</acronym>"
|
449
|
+
|
450
|
+
when :emph
|
451
|
+
@html_string << "</em>"
|
452
|
+
|
453
|
+
when :tt
|
454
|
+
@html_string << "</tt>"
|
455
|
+
end
|
456
|
+
end
|
457
|
+
|
458
|
+
###
|
459
|
+
### Helper functions
|
460
|
+
###
|
461
|
+
|
462
|
+
# Return the header id, given a string of text
|
463
|
+
def self.header_id(header_text)
|
464
|
+
return header_text.gsub(" ", "_").downcase
|
465
|
+
end
|
466
|
+
|
467
|
+
# Fix Typography, according to HTML standards
|
468
|
+
def typeset(string)
|
469
|
+
return_str = string
|
470
|
+
|
471
|
+
return_str.gsub!(';',' :')
|
472
|
+
return_str.gsub!(':',' :')
|
473
|
+
|
474
|
+
return_str.gsub!("'", "’")
|
475
|
+
|
476
|
+
return_str.gsub!('.',' . ')
|
477
|
+
return_str.gsub!('?',' ? ')
|
478
|
+
return_str.gsub!('!',' ! ')
|
479
|
+
|
480
|
+
return_str.gsub!('e . g . ','e.g. ')
|
481
|
+
return_str.gsub!('i . e . ','i.e. ')
|
482
|
+
|
483
|
+
return return_str
|
484
|
+
end
|
485
|
+
|
486
|
+
# Return the correct indent for the given level
|
487
|
+
def indent(level)
|
488
|
+
case level
|
489
|
+
when 1
|
490
|
+
return ""
|
491
|
+
when 2
|
492
|
+
return " "
|
493
|
+
when 3
|
494
|
+
return " "
|
495
|
+
when 4
|
496
|
+
return " "
|
497
|
+
when 5
|
498
|
+
return " "
|
499
|
+
when 6
|
500
|
+
return " "
|
501
|
+
else
|
502
|
+
return ""
|
503
|
+
end
|
504
|
+
end
|
505
|
+
|
506
|
+
end
|