BBRedCloth 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. data/BBRedCloth.gemspec +36 -0
  2. data/CHANGELOG +123 -0
  3. data/COPYING +18 -0
  4. data/Manifest +45 -0
  5. data/README.textile +149 -0
  6. data/Rakefile +247 -0
  7. data/bin/bbredcloth +34 -0
  8. data/ext/mingw-rbconfig.rb +176 -0
  9. data/ext/redcloth_scan/extconf.rb +9 -0
  10. data/ext/redcloth_scan/redcloth.h +196 -0
  11. data/ext/redcloth_scan/redcloth_attributes.c +655 -0
  12. data/ext/redcloth_scan/redcloth_bbcode.c +2457 -0
  13. data/ext/redcloth_scan/redcloth_bbcode_inline.c +1890 -0
  14. data/ext/redcloth_scan/redcloth_inline.c +12387 -0
  15. data/ext/redcloth_scan/redcloth_scan.c +10848 -0
  16. data/extras/ragel_profiler.rb +73 -0
  17. data/lib/case_sensitive_require/RedCloth.rb +6 -0
  18. data/lib/redcloth/erb_extension.rb +27 -0
  19. data/lib/redcloth/formatters/base.rb +57 -0
  20. data/lib/redcloth/formatters/html.rb +487 -0
  21. data/lib/redcloth/formatters/latex.rb +249 -0
  22. data/lib/redcloth/formatters/latex_entities.yml +2414 -0
  23. data/lib/redcloth/textile_doc.rb +196 -0
  24. data/lib/redcloth/version.rb +28 -0
  25. data/lib/redcloth.rb +37 -0
  26. data/setup.rb +1585 -0
  27. data/test/basic.yml +933 -0
  28. data/test/code.yml +229 -0
  29. data/test/definitions.yml +82 -0
  30. data/test/extra_whitespace.yml +64 -0
  31. data/test/filter_html.yml +177 -0
  32. data/test/filter_pba.yml +20 -0
  33. data/test/helper.rb +109 -0
  34. data/test/html.yml +313 -0
  35. data/test/images.yml +254 -0
  36. data/test/instiki.yml +38 -0
  37. data/test/links.yml +275 -0
  38. data/test/lists.yml +283 -0
  39. data/test/poignant.yml +89 -0
  40. data/test/sanitize_html.yml +42 -0
  41. data/test/table.yml +267 -0
  42. data/test/test_custom_tags.rb +46 -0
  43. data/test/test_erb.rb +13 -0
  44. data/test/test_extensions.rb +31 -0
  45. data/test/test_formatters.rb +24 -0
  46. data/test/test_parser.rb +73 -0
  47. data/test/test_restrictions.rb +61 -0
  48. data/test/textism.yml +484 -0
  49. data/test/threshold.yml +772 -0
  50. data/test/validate_fixtures.rb +74 -0
  51. metadata +139 -0
@@ -0,0 +1,249 @@
1
+ require 'yaml'
2
+
3
+ module RedCloth::Formatters::LATEX
4
+ include RedCloth::Formatters::Base
5
+
6
+ ENTITIES = YAML::load(File.read(File.dirname(__FILE__)+'/latex_entities.yml'))
7
+
8
+ module Settings
9
+ # Maps CSS style names to latex formatting options
10
+ def latex_image_styles
11
+ @latex_image_class_styles ||= {}
12
+ end
13
+ end
14
+
15
+ RedCloth::TextileDoc.send(:include, Settings)
16
+
17
+ def escape(text)
18
+ latex_esc(text)
19
+ end
20
+
21
+ def escape_pre(text)
22
+ text
23
+ end
24
+
25
+ # headers
26
+ { :h1 => 'section*',
27
+ :h2 => 'subsection*',
28
+ :h3 => 'subsubsection*',
29
+ :h4 => 'textbf',
30
+ :h5 => 'textbf',
31
+ :h6 => 'textbf',
32
+ }.each do |m,tag|
33
+ define_method(m) do |opts|
34
+ "\\#{tag}{#{opts[:text]}}\n\n"
35
+ end
36
+ end
37
+
38
+ # commands
39
+ { :strong => 'textbf',
40
+ :em => 'emph',
41
+ :i => 'emph',
42
+ :b => 'textbf',
43
+ :ins => 'underline',
44
+ :del => 'sout',
45
+ :acronym => 'MakeUppercase',
46
+ :caps => 'MakeUppercase',
47
+ }.each do |m,tag|
48
+ define_method(m) do |opts|
49
+ "\\#{tag}{#{opts[:text]}}"
50
+ end
51
+ end
52
+
53
+ { :sup => '\ensuremath{^\textrm{#1}}',
54
+ :sub => '\ensuremath{_\textrm{#1}}',
55
+ }.each do |m, expr|
56
+ define_method(m) do |opts|
57
+ expr.sub('#1', opts[:text])
58
+ end
59
+ end
60
+
61
+ # environments
62
+ { :pre => 'verbatim',
63
+ :code => 'verbatim',
64
+ :cite => 'quote',
65
+ }.each do |m, env|
66
+ define_method(m) do |opts|
67
+ begin_chunk(env) + opts[:text] + end_chunk(env)
68
+ end
69
+ end
70
+
71
+ # ignore (or find a good solution later)
72
+ [ :span,
73
+ :div,
74
+ ].each do |m|
75
+ define_method(m) do |opts|
76
+ opts[:text].to_s
77
+ end
78
+ end
79
+
80
+ { :ol => 'enumerate',
81
+ :ul => 'itemize',
82
+ }.each do |m, env|
83
+ define_method("#{m}_open") do |opts|
84
+ opts[:block] = true
85
+ "\\begin{#{env}}\n"
86
+ end
87
+ define_method("#{m}_close") do |opts|
88
+ "#{li_close}\\end{#{env}}\n\n"
89
+ end
90
+ end
91
+
92
+ def li_open(opts)
93
+ "#{li_close unless opts.delete(:first)}\t\\item #{opts[:text]}"
94
+ end
95
+
96
+ def li_close(opts=nil)
97
+ "\n"
98
+ end
99
+
100
+ def p(opts)
101
+ opts[:text] + "\n\n"
102
+ end
103
+
104
+ def td(opts)
105
+ "\t\t\t#{opts[:text]} &\n"
106
+ end
107
+
108
+ def tr_open(opts)
109
+ "\t\t"
110
+ end
111
+
112
+ def tr_close(opts)
113
+ "\t\t\\\\\n"
114
+ end
115
+
116
+ # FIXME: we need to know the column count before opening tabular context.
117
+ def table_open(opts)
118
+ "\\begin{align*}\n"
119
+ end
120
+
121
+ def table_close(opts)
122
+ "\t\\end{align*}\n"
123
+ end
124
+
125
+ def bc_open(opts)
126
+ opts[:block] = true
127
+ begin_chunk("verbatim") + "\n"
128
+ end
129
+
130
+ def bc_close(opts)
131
+ end_chunk("verbatim") + "\n"
132
+ end
133
+
134
+ def bq_open(opts)
135
+ opts[:block] = true
136
+ "\\begin{quotation}\n"
137
+ end
138
+
139
+ def bq_close(opts)
140
+ "\\end{quotation}\n\n"
141
+ end
142
+
143
+ def link(opts)
144
+ "\\href{#{opts[:href]}}{#{opts[:name]}}"
145
+ end
146
+
147
+ # FIXME: use includegraphics with security verification
148
+ #
149
+ # Remember to use '\RequirePackage{graphicx}' in your LaTeX header
150
+ #
151
+ # FIXME: Look at dealing with width / height gracefully as this should be
152
+ # specified in a unit like cm rather than px.
153
+ def image(opts)
154
+ # Don't know how to use remote links, plus can we trust them?
155
+ return "" if opts[:src] =~ /^\w+\:\/\//
156
+ # Resolve CSS styles if any have been set
157
+ styling = opts[:class].to_s.split(/\s+/).collect { |style| latex_image_styles[style] }.compact.join ','
158
+ # Build latex code
159
+ [ "\\begin{figure}[htp]",
160
+ " \\includegraphics[#{styling}]{#{opts[:src]}}",
161
+ (" \\caption{#{escape opts[:title]}}" if opts[:title]),
162
+ (" \\label{#{escape opts[:alt]}}" if opts[:alt]),
163
+ "\\end{figure}",
164
+ ].compact.join "\n"
165
+ end
166
+
167
+ def footno(opts)
168
+ # TODO: insert a placeholder until we know the footnote content.
169
+ # For this to work, we need some kind of post-processing...
170
+ "\\footnotemark[#{opts[:text]}]"
171
+ end
172
+
173
+ def fn(opts)
174
+ "\\footnotetext[#{opts[:id]}]{#{opts[:text]}}"
175
+ end
176
+
177
+ def snip(opts)
178
+ "\\begin{verbatim}#{opts[:text]}\\end{verbatim}"
179
+ end
180
+
181
+ def quote1(opts)
182
+ "`#{opts[:text]}'"
183
+ end
184
+
185
+ def quote2(opts)
186
+ "``#{opts[:text]}\""
187
+ end
188
+
189
+ def ellipsis(opts)
190
+ "#{opts[:text]}\\ldots{}"
191
+ end
192
+
193
+ def emdash(opts)
194
+ "---"
195
+ end
196
+
197
+ def endash(opts)
198
+ "--"
199
+ end
200
+
201
+ def arrow(opts)
202
+ "\\rightarrow{}"
203
+ end
204
+
205
+ def trademark(opts)
206
+ "\\texttrademark{}"
207
+ end
208
+
209
+ def registered(opts)
210
+ "\\textregistered{}"
211
+ end
212
+
213
+ def copyright(opts)
214
+ "\\copyright{}"
215
+ end
216
+
217
+ # TODO: what do we do with (unknown) unicode entities ?
218
+ #
219
+ def entity(opts)
220
+ text = opts[:text][0..0] == '#' ? opts[:text][1..-1] : opts[:text]
221
+ ENTITIES[text]
222
+ end
223
+
224
+ def dim(opts)
225
+ space = opts[:space] ? " " : ''
226
+ "#{opts[:text]}#{space}\\texttimes{}#{space}"
227
+ end
228
+
229
+ private
230
+
231
+ # Use this for block level commands that use \begin
232
+ def begin_chunk(type)
233
+ chunk_counter[type] += 1
234
+ return "\\begin{#{type}}" if 1 == chunk_counter[type]
235
+ ''
236
+ end
237
+
238
+ # Use this for block level commands that use \end
239
+ def end_chunk(type)
240
+ chunk_counter[type] -= 1
241
+ raise RuntimeError, "Bad latex #{type} nesting detected" if chunk_counter[type] < 0 # This should never need to happen
242
+ return "\\end{#{type}}" if 0 == chunk_counter[type]
243
+ ''
244
+ end
245
+
246
+ def chunk_counter
247
+ @chunk_counter ||= Hash.new 0
248
+ end
249
+ end