hemingway 0.0.0 → 0.0.2
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.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +297 -0
- data/Rakefile +1 -0
- data/hemingway.gemspec +23 -0
- data/lib/hemingway/block/block.rb +378 -0
- data/lib/hemingway/block/block.treetop +36 -0
- data/lib/hemingway/block/block_nodes.rb +9 -0
- data/lib/hemingway/block/list/list.rb +412 -0
- data/lib/hemingway/block/list/list.treetop +51 -0
- data/lib/hemingway/block/list/list_nodes.rb +39 -0
- data/lib/hemingway/block/quote/quote.rb +192 -0
- data/lib/hemingway/block/quote/quote.treetop +27 -0
- data/lib/hemingway/block/quote/quote_nodes.rb +25 -0
- data/lib/hemingway/block/verbatim/verbatim.rb +159 -0
- data/lib/hemingway/block/verbatim/verbatim.treetop +21 -0
- data/lib/hemingway/block/verbatim/verbatim_nodes.rb +9 -0
- data/lib/hemingway/build.rb +65 -0
- data/lib/hemingway/footnote/footnote.rb +83 -0
- data/lib/hemingway/footnote/footnote.treetop +11 -0
- data/lib/hemingway/footnote/footnote_nodes.rb +21 -0
- data/lib/hemingway/latex.rb +409 -0
- data/lib/hemingway/latex.treetop +81 -0
- data/lib/hemingway/latex_nodes.rb +45 -0
- data/lib/hemingway/math/math.rb +135 -0
- data/lib/hemingway/math/math.treetop +29 -0
- data/lib/hemingway/math/math_nodes.rb +7 -0
- data/lib/hemingway/special/special.rb +164 -0
- data/lib/hemingway/special/special.treetop +17 -0
- data/lib/hemingway/special/special_nodes.rb +7 -0
- data/lib/hemingway/symbol/symbol.rb +460 -0
- data/lib/hemingway/symbol/symbol.treetop +47 -0
- data/lib/hemingway/symbol/symbol_nodes.rb +7 -0
- data/lib/hemingway/tag/tag.rb +538 -0
- data/lib/hemingway/tag/tag.treetop +63 -0
- data/lib/hemingway/tag/tag_nodes.rb +49 -0
- data/lib/hemingway/text/text.rb +121 -0
- data/lib/hemingway/text/text.treetop +35 -0
- data/lib/hemingway/text/text_nodes.rb +7 -0
- data/lib/hemingway/version.rb +3 -0
- data/lib/hemingway.rb +7 -0
- data/script/build +22 -0
- data/script/test +2 -0
- data/spec/build_spec.rb +65 -0
- data/spec/nodes/block/list_spec.rb +91 -0
- data/spec/nodes/block/quote_spec.rb +31 -0
- data/spec/nodes/block/verbatim_spec.rb +27 -0
- data/spec/nodes/block_spec.rb +21 -0
- data/spec/nodes/footnote_spec.rb +42 -0
- data/spec/nodes/math_spec.rb +31 -0
- data/spec/nodes/special_spec.rb +27 -0
- data/spec/nodes/tag_spec.rb +98 -0
- data/spec/parser_spec.rb +48 -0
- data/spec/spec_helper.rb +5 -0
- metadata +110 -18
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bf15765814157f6a98fa3980ffe6e0c8d8c43861
|
4
|
+
data.tar.gz: 88cf015095d95839cbd00b93bf1891124f97b06c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2aab3777d099f030d8685f2f0e74080e71891ad9fb8d25a964a0f9f5e4b9135f4edf25f471386d44c335f5781a171cf0c7c4a27eab819b8ecc42502470d0da25
|
7
|
+
data.tar.gz: c201f4340c352d73cea3fdf80b076e13a705801d18806cd628aba1e9eb39a00417e92004b0b628948dcd6aeac275ee63f43dc857fc3a1af16c417fd365d1d437
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 William Myers
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,297 @@
|
|
1
|
+
# Hemingway [](https://travis-ci.org/griffinmyers/hemingway)
|
2
|
+
|
3
|
+
Hemingway can translate a very rigid subset of LaTeX commands into HTML markup that can then be styled at the user's whim.
|
4
|
+
|
5
|
+
The parser was created using Treetop, so it might be useful to consult the [Treetop Documentation](http://treetop.rubyforge.org/syntactic_recognition.html) to learn more about the inner workings.
|
6
|
+
|
7
|
+
Throughout you'll notice this character: `\\`. This is the string represntation of the `\` character.
|
8
|
+
|
9
|
+
So if your latex is coming from a file you would just write `\emph{wookies}`, and if it were programatically coming from a string
|
10
|
+
you would write `\\emph{wookies}`
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'hemingway'
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install hemingway
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
First, instantiate the parser.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
parser = Hemingway::Parser.new
|
34
|
+
```
|
35
|
+
|
36
|
+
Next, chuck some Latex markup into it.
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
result = parser.parse("do, or do not, there is no \\emph{try}")
|
40
|
+
```
|
41
|
+
|
42
|
+
Finally, convert the result to html markup.
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
markup = result.html
|
46
|
+
```
|
47
|
+
|
48
|
+
If something goes really wrong, the parse method will return `nil`. If that's the case, you can say something like
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
parser.failure_reason
|
52
|
+
```
|
53
|
+
|
54
|
+
to figure out what happened. `Hemingway::Parser` is a delegator for a Treetop parser, so check out the [Treetop Documentation](http://treetop.rubyforge.org/syntactic_recognition.html) to see what other useful methods you can use in case of something going wrong.
|
55
|
+
|
56
|
+
## Supported Syntax
|
57
|
+
Here is a breakdown of supported latex and its markup equivalent.
|
58
|
+
In most examples, I only show the interesting bits of conversion. Note that at the
|
59
|
+
top level, everything is wrapped in
|
60
|
+
|
61
|
+
```html
|
62
|
+
<div class='entry'></div>
|
63
|
+
```
|
64
|
+
|
65
|
+
but I'm omitting that detail from the examples for brevity. Throughout this,
|
66
|
+
the `:` operator simply says the LHS maps to the RHS.
|
67
|
+
|
68
|
+
###### Newlines
|
69
|
+
|
70
|
+
Delimits paragraphs
|
71
|
+
|
72
|
+
```html
|
73
|
+
wookie\n\nbreakfast : <p>wookie></p><p>breakfast</p>
|
74
|
+
```
|
75
|
+
|
76
|
+
###### Tags
|
77
|
+
|
78
|
+
Adds inline styling
|
79
|
+
|
80
|
+
```html
|
81
|
+
That’s no moon, \\emph{it’s a space station.} : That’s no moon, <em>it’s a space station.</em>
|
82
|
+
|
83
|
+
\\textbf{The Force} : <strong>The Force</strong>
|
84
|
+
|
85
|
+
\\texttt{R2-D2} : <code>R2-D2</code>
|
86
|
+
|
87
|
+
\\textsc{Death Star} : <span class='textsc'>Death Star</span>
|
88
|
+
```
|
89
|
+
|
90
|
+
Or some vertical padding
|
91
|
+
|
92
|
+
```html
|
93
|
+
\\vspace{5mm} : <div class='vspace5'></div>
|
94
|
+
```
|
95
|
+
|
96
|
+
###### Maths
|
97
|
+
|
98
|
+
Adds math symbols
|
99
|
+
|
100
|
+
```html
|
101
|
+
$\\Gamma$" : Γ
|
102
|
+
$\\Delta$" : Δ
|
103
|
+
$\\Theta$" : Θ
|
104
|
+
$\\Lambda$" : Λ
|
105
|
+
$\\Xi$" : Ξ
|
106
|
+
$\\Pi$" : Π
|
107
|
+
$\\Sigma$" : Σ
|
108
|
+
$\\Upsilon$" : Υ
|
109
|
+
$\\Phi$" : Φ
|
110
|
+
$\\Psi$" : Ψ
|
111
|
+
$\\Omega$" : Ω
|
112
|
+
$\\alpha$" : α
|
113
|
+
$\\beta$" : β
|
114
|
+
$\\gamma$" : γ
|
115
|
+
$\\delta$" : δ
|
116
|
+
$\\epsilon$" : ε
|
117
|
+
$\\zeta$" : ζ
|
118
|
+
$\\eta$" : η
|
119
|
+
$\\theta$" : θ
|
120
|
+
$\\iota$" : ι
|
121
|
+
$\\kappa$" : κ
|
122
|
+
$\\lambda$" : λ
|
123
|
+
$\\mu$" : μ
|
124
|
+
$\\nu$" : ν
|
125
|
+
$\\xi$" : ξ
|
126
|
+
$\\pi$" : π
|
127
|
+
$\\rho$" : ρ
|
128
|
+
$\\varsigma$" : ς
|
129
|
+
$\\sigma$" : σ
|
130
|
+
$\\tau$" : τ
|
131
|
+
$\\upsilon$" : υ
|
132
|
+
$\\phi$" : φ
|
133
|
+
$\\chi$" : χ
|
134
|
+
$\\psi$" : ψ
|
135
|
+
$\\omega$" : ω
|
136
|
+
```
|
137
|
+
|
138
|
+
|
139
|
+
###### Special Characters
|
140
|
+
|
141
|
+
```html
|
142
|
+
\\# : #
|
143
|
+
\\$ : $
|
144
|
+
\\% : %
|
145
|
+
\\& : &
|
146
|
+
\\_ : _
|
147
|
+
\\{ : {
|
148
|
+
\\} : }
|
149
|
+
```
|
150
|
+
|
151
|
+
###### Blocks
|
152
|
+
|
153
|
+
You can make lists with `itemize`, `description`, or `enumerate`.
|
154
|
+
|
155
|
+
```html
|
156
|
+
\\begin{itemize}\\item Wookie \\item Jedi \\end{itemize} : <ul><li>Wookie </li><li>Jedi </li></ul>
|
157
|
+
|
158
|
+
\\begin{enumerate} \\item Frodo \\item Sam \\end{enumerate} : <ol><li>Frodo </li><li>Sam </li></ol>
|
159
|
+
|
160
|
+
\\begin{description} \\item Ginger-Nut \\item Turkey \\end{description} : <dl><dd>Ginger-Nut </dd><dd>Turkey </dd></dl>
|
161
|
+
```
|
162
|
+
|
163
|
+
Add labels to a list with `\item[label]`:
|
164
|
+
|
165
|
+
```html
|
166
|
+
\\begin{itemize}\\item[bros] before hoes \\item \\n [chicks] before dicks \\end{itemize} : <ul><li><span class='list-label'>bros</span> before hoes </li><li><span class='list-label'>chicks</span> before dicks </li></ul>
|
167
|
+
|
168
|
+
\\begin{description} \\item [Frodo] Intrepid Adventurer \\item [Sam] Faithful Companion \\end{description} : <dl><dd><dt>Frodo</dt> Intrepid Adventurer </dd><dd><dt>Sam</dt> Faithful Companion </dd></dl>
|
169
|
+
```
|
170
|
+
|
171
|
+
Go ahead, nest lists in all sorts of interesting ways. No reason you couldn't chuck some empahsized text in a label either.
|
172
|
+
|
173
|
+
Enter in preformatted text:
|
174
|
+
|
175
|
+
```html
|
176
|
+
\\begin{verbatim} don't we \n \n all wish \n \n for a little sleep? \\end{verbatim}") : <pre>don't we \n \n all wish \n \n for a little sleep? </pre>
|
177
|
+
```
|
178
|
+
|
179
|
+
###### Footnotes
|
180
|
+
|
181
|
+
Putting in a bunch of footnotes inline with your content is an awesome idea. All footnotes within an entry
|
182
|
+
will be yanked out, linked with an anchor tag, and placed after all paragraphs in the entry. Naturally
|
183
|
+
you can put just about whatever you want in a footnote (save another footnote).
|
184
|
+
|
185
|
+
I might have made a bad assumption here and used the `<sup>` tag for the footnote number because it assumes formatting, something I've been trying to avoid. If you'd like that assumption removed, you're just a pull request away.
|
186
|
+
|
187
|
+
For example this latex markup:
|
188
|
+
|
189
|
+
> So we met up with Han and saw his ship, The Millennium Falcon\\footnote{a total piece of junk}. I had no idea how that thing was supposed to get us to Alderaan\\footnote{location of the \\emph{hidden rebel base}}.
|
190
|
+
|
191
|
+
> On board we found homely accommodations including a Dejarik\\footnote{much like chess} set that I indulged in with Chewbacca\\footnote{Han's carpety first mate}.
|
192
|
+
|
193
|
+
Renders to this html:
|
194
|
+
|
195
|
+
```html
|
196
|
+
<div class='entry'>
|
197
|
+
<p>
|
198
|
+
So we met up with Han and saw his ship, The Millenium Falcon<a href='#footnote1'><span class='inline-footnote-number'><sup>1</sup></span></a>. I had no idea how that thing was supposed to get us to Alderaan<a href='#footnote2'><span class='inline-footnote-number'><sup>2</sup></span></a>.
|
199
|
+
</p>
|
200
|
+
<p>
|
201
|
+
On board we found homely accommodations including a Dejarik<a href='#footnote3'><span class='inline-footnote-number'><sup>3</sup></span></a> set that I indulged in with Chewbacca<a href='#footnote4'><span class='inline-footnote-number'><sup>4</sup></span></a>.
|
202
|
+
</p>
|
203
|
+
|
204
|
+
<div id='footnote1' class='footnote'>
|
205
|
+
<span class='footnote-number'><sup>1</sup></span>a total piece of junk
|
206
|
+
</div>
|
207
|
+
|
208
|
+
<div id='footnote2' class='footnote'>
|
209
|
+
<span class='footnote-number'><sup>2</sup></span>location of the <em>hidden rebel base</em>
|
210
|
+
</div>
|
211
|
+
|
212
|
+
<div id='footnote3' class='footnote'>
|
213
|
+
<span class='footnote-number'><sup>3</sup></span>much like chess
|
214
|
+
</div>
|
215
|
+
|
216
|
+
<div id='footnote4' class='footnote'>
|
217
|
+
<span class='footnote-number'><sup>4</sup></span>Han's carpety first mate
|
218
|
+
</div>
|
219
|
+
|
220
|
+
</div>
|
221
|
+
```
|
222
|
+
|
223
|
+
And looks like this:
|
224
|
+
|
225
|
+
<div class='entry'>
|
226
|
+
<p>
|
227
|
+
So we met up with Han and saw his ship, The Millennium Falcon<a href='#footnote1'><span class='inline-footnote-number'><sup>1</sup></span></a>. I had no idea how that thing was supposed to get us to Alderaan<a href='#footnote2'><span class='inline-footnote-number'><sup>2</sup></span></a>.
|
228
|
+
</p>
|
229
|
+
<p>
|
230
|
+
On board we found homely accommodations including a Dejarik<a href='#footnote3'><span class='inline-footnote-number'><sup>3</sup></span></a> set that I indulged in with Chewbacca<a href='#footnote4'><span class='inline-footnote-number'><sup>4</sup></span></a>.
|
231
|
+
</p>
|
232
|
+
|
233
|
+
<div id='footnote1' class='footnote'>
|
234
|
+
<span class='footnote-number'><sup>1</sup></span>a total piece of junk
|
235
|
+
</div>
|
236
|
+
|
237
|
+
<div id='footnote2' class='footnote'>
|
238
|
+
<span class='footnote-number'><sup>2</sup></span>location of the <em>hidden rebel base</em>
|
239
|
+
</div>
|
240
|
+
|
241
|
+
<div id='footnote3' class='footnote'>
|
242
|
+
<span class='footnote-number'><sup>3</sup></span>much like chess
|
243
|
+
</div>
|
244
|
+
|
245
|
+
<div id='footnote4' class='footnote'>
|
246
|
+
<span class='footnote-number'><sup>4</sup></span>Han's carpety first mate
|
247
|
+
</div>
|
248
|
+
|
249
|
+
</div>
|
250
|
+
|
251
|
+
###### Block Quotes
|
252
|
+
|
253
|
+
Pretty standard. You can put anything in there except a footnote. That seemed
|
254
|
+
excessive.
|
255
|
+
|
256
|
+
```html
|
257
|
+
\\begin{quote}
|
258
|
+
Have you guys ever heard the song \\emph{Blow} by \\emph{MILF}?
|
259
|
+
\\end{quote}
|
260
|
+
```
|
261
|
+
|
262
|
+
maps to
|
263
|
+
|
264
|
+
```html
|
265
|
+
<blockquote>
|
266
|
+
<p>
|
267
|
+
Have you guys ever heard the song <em>Blow</em> by <em>MILF</em>?
|
268
|
+
</p>
|
269
|
+
</blockquote>
|
270
|
+
```
|
271
|
+
|
272
|
+
###### Inline Right Justification
|
273
|
+
|
274
|
+
```html
|
275
|
+
The love, \\hfill Will
|
276
|
+
```
|
277
|
+
|
278
|
+
maps to
|
279
|
+
|
280
|
+
```html
|
281
|
+
The love, <span class="pull-right">Will</span>
|
282
|
+
```
|
283
|
+
|
284
|
+
###### Horizontal Rules
|
285
|
+
|
286
|
+
```html
|
287
|
+
\\neatline : <hr class='neatline'>
|
288
|
+
```
|
289
|
+
|
290
|
+
## Contributing
|
291
|
+
|
292
|
+
1. Fork it
|
293
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
294
|
+
3. Write and run tests (`script/test`)
|
295
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
296
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
297
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/hemingway.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'hemingway/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "hemingway"
|
8
|
+
gem.version = Hemingway::VERSION
|
9
|
+
gem.authors = ["William Myers"]
|
10
|
+
gem.email = ["griffin.myers@gmail.com"]
|
11
|
+
gem.description = %q{A LaTeX to HTML parser.}
|
12
|
+
gem.summary = %q{Hemingway is a LaTeX to HTML parser.}
|
13
|
+
gem.homepage = "https://rubygems.org/gems/hemingway"
|
14
|
+
gem.licenses = "MIT"
|
15
|
+
|
16
|
+
gem.add_development_dependency "rspec"
|
17
|
+
gem.add_runtime_dependency "treetop"
|
18
|
+
|
19
|
+
gem.files = `git ls-files`.split($/)
|
20
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
21
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
22
|
+
gem.require_paths = ["lib"]
|
23
|
+
end
|