smarky 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d899ab9c2c49e0e1ef563a405a33f34ceea8f679
4
- data.tar.gz: 517a6dcf52a81fdc4bdd56cc4f49150fe512c872
3
+ metadata.gz: fa9f31c6225a86adf76e593a27e76edabcd516ee
4
+ data.tar.gz: e99740f11285229385a36a7e9f9a096e9ab68865
5
5
  SHA512:
6
- metadata.gz: 23932ef26b235379ba126df3e93e7b20cae2769cc1916a1472b7a83f358a158c5445ecb83bd05c37b23a5c0e7c4f37147ce07095944e4aa36676605fa47bd2ee
7
- data.tar.gz: 19c27661e90205aa476c0ffa889e833e2628a7f471466c05d9d18c0b3e859a32a133811669fbf6b09e9b2c2b84d85330fbf94767b74e6ce6f12a07889a674813
6
+ metadata.gz: a21a8033ed7410766a7c1b7e10f3b53a5548a71cdc9b7514a770c4918332fc15011ebe093edbb9d5f8ab479ae6bc9348e53c17aeb09f555ff01977454d6fc7d0
7
+ data.tar.gz: e290a87f88a69bd672aaac30968053d55f2819896ac31bad146b5004545d4ac70e8a91022a37ee6c0f85d9b2d05e3d049159a65d72e2633d2bc93b2c8f4948be
data/README.md CHANGED
@@ -30,13 +30,13 @@ Traditional Markdown renderers will translate this to the following HTML:
30
30
  This is *flat*. Smarky will produce this instead:
31
31
 
32
32
  ```html
33
- <article>
33
+ <article id="the-trial">
34
34
  <h1>The Trial</h1>
35
- <section>
35
+ <section id="chapter-1">
36
36
  <h2>Chapter 1</h2>
37
37
  <p>Someone must have been telling lies about Joseph K. [...]</p>
38
38
  </section>
39
- <section>
39
+ <section id="chapter-2">
40
40
  <h2>Chapter 2</h2>
41
41
  <p>K. was informed by telephone [...]</p>
42
42
  </section>
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'redcarpet'
4
+ require 'smarky'
5
+
6
+ input_file = ARGV[0] || 'index.md'
7
+ if !File.exist?(input_file)
8
+ puts "Usage: smarky [input file path] [output file path]"
9
+ exit
10
+ end
11
+
12
+ output_file = ARGV[1] || File.basename(input_file, '.*') + '.html'
13
+
14
+ document = Smarky.parse(File.read(input_file))
15
+
16
+ File.open(output_file, 'w') do |f|
17
+ # Hacky way of getting nicely indented HTML:
18
+ # http://stackoverflow.com/questions/1898829/how-do-i-pretty-print-html-with-nokogiri
19
+ # This might be a huge mistake.
20
+ f.write(Nokogiri::XML(document.to_html, &:noblanks).to_xhtml(:indent => 4))
21
+ end
@@ -54,6 +54,13 @@ module Smarky
54
54
  end
55
55
  end
56
56
 
57
+ # Special case: when an <article> contains exactly one <section> and nothing more.
58
+ if article.children.length == 1 && article.sections.length == 1
59
+ only_section = article.sections.first
60
+ only_section.name = 'article'
61
+ return only_section
62
+ end
63
+
57
64
  article
58
65
  end
59
66
 
@@ -72,9 +79,22 @@ module Smarky
72
79
  Smarky::Markdown::Kramdown.new
73
80
 
74
81
  else
75
- # Default to Redcarpet
76
- require 'smarky/markdown/redcarpet'
77
- Smarky::Markdown::Redcarpet.new
82
+ # Just use whatever's available.
83
+ if defined?(::Redcarpet)
84
+ require 'smarky/markdown/redcarpet'
85
+ Smarky::Markdown::Redcarpet.new
86
+
87
+ elsif defined?(::Kramdown)
88
+ require 'smarky/markdown/kramdown'
89
+ Smarky::Markdown::Kramdown.new
90
+
91
+ elsif defined?(::Maruku)
92
+ require 'smarky/markdown/maruku'
93
+ Smarky::Markdown::Maruku.new
94
+
95
+ else
96
+ raise "Smarky currently requires Redcarpet, Kramdown, or Maruku!"
97
+ end
78
98
  end
79
99
  end
80
100
  end
@@ -29,6 +29,10 @@ module Smarky
29
29
  @node.name
30
30
  end
31
31
 
32
+ def name=(value)
33
+ @node.name = value
34
+ end
35
+
32
36
  def attributes
33
37
  @node.attributes
34
38
  end
@@ -1,3 +1,3 @@
1
1
  module Smarky
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -49,7 +49,7 @@ describe Smarky::Element do
49
49
  Content content content.
50
50
  EOMARKDOWN
51
51
 
52
- sections.first.title.should == 'This is a title'
52
+ result.title.should == 'This is a title'
53
53
  end
54
54
 
55
55
  it "doesn't have a title if its first child is not a heading" do
@@ -81,9 +81,30 @@ describe Smarky do
81
81
  input <<-EOMARKDOWN
82
82
  Section 1
83
83
  =========
84
+
85
+ Section 2
86
+ =========
87
+ EOMARKDOWN
88
+
89
+ # TODO: This is fragile :( Make it not!
90
+ verify_result '<article>' +
91
+ '<section id="section-1"><h1>Section 1</h1>' + "\n\n" + '</section>' +
92
+ '<section id="section-2"><h1>Section 2</h1></section>' +
93
+ '</article>'
94
+ end
95
+
96
+ it 'adds content directly to the root article if there is only one top-level section' do
97
+ input <<-EOMARKDOWN
98
+ Article
99
+ =======
100
+
101
+ This is some content.
84
102
  EOMARKDOWN
85
103
 
86
- verify_result '<article><section id="section-1"><h1>Section 1</h1></section></article>'
104
+ verify_result [
105
+ [:h1, 'Article'],
106
+ [:p, 'This is some content.']
107
+ ]
87
108
  end
88
109
 
89
110
  it 'renders nested sections for heading elements with descending rank' do
@@ -104,16 +125,14 @@ describe Smarky do
104
125
  EOMARKDOWN
105
126
 
106
127
  verify_result [
128
+ [:h1, 'Section 1'],
129
+ [:p, 'This is section 1.'],
107
130
  [:section,
108
- [:h1, 'Section 1'],
109
- [:p, 'This is section 1.'],
131
+ [:h2, 'Section 1.1'],
132
+ [:p, 'This is section 1.1.'],
110
133
  [:section,
111
- [:h2, 'Section 1.1'],
112
- [:p, 'This is section 1.1.'],
113
- [:section,
114
- [:h3, 'Section 1.1.1'],
115
- [:p, 'This is section 1.1.1.']
116
- ]
134
+ [:h3, 'Section 1.1.1'],
135
+ [:p, 'This is section 1.1.1.']
117
136
  ]
118
137
  ]
119
138
  ]
@@ -1,3 +1,4 @@
1
+ require 'redcarpet'
1
2
  require 'smarky'
2
3
  require 'rspec'
3
4
  require 'heredoc_unindent'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smarky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Tao
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-09 00:00:00.000000000 Z
11
+ date: 2013-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -125,7 +125,8 @@ dependencies:
125
125
  description: Smarky creates structure from Markdown
126
126
  email:
127
127
  - daniel.tao@gmail.com
128
- executables: []
128
+ executables:
129
+ - smarky
129
130
  extensions: []
130
131
  extra_rdoc_files: []
131
132
  files:
@@ -135,6 +136,7 @@ files:
135
136
  - LICENSE.txt
136
137
  - README.md
137
138
  - Rakefile
139
+ - bin/smarky
138
140
  - lib/smarky.rb
139
141
  - lib/smarky/element.rb
140
142
  - lib/smarky/markdown/kramdown.rb
@@ -165,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
167
  version: '0'
166
168
  requirements: []
167
169
  rubyforge_project:
168
- rubygems_version: 2.0.3
170
+ rubygems_version: 2.0.5
169
171
  signing_key:
170
172
  specification_version: 4
171
173
  summary: Smarky creates structure from Markdown
@@ -173,4 +175,3 @@ test_files:
173
175
  - spec/element_spec.rb
174
176
  - spec/smarky_spec.rb
175
177
  - spec/spec_helper.rb
176
- has_rdoc: