hemingway 0.0.0 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.travis.yml +4 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +297 -0
  7. data/Rakefile +1 -0
  8. data/hemingway.gemspec +23 -0
  9. data/lib/hemingway/block/block.rb +378 -0
  10. data/lib/hemingway/block/block.treetop +36 -0
  11. data/lib/hemingway/block/block_nodes.rb +9 -0
  12. data/lib/hemingway/block/list/list.rb +412 -0
  13. data/lib/hemingway/block/list/list.treetop +51 -0
  14. data/lib/hemingway/block/list/list_nodes.rb +39 -0
  15. data/lib/hemingway/block/quote/quote.rb +192 -0
  16. data/lib/hemingway/block/quote/quote.treetop +27 -0
  17. data/lib/hemingway/block/quote/quote_nodes.rb +25 -0
  18. data/lib/hemingway/block/verbatim/verbatim.rb +159 -0
  19. data/lib/hemingway/block/verbatim/verbatim.treetop +21 -0
  20. data/lib/hemingway/block/verbatim/verbatim_nodes.rb +9 -0
  21. data/lib/hemingway/build.rb +65 -0
  22. data/lib/hemingway/footnote/footnote.rb +83 -0
  23. data/lib/hemingway/footnote/footnote.treetop +11 -0
  24. data/lib/hemingway/footnote/footnote_nodes.rb +21 -0
  25. data/lib/hemingway/latex.rb +409 -0
  26. data/lib/hemingway/latex.treetop +81 -0
  27. data/lib/hemingway/latex_nodes.rb +45 -0
  28. data/lib/hemingway/math/math.rb +135 -0
  29. data/lib/hemingway/math/math.treetop +29 -0
  30. data/lib/hemingway/math/math_nodes.rb +7 -0
  31. data/lib/hemingway/special/special.rb +164 -0
  32. data/lib/hemingway/special/special.treetop +17 -0
  33. data/lib/hemingway/special/special_nodes.rb +7 -0
  34. data/lib/hemingway/symbol/symbol.rb +460 -0
  35. data/lib/hemingway/symbol/symbol.treetop +47 -0
  36. data/lib/hemingway/symbol/symbol_nodes.rb +7 -0
  37. data/lib/hemingway/tag/tag.rb +538 -0
  38. data/lib/hemingway/tag/tag.treetop +63 -0
  39. data/lib/hemingway/tag/tag_nodes.rb +49 -0
  40. data/lib/hemingway/text/text.rb +121 -0
  41. data/lib/hemingway/text/text.treetop +35 -0
  42. data/lib/hemingway/text/text_nodes.rb +7 -0
  43. data/lib/hemingway/version.rb +3 -0
  44. data/lib/hemingway.rb +7 -0
  45. data/script/build +22 -0
  46. data/script/test +2 -0
  47. data/spec/build_spec.rb +65 -0
  48. data/spec/nodes/block/list_spec.rb +91 -0
  49. data/spec/nodes/block/quote_spec.rb +31 -0
  50. data/spec/nodes/block/verbatim_spec.rb +27 -0
  51. data/spec/nodes/block_spec.rb +21 -0
  52. data/spec/nodes/footnote_spec.rb +42 -0
  53. data/spec/nodes/math_spec.rb +31 -0
  54. data/spec/nodes/special_spec.rb +27 -0
  55. data/spec/nodes/tag_spec.rb +98 -0
  56. data/spec/parser_spec.rb +48 -0
  57. data/spec/spec_helper.rb +5 -0
  58. metadata +110 -18
@@ -0,0 +1,121 @@
1
+ # Autogenerated from a Treetop grammar. Edits may be lost.
2
+
3
+
4
+ require "hemingway/text/text_nodes"
5
+
6
+ module Hemingway
7
+ module Text
8
+ include Treetop::Runtime
9
+
10
+ def root
11
+ @root ||= :text
12
+ end
13
+
14
+ module Text0
15
+ end
16
+
17
+ def _nt_text
18
+ start_index = index
19
+ if node_cache[:text].has_key?(index)
20
+ cached = node_cache[:text][index]
21
+ if cached
22
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
23
+ @index = cached.interval.end
24
+ end
25
+ return cached
26
+ end
27
+
28
+ s0, i0 = [], index
29
+ loop do
30
+ i1, s1 = index, []
31
+ i2 = index
32
+ r3 = _nt_non_text
33
+ if r3
34
+ r2 = nil
35
+ else
36
+ @index = i2
37
+ r2 = instantiate_node(SyntaxNode,input, index...index)
38
+ end
39
+ s1 << r2
40
+ if r2
41
+ if index < input_length
42
+ r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
43
+ @index += 1
44
+ else
45
+ terminal_parse_failure("any character")
46
+ r4 = nil
47
+ end
48
+ s1 << r4
49
+ end
50
+ if s1.last
51
+ r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
52
+ r1.extend(Text0)
53
+ else
54
+ @index = i1
55
+ r1 = nil
56
+ end
57
+ if r1
58
+ s0 << r1
59
+ else
60
+ break
61
+ end
62
+ end
63
+ if s0.empty?
64
+ @index = i0
65
+ r0 = nil
66
+ else
67
+ r0 = instantiate_node(TextNode,input, i0...index, s0)
68
+ end
69
+
70
+ node_cache[:text][start_index] = r0
71
+
72
+ r0
73
+ end
74
+
75
+ def _nt_non_text
76
+ start_index = index
77
+ if node_cache[:non_text].has_key?(index)
78
+ cached = node_cache[:non_text][index]
79
+ if cached
80
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
81
+ @index = cached.interval.end
82
+ end
83
+ return cached
84
+ end
85
+
86
+ i0 = index
87
+ r1 = _nt_escape
88
+ if r1
89
+ r0 = r1
90
+ else
91
+ r2 = _nt_tag_end
92
+ if r2
93
+ r0 = r2
94
+ else
95
+ r3 = _nt_math_start
96
+ if r3
97
+ r0 = r3
98
+ else
99
+ r4 = _nt_newline
100
+ if r4
101
+ r0 = r4
102
+ else
103
+ @index = i0
104
+ r0 = nil
105
+ end
106
+ end
107
+ end
108
+ end
109
+
110
+ node_cache[:non_text][start_index] = r0
111
+
112
+ r0
113
+ end
114
+
115
+ end
116
+
117
+ class TextParser < Treetop::Runtime::CompiledParser
118
+ include Text
119
+ end
120
+
121
+ end
@@ -0,0 +1,35 @@
1
+ require "hemingway/text/text_nodes"
2
+
3
+ module Hemingway
4
+ grammar Text
5
+
6
+ # Example: blah blah blah
7
+ # Notes:
8
+ # - Okay so this is midly confusing. It's super important to keep the idea
9
+ # of what text is consumed in mind. If I just have the rule as
10
+ #
11
+ # !( non_text / eop)+
12
+ #
13
+ # it will never consume any text [because negative lookahead assertions
14
+ # don't consume text]. When this runs it would just sit on the first
15
+ # character and continually check for non_text, causing a deadspin if it
16
+ # wasn't a non_text. To fix this, make it a sequence with '.'. The '.' will
17
+ # consume any input and keep that index moving along until in fact we find
18
+ # our non_text.
19
+ # - Okay another super important consideration: I MUST use
20
+ # the + rather than the *. If I use *, then the empty string will match
21
+ # text, and because the parent rule of paragraph has zero or more texts in
22
+ # a sequence, it will forever match the empty string and never move onto
23
+ # eop. We much only match text when there is one or more characters, a
24
+ # totally reasonable rule.
25
+ rule text
26
+ ( !non_text . )+ <TextNode>
27
+ end
28
+
29
+ # If you hit any of these while chomping on text you should pop out
30
+ rule non_text
31
+ escape / tag_end / math_start / newline
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,7 @@
1
+ module Hemingway
2
+ module TextNode
3
+ def html
4
+ text_value
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module Hemingway
2
+ VERSION = "0.0.2"
3
+ end
data/lib/hemingway.rb CHANGED
@@ -0,0 +1,7 @@
1
+ require "treetop"
2
+ require "hemingway/latex"
3
+
4
+ module Hemingway
5
+ # This aliases the LatexParser that treetop generates as Parser
6
+ Parser = LatexParser
7
+ end
data/script/build ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ def compile_and_recurse
4
+
5
+ # Compile all of the treetop files in the pwd
6
+ Dir.glob("*.treetop").each do |treetop_file|
7
+ system "tt -f #{treetop_file}"
8
+ end
9
+
10
+ # Get a list of all the directories in the pwd
11
+ Dir.glob("*").select do |file_name|
12
+ Dir.exists?(file_name)
13
+ end.each do |dir|
14
+ Dir.chdir(dir)
15
+ compile_and_recurse
16
+ Dir.chdir("..")
17
+ end
18
+
19
+ end
20
+
21
+ Dir.chdir("lib/hemingway")
22
+ compile_and_recurse
data/script/test ADDED
@@ -0,0 +1,2 @@
1
+ script/build
2
+ rspec -f d --color
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ module Hemingway
4
+
5
+ describe Build do
6
+
7
+ describe "#tag" do
8
+ let(:attribute) { "div" }
9
+ let(:content) { "king of the dinos" }
10
+ let(:klass) { "trex" }
11
+ let(:id) { "tom" }
12
+ let(:href) { "http://t-bone.org" }
13
+
14
+ it 'should generate a tag with no content or class' do
15
+ Build.tag(attribute).should == "<#{attribute}></#{attribute}>"
16
+ end
17
+
18
+ it 'should generate a tag with content' do
19
+ Build.tag(attribute, content).should == "<#{attribute}>#{content}</#{attribute}>"
20
+ end
21
+
22
+ it 'should generate a tag with content and a class' do
23
+ Build.tag(attribute, content, :class => klass).should == "<#{attribute} class='#{klass}'>#{content}</#{attribute}>"
24
+ end
25
+
26
+ it 'should generate a tag with content and an id' do
27
+ Build.tag(attribute, content, :id => id).should == "<#{attribute} id='#{id}'>#{content}</#{attribute}>"
28
+ end
29
+
30
+ it 'should generate a tag with content and an href' do
31
+ Build.tag(attribute, content, :href => href).should == "<#{attribute} href='#{href}'>#{content}</#{attribute}>"
32
+ end
33
+
34
+ it 'should generate a tag with content and an id and a class' do
35
+ Build.tag(attribute, content, :id => id, :class => klass).should == "<#{attribute} id='#{id}' class='#{klass}'>#{content}</#{attribute}>"
36
+ end
37
+
38
+ it 'should generate a tag with content and an id and a class and an href' do
39
+ Build.tag(attribute, content, :id => id, :class => klass, :href => href).should == "<#{attribute} id='#{id}' class='#{klass}' href='#{href}'>#{content}</#{attribute}>"
40
+ end
41
+
42
+ # Can't wait for Ruby 2.0
43
+ it 'should generate a tag with content and a class and no content' do
44
+ Build.tag(attribute, nil, :class => klass).should == "<#{attribute} class='#{klass}'></#{attribute}>"
45
+ end
46
+
47
+ it 'should allow me to create a tag that doesnt close' do
48
+ Build.tag("hr", nil, :close_tag => false).should == "<hr>"
49
+ end
50
+
51
+ end
52
+
53
+ describe "#symbol" do
54
+
55
+ let(:symbol) { "\\Delta" }
56
+
57
+ it 'should translate the Latex symbol into an html equiavalent' do
58
+ Build.symbol(symbol).should == "&Delta;"
59
+ end
60
+
61
+ end
62
+
63
+ end
64
+
65
+ end
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+
3
+ module Hemingway
4
+
5
+ describe Parser do
6
+
7
+ before do
8
+ @parser = Parser.new
9
+ end
10
+
11
+ describe "#itemize" do
12
+
13
+ it 'allows me to create an itemized list' do
14
+ html = @parser.parse("\\begin{itemize}\\item thing 1 \\item thing 2 \\end{itemize}").html
15
+ html.should == "<div class='entry'><p><ul><li>thing 1 </li><li>thing 2 </li></ul></p></div>"
16
+ end
17
+
18
+ it 'eats up any extra newlines and such between items' do
19
+ html = @parser.parse("\\begin{itemize}\\item thing 1 \n\n\n \\item thing 2 \n \\end{itemize}").html
20
+ html.should == "<div class='entry'><p><ul><li>thing 1 </li><li>thing 2 </li></ul></p></div>"
21
+ end
22
+
23
+ it 'supports text, tags, special chars, math inline' do
24
+ html = @parser.parse("\\begin{itemize}\\item hey \\emph{$\\lambda$} \\$ buddies \\end{itemize}").html
25
+ html.should == "<div class='entry'><p><ul><li>hey <em>&lambda;</em> $ buddies </li></ul></p></div>"
26
+ end
27
+
28
+ it 'supports items to have labels on them with various spacing' do
29
+ html = @parser.parse("\\begin{itemize}\\item[bros] over hoes \\item \n [chicks] before dicks \\end{itemize}").html
30
+ html.should == "<div class='entry'><p><ul><li><span class='list-label'>bros</span> over hoes </li><li><span class='list-label'>chicks</span> before dicks </li></ul></p></div>"
31
+ end
32
+
33
+ it 'supports text, tags, special chars, and math in labels' do
34
+ html = @parser.parse("\\begin{itemize}\\item[so many \\emph{vibes} $\\lambda$ \\$ \\$] to be had \\end{itemize}").html
35
+ html.should == "<div class='entry'><p><ul><li><span class='list-label'>so many <em>vibes</em> &lambda; $ $</span> to be had </li></ul></p></div>"
36
+ end
37
+
38
+ it 'supports empty labels' do
39
+ html = @parser.parse("\\begin{itemize}\\item[] do or do not \\end{itemize}").html
40
+ html.should == "<div class='entry'><p><ul><li><span class='list-label'></span> do or do not </li></ul></p></div>"
41
+ end
42
+
43
+ it 'supports empty items with labels' do
44
+ html = @parser.parse("\\begin{itemize}\\item[Millenium \\emph{Falcon}] \\item Slave-1 \\end{itemize}").html
45
+ html.should == "<div class='entry'><p><ul><li><span class='list-label'>Millenium <em>Falcon</em></span> </li><li>Slave-1 </li></ul></p></div>"
46
+ end
47
+
48
+ it 'supports empty items without labels' do
49
+ html = @parser.parse("\\begin{itemize}\\item \\item ears off a gundart \\end{itemize}").html
50
+ html.should == "<div class='entry'><p><ul><li></li><li>ears off a gundart </li></ul></p></div>"
51
+ end
52
+
53
+ it 'should allow me to nest some lists' do
54
+ html = @parser.parse("\\begin{itemize} \\item[another list] \\begin{itemize} \\item[nesting \\emph{vibes}] over here \\end{itemize} \\item for good measure \\end{itemize}").html
55
+ html.should == "<div class='entry'><p><ul><li><span class='list-label'>another list</span> <ul><li><span class='list-label'>nesting <em>vibes</em></span> over here </li></ul> </li><li>for good measure </li></ul></p></div>"
56
+ end
57
+
58
+ it 'should nest 3 layers deep just for fun' do
59
+ html = @parser.parse("\\begin{itemize} \\item \\begin{itemize} \\item \\begin{itemize} \\item hey \\end{itemize} \\end{itemize} \\end{itemize}").html
60
+ html.should == "<div class='entry'><p><ul><li><ul><li><ul><li>hey </li></ul> </li></ul> </li></ul></p></div>"
61
+ end
62
+
63
+ end
64
+
65
+ describe "#enumerate" do
66
+ it 'should allow me to create an ordered list' do
67
+ html = @parser.parse("\\begin{enumerate} \\item Frodo \\item Sam \\end{enumerate}").html
68
+ html.should == "<div class='entry'><p><ol><li>Frodo </li><li>Sam </li></ol></p></div>"
69
+ end
70
+
71
+ it 'should allow me to nest an unordered list in an ordered list' do
72
+ html = @parser.parse("\\begin{enumerate} \\item \\begin{itemize} \\item Frodo \\item Pippin \\end{itemize} \\item Sam \\end{enumerate}").html
73
+ html.should == "<div class='entry'><p><ol><li><ul><li>Frodo </li><li>Pippin </li></ul> </li><li>Sam </li></ol></p></div>"
74
+ end
75
+ end
76
+
77
+ describe "#description" do
78
+ it 'should allow me to create a dictionary list' do
79
+ html = @parser.parse("\\begin{description} \\item Frodo \\item Sam \\end{description}").html
80
+ html.should == "<div class='entry'><p><dl><dd>Frodo </dd><dd>Sam </dd></dl></p></div>"
81
+ end
82
+
83
+ it 'should wrap labels in the dictionary label tag' do
84
+ html = @parser.parse("\\begin{description} \\item [Frodo] Adventuerer \\item [Sam] Faithful Companion \\end{description}").html
85
+ html.should == "<div class='entry'><p><dl><dd><dt>Frodo</dt> Adventuerer </dd><dd><dt>Sam</dt> Faithful Companion </dd></dl></p></div>"
86
+ end
87
+ end
88
+
89
+ end
90
+ end
91
+
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ module Hemingway
4
+
5
+ describe Parser do
6
+
7
+ before do
8
+ @parser = Parser.new
9
+ end
10
+
11
+ describe "#quote" do
12
+
13
+ it 'parses simple block quotes' do
14
+ html = @parser.parse("\\begin{quote}\nHave you guys ever heard the song \\emph{Blow} by \\emph{MILF}?\n\\end{quote}").html
15
+ html.should == "<div class='entry'><p><blockquote><p>Have you guys ever heard the song <em>Blow</em> by <em>MILF</em>?</p></blockquote></p></div>"
16
+ end
17
+
18
+ it 'parses multi-paragraph block quotes' do
19
+ html = @parser.parse("\\begin{quote}\n We really ought to listen to The Smiths more. \n\n Melancholy can be a good thing. \n\\end{quote}").html
20
+ html.should == "<div class='entry'><p><blockquote><p>We really ought to listen to The Smiths more. </p><p> Melancholy can be a good thing. </p></blockquote></p></div>"
21
+ end
22
+
23
+ it 'doesnt support footnotes' do
24
+ @parser.parse("\\begin{quote}\n T-Rex\\footnote{King of the Dinos} \n\\end{quote}").should be_nil
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ module Hemingway
4
+
5
+ describe Parser do
6
+
7
+ before do
8
+ @parser = Parser.new
9
+ end
10
+
11
+ describe "#verbatim" do
12
+
13
+ it 'allows me to instantiate pre-formatted text' do
14
+ html = @parser.parse("\\begin{verbatim} don't we \n \n all wish \n \n for a little sleep? \\end{verbatim}").html
15
+ html.should == "<div class='entry'><p><pre>don't we \n \n all wish \n \n for a little sleep? </pre></p></div>"
16
+ end
17
+
18
+ it 'allows me to write tex markup that isnt parses' do
19
+ html = @parser.parse("\\begin{verbatim} Emphasized text uses the \\emph{} tag. \\end{verbatim}").html
20
+ html.should == "<div class='entry'><p><pre>Emphasized text uses the \\emph{} tag. </pre></p></div>"
21
+ end
22
+
23
+ end
24
+
25
+ end
26
+ end
27
+
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ module Hemingway
4
+
5
+ describe Parser do
6
+
7
+ before do
8
+ @parser = Parser.new
9
+ end
10
+
11
+ describe "#block" do
12
+
13
+ it "should only parse blocks with matching begin and end tags" do
14
+ @parser.parse("\\begin{itemize} \\item hey \\end{description}").should be_nil
15
+ end
16
+
17
+ end
18
+
19
+ end
20
+ end
21
+
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ module Hemingway
4
+
5
+ describe Parser do
6
+
7
+ before do
8
+ @parser = Parser.new
9
+ end
10
+
11
+ describe "#footnote" do
12
+
13
+ it "should put a footnote at the end of a paragraph" do
14
+ html = @parser.parse("You are what you redpoint\\footnote{sending a lead route}, after all.").html
15
+ html.should == "<div class='entry'><p>You are what you redpoint<a href='#footnote1'><span class='inline-footnote-number'><sup>1</sup></span></a>, after all.</p><div id='footnote1' class='footnote'><span class='footnote-number'><sup>1</sup></span>sending a lead route</div></div>"
16
+ end
17
+
18
+ it "should put properly increment the footnote count per entry" do
19
+ html = @parser.parse("Slowly, Vader\\footnote{thug} approached Luke\\footnote{homeboy}").html
20
+ html.should == "<div class='entry'><p>Slowly, Vader<a href='#footnote1'><span class='inline-footnote-number'><sup>1</sup></span></a> approached Luke<a href='#footnote2'><span class='inline-footnote-number'><sup>2</sup></span></a></p><div id='footnote1' class='footnote'><span class='footnote-number'><sup>1</sup></span>thug</div><div id='footnote2' class='footnote'><span class='footnote-number'><sup>2</sup></span>homeboy</div></div>"
21
+ end
22
+
23
+ it "should support any type of content in a footnote" do
24
+ html = @parser.parse("Dave Graham\\footnote{\\emph{Boulderer}, and \& all around \\textsc{good} guy $\\gamma$} makes the best mixtapes").html
25
+ html.should == "<div class='entry'><p>Dave Graham<a href='#footnote1'><span class='inline-footnote-number'><sup>1</sup></span></a> makes the best mixtapes</p><div id='footnote1' class='footnote'><span class='footnote-number'><sup>1</sup></span><em>Boulderer</em>, and & all around <span class='textsc'>good</span> guy &gamma;</div></div>"
26
+ end
27
+
28
+ it "should properly place footnotes from all paragraphs after all paragraphs an increment properly" do
29
+ html = @parser.parse("Freddie Gibbs\\footnote{from Gary, Indiana} is hood\\footnote{thug} as all hell.\n\n John Russel\\footnote{of Short Bus fame} almost got raped in Gary, ID\\footnote{but not by Freddie Gibbs}").html
30
+ html.should == "<div class='entry'><p>Freddie Gibbs<a href='#footnote1'><span class='inline-footnote-number'><sup>1</sup></span></a> is hood<a href='#footnote2'><span class='inline-footnote-number'><sup>2</sup></span></a> as all hell.</p><p> John Russel<a href='#footnote3'><span class='inline-footnote-number'><sup>3</sup></span></a> almost got raped in Gary, ID<a href='#footnote4'><span class='inline-footnote-number'><sup>4</sup></span></a></p><div id='footnote1' class='footnote'><span class='footnote-number'><sup>1</sup></span>from Gary, Indiana</div><div id='footnote2' class='footnote'><span class='footnote-number'><sup>2</sup></span>thug</div><div id='footnote3' class='footnote'><span class='footnote-number'><sup>3</sup></span>of Short Bus fame</div><div id='footnote4' class='footnote'><span class='footnote-number'><sup>4</sup></span>but not by Freddie Gibbs</div></div>"
31
+ end
32
+
33
+ it "will obviously allow me to drop a list in a footnote (this is just for my own satisfaction mostly)" do
34
+ html = @parser.parse("There are some rules\\footnote{\\begin{itemize} \\item Steezy socks always \\item Brosend often \\item Everything for the ladies \\end{itemize}} that we all must live by.").html
35
+ html.should == "<div class='entry'><p>There are some rules<a href='#footnote1'><span class='inline-footnote-number'><sup>1</sup></span></a> that we all must live by.</p><div id='footnote1' class='footnote'><span class='footnote-number'><sup>1</sup></span><ul><li>Steezy socks always </li><li>Brosend often </li><li>Everything for the ladies </li></ul></div></div>"
36
+ end
37
+
38
+ end
39
+
40
+ end
41
+ end
42
+
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ module Hemingway
4
+
5
+ describe Parser do
6
+
7
+ before do
8
+ @parser = Parser.new
9
+ end
10
+
11
+ describe "#math" do
12
+ it 'should parse out a math symbol' do
13
+ html = @parser.parse("$\\Delta$").html
14
+ html.should == "<div class='entry'><p>&Delta;</p></div>"
15
+ end
16
+
17
+ it 'should allow me to nest math symbols in a tag' do
18
+ html = @parser.parse("\\emph{$\\Delta$}").html
19
+ html.should == "<div class='entry'><p><em>&Delta;</em></p></div>"
20
+ end
21
+
22
+ it 'should escape text properly into a math symbol' do
23
+ html = @parser.parse("hello $\\Delta$").html
24
+ html.should == "<div class='entry'><p>hello &Delta;</p></div>"
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ module Hemingway
4
+
5
+ describe Parser do
6
+
7
+ before do
8
+ @parser = Parser.new
9
+ end
10
+
11
+ describe "#special" do
12
+
13
+ it 'should escape a special character' do
14
+ html = @parser.parse("War \\& Peace").html
15
+ html.should == "<div class='entry'><p>War & Peace</p></div>"
16
+ end
17
+
18
+ it 'should allow for special chars and tags in sequence' do
19
+ html = @parser.parse("War \\& Peace \\textbf{Tolstoy} \\#").html
20
+ html.should == "<div class='entry'><p>War & Peace <strong>Tolstoy</strong> #</p></div>"
21
+ end
22
+
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,98 @@
1
+ require 'spec_helper'
2
+
3
+ module Hemingway
4
+
5
+ describe Parser do
6
+
7
+ before do
8
+ @parser = Parser.new
9
+ end
10
+
11
+ describe "#tag" do
12
+
13
+ it 'should parse an emph tag' do
14
+ html = @parser.parse("a \\emph{hey} b").html
15
+ html.should == "<div class='entry'><p>a <em>hey</em> b</p></div>"
16
+ end
17
+
18
+ it 'should parse a texttt tag' do
19
+ html = @parser.parse("\\texttt{hey}").html
20
+ html.should == "<div class='entry'><p><code>hey</code></p></div>"
21
+ end
22
+
23
+ it 'should parse a textbf tag' do
24
+ html = @parser.parse("\\textbf{hey}").html
25
+ html.should == "<div class='entry'><p><strong>hey</strong></p></div>"
26
+ end
27
+
28
+ it 'should parse a textsc tag' do
29
+ html = @parser.parse("\\textsc{hey}").html
30
+ html.should == "<div class='entry'><p><span class='textsc'>hey</span></p></div>"
31
+ end
32
+
33
+ it 'should allow sequences of content within a tag' do
34
+ html = @parser.parse("\\textsc{hey \\emph{vibes} \& times}").html
35
+ html.should == "<div class='entry'><p><span class='textsc'>hey <em>vibes</em> & times</span></p></div>"
36
+ end
37
+
38
+ end
39
+
40
+ describe "#nesting" do
41
+
42
+ it 'should allow me to nest tags' do
43
+ html = @parser.parse("\\emph{\\texttt{hey}}").html
44
+ html.should == "<div class='entry'><p><em><code>hey</code></em></p></div>"
45
+ end
46
+
47
+ it 'should REALLY allow me to next tags' do
48
+ html = @parser.parse("\\emph{\\texttt{\\texttt{hey}}}").html
49
+ html.should == "<div class='entry'><p><em><code><code>hey</code></code></em></p></div>"
50
+ end
51
+
52
+ it 'should escape special characters in a tag' do
53
+ html = @parser.parse("\\emph{War \\& Peace}").html
54
+ html.should == "<div class='entry'><p><em>War & Peace</em></p></div>"
55
+ end
56
+
57
+ end
58
+
59
+ describe "#vspace" do
60
+
61
+ it 'should build vertical space taking divs' do
62
+ html = @parser.parse("\\vspace{5mm}").html
63
+ html.should == "<div class='entry'><p><div class='vspace5'></div></p></div>"
64
+ end
65
+
66
+ it 'should build vertical space taking divs with double digit heights' do
67
+ html = @parser.parse("\\vspace{12mm}").html
68
+ html.should == "<div class='entry'><p><div class='vspace12'></div></p></div>"
69
+ end
70
+
71
+ end
72
+
73
+ describe '#hfill' do
74
+
75
+ it 'supports right justifying on a line' do
76
+ html = @parser.parse("The love, \\hfill Will").html
77
+ html.should == "<div class='entry'><p>The love, <span class='pull-right'>Will</span></p></div>"
78
+ end
79
+
80
+ it 'allows me to put all the good shit in' do
81
+ html = @parser.parse("The love, \\hfill \\emph{Will} \\textsc{Tha Thrill} $\\delta$ \\textbf{Myers}").html
82
+ html.should == "<div class='entry'><p>The love, <span class='pull-right'><em>Will</em> <span class='textsc'>Tha Thrill</span> &delta; <strong>Myers</strong></span></p></div>"
83
+ end
84
+
85
+ end
86
+
87
+ describe '#neatline' do
88
+
89
+ it 'allows me to add fancy <hr>s to a page' do
90
+ html = @parser.parse("\\neatline").html
91
+ html.should == "<div class='entry'><p><hr class='neatline'></p></div>"
92
+ end
93
+
94
+ end
95
+
96
+ end
97
+
98
+ end