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 +4 -4
- data/README.md +3 -3
- data/bin/smarky +21 -0
- data/lib/smarky.rb +23 -3
- data/lib/smarky/element.rb +4 -0
- data/lib/smarky/version.rb +1 -1
- data/spec/element_spec.rb +1 -1
- data/spec/smarky_spec.rb +28 -9
- data/spec/spec_helper.rb +1 -0
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa9f31c6225a86adf76e593a27e76edabcd516ee
|
4
|
+
data.tar.gz: e99740f11285229385a36a7e9f9a096e9ab68865
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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>
|
data/bin/smarky
ADDED
@@ -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
|
data/lib/smarky.rb
CHANGED
@@ -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
|
-
#
|
76
|
-
|
77
|
-
|
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
|
data/lib/smarky/element.rb
CHANGED
data/lib/smarky/version.rb
CHANGED
data/spec/element_spec.rb
CHANGED
data/spec/smarky_spec.rb
CHANGED
@@ -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
|
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
|
-
[:
|
109
|
-
[:p, 'This is section 1.'],
|
131
|
+
[:h2, 'Section 1.1'],
|
132
|
+
[:p, 'This is section 1.1.'],
|
110
133
|
[:section,
|
111
|
-
[:
|
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
|
]
|
data/spec/spec_helper.rb
CHANGED
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.
|
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-
|
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.
|
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:
|