kramdown-asciidoc 1.0.0.alpha.11 → 1.0.0.alpha.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.adoc +18 -0
- data/README.adoc +59 -1
- data/lib/kramdoc.rb +1 -0
- data/lib/kramdown-asciidoc/api.rb +21 -3
- data/lib/kramdown-asciidoc/cli.rb +15 -21
- data/lib/kramdown-asciidoc/converter.rb +5 -2
- data/lib/kramdown-asciidoc/version.rb +1 -1
- data/spec/api_spec.rb +102 -7
- data/spec/cli_spec.rb +26 -14
- data/spec/scenarios/heading/no-auto-ids.adoc +3 -0
- data/spec/scenarios/heading/no-auto-ids.md +3 -0
- data/spec/scenarios/heading/no-auto-ids.opts +3 -0
- data/spec/scenarios/wrap/ventilate-exclamation.adoc +3 -0
- data/spec/scenarios/wrap/ventilate-exclamation.md +1 -0
- data/spec/scenarios/wrap/ventilate-exclamation.opts +1 -0
- data/spec/scenarios/wrap/ventilate-french.adoc +3 -0
- data/spec/scenarios/wrap/ventilate-french.md +1 -0
- data/spec/scenarios/wrap/ventilate-french.opts +1 -0
- data/spec/scenarios/wrap/ventilate-question.adoc +3 -0
- data/spec/scenarios/wrap/ventilate-question.md +3 -0
- data/spec/scenarios/wrap/ventilate-question.opts +1 -0
- data/spec/spec_helper.rb +5 -0
- metadata +27 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64f9079115320afb426fbb449cd0b6163b49fbdeb7ae2dc07407eb37524c787a
|
4
|
+
data.tar.gz: e2b4a086c0ec8248970d4d8f121b9642b8a9665510b69fe658f9311a7f96fa2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a537db76f1c5406c9a991e442fa366a121907c3b3aeb813434da304f2ec37d0773c1a91b72224ff2ab28f7ad8bc8f9884c842dce0d4228f31a44f4aca889a9e
|
7
|
+
data.tar.gz: fd86b40db1f4f2b22d99ae6295a8a78173f0e8039045224306b143f1d6fd96e00e384c6d9fea4873ccad4616771fa29a96b8cb01005e129315d19c729b7a8cb6
|
data/CHANGELOG.adoc
CHANGED
@@ -5,6 +5,24 @@
|
|
5
5
|
This document provides a high-level view of the changes to {project-name} by release.
|
6
6
|
For a detailed view of what has changed, refer to the {uri-repo}/commits/master[commit history] on GitHub.
|
7
7
|
|
8
|
+
== 1.0.0.alpha.12 (2018-08-11) - @mojavelinux
|
9
|
+
|
10
|
+
=== Added
|
11
|
+
|
12
|
+
* encode Markdown source passed to `convert` to UTF-8 with universal newlines unless :encode option is false
|
13
|
+
* `convert_file` now writes output to file specified by :to option, if given (#40)
|
14
|
+
* `convert_file` now returns output as string when value of :to option is falsy (#39)
|
15
|
+
* IO object can be used as value of :to option in `convert` and `convert_file` (#43)
|
16
|
+
* intermediate directories are now created in `convert` instead of `convert_file` (#45)
|
17
|
+
* `convert_file` now writes output file using explicit UTF-8 encoding (#46)
|
18
|
+
* prevent `convert_file` from using input file as implicit output file
|
19
|
+
* allow library to be required via alias `kramdoc`
|
20
|
+
|
21
|
+
=== Changed
|
22
|
+
|
23
|
+
* break on all terminal punctuation (period, question mark, and exclamation mark) when ventilating prose (#51)
|
24
|
+
* consolidated logic in CLI by further delegating to API
|
25
|
+
|
8
26
|
== 1.0.0.alpha.11 (2018-08-02) - @mojavelinux
|
9
27
|
|
10
28
|
=== Added
|
data/README.adoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= {project-name} (Markdown to AsciiDoc)
|
2
2
|
Dan Allen <https://github.com/mojavelinux>
|
3
|
-
v1.0.0.alpha.
|
3
|
+
v1.0.0.alpha.12, 2018-08-11
|
4
4
|
// Aliases:
|
5
5
|
:project-name: Kramdown AsciiDoc
|
6
6
|
:project-handle: kramdown-asciidoc
|
@@ -136,6 +136,64 @@ image::octocat.png[Octocat]
|
|
136
136
|
|
137
137
|
In this scenario, you may need to pass the `imagesdir` attribute to the AsciiDoc processor when converting the output document so the image is resolved, depending on where the image is stored.
|
138
138
|
|
139
|
+
== API
|
140
|
+
|
141
|
+
In additional to the command-line interface, {project-name} also provides a porcelain API.
|
142
|
+
We use the term "`porcelain`" because the API hides the details of registering the converter, preprocessing the Markdown document, parsing the document with kramdown, and calling the converter method to transform the parse tree to AsciiDoc.
|
143
|
+
|
144
|
+
The API consists of two static methods:
|
145
|
+
|
146
|
+
* `Kramdoc.convert(source, opts)` - convert a Markdown string to AsciiDoc
|
147
|
+
* `Kramdoc.convert_file(file, opts)` - convert a Markdown file to AsciiDoc
|
148
|
+
|
149
|
+
NOTE: `Kramdoc` is shorthand for `Kramdown::AsciiDoc` to align with the name of the CLI.
|
150
|
+
|
151
|
+
Both API methods accept the source as the first argument and an options hash as the second.
|
152
|
+
|
153
|
+
To convert a Markdown file to AsciiDoc using the {project-name} API, pass the name of the file to the `Kramdoc.convert_file` method as follows:
|
154
|
+
|
155
|
+
[source,ruby]
|
156
|
+
----
|
157
|
+
require 'kramdown-asciidoc'
|
158
|
+
|
159
|
+
Kramdoc.convert_file 'sample.md'
|
160
|
+
----
|
161
|
+
|
162
|
+
Like the command-line, `Kramdoc.convert_file` converts the Markdown file to an adjacent AsciiDoc file calculated by removing the Markdown file extension, `.md`, and replacing it with the AsciiDoc file extension, `.adoc`.
|
163
|
+
|
164
|
+
If you want to direct the output to a different file, pass the name of that file to the `Kramdoc.convert_file` method using the `:to` option as follows:
|
165
|
+
|
166
|
+
[source,ruby]
|
167
|
+
----
|
168
|
+
require 'kramdown-asciidoc'
|
169
|
+
|
170
|
+
Kramdoc.convert_file 'sample.md', to: 'result.adoc'
|
171
|
+
----
|
172
|
+
|
173
|
+
To convert a Markdown string to an AsciiDoc string using the {project-name} API, pass the string to the `Kramdoc.convert` method as follows:
|
174
|
+
|
175
|
+
[source,ruby]
|
176
|
+
----
|
177
|
+
require 'kramdown-asciidoc'
|
178
|
+
|
179
|
+
markdown = <<~EOS
|
180
|
+
# Document Title
|
181
|
+
|
182
|
+
Hello, world!
|
183
|
+
EOS
|
184
|
+
|
185
|
+
asciidoc = Kramdoc.convert markdown
|
186
|
+
----
|
187
|
+
|
188
|
+
If you want to direct the output to a file, pass the name of that file to the `Kramdoc.convert` method using the `:to` option as follows:
|
189
|
+
|
190
|
+
[source,ruby]
|
191
|
+
----
|
192
|
+
Kramdoc.convert markdown, to: 'result.adoc'
|
193
|
+
----
|
194
|
+
|
195
|
+
The input string is automatically converted to UTF-8.
|
196
|
+
|
139
197
|
== Development
|
140
198
|
|
141
199
|
To help develop {project-name}, or to simply test-drive the development version, you need to retrieve the source from GitHub.
|
data/lib/kramdoc.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'kramdown-asciidoc'
|
@@ -1,16 +1,27 @@
|
|
1
1
|
module Kramdown; module AsciiDoc
|
2
|
+
CR = ?\r
|
2
3
|
LF = ?\n
|
4
|
+
UTF_8 = ::Encoding::UTF_8
|
3
5
|
|
4
6
|
def self.convert markdown, opts = {}
|
7
|
+
unless (opts.delete :encode) == false || (markdown.encoding == UTF_8 && !(markdown.include? CR))
|
8
|
+
markdown = markdown.encode UTF_8, universal_newline: true
|
9
|
+
end
|
5
10
|
markdown = markdown.rstrip
|
6
11
|
markdown = markdown.slice 1, markdown.length while markdown.start_with? LF
|
12
|
+
# QUESTION should we .dup?
|
7
13
|
attributes = (opts[:attributes] ||= {})
|
8
14
|
markdown = ::Kramdown::AsciiDoc.extract_front_matter markdown, attributes
|
9
15
|
markdown = ::Kramdown::AsciiDoc.replace_toc markdown, attributes
|
10
16
|
asciidoc = (::Kramdown::Document.new markdown, (::Kramdown::AsciiDoc::DEFAULT_PARSER_OPTS.merge opts)).to_asciidoc
|
11
17
|
asciidoc += LF unless asciidoc.empty?
|
12
18
|
if (to = opts[:to])
|
13
|
-
(to.respond_to? :write)
|
19
|
+
if ::Pathname === to || (!(to.respond_to? :write) && (to = ::Pathname.new to.to_s))
|
20
|
+
to.dirname.mkpath
|
21
|
+
to.write asciidoc, encoding: UTF_8
|
22
|
+
else
|
23
|
+
to.write asciidoc
|
24
|
+
end
|
14
25
|
nil
|
15
26
|
else
|
16
27
|
asciidoc
|
@@ -19,8 +30,15 @@ module Kramdown; module AsciiDoc
|
|
19
30
|
|
20
31
|
def self.convert_file markdown_file, opts = {}
|
21
32
|
markdown = ::IO.read markdown_file, mode: 'r:UTF-8', newline: :universal
|
22
|
-
(
|
23
|
-
|
33
|
+
if (to = opts[:to])
|
34
|
+
to = ::Pathname.new to.to_s unless ::Pathname === to || (to.respond_to? :write)
|
35
|
+
else
|
36
|
+
unless opts.key? :to
|
37
|
+
to = (::Pathname.new markdown_file).sub_ext '.adoc'
|
38
|
+
raise ::IOError, %(input and output cannot be the same file: #{markdown_file}) if to.to_s == markdown_file.to_s
|
39
|
+
end
|
40
|
+
end
|
41
|
+
convert markdown, (opts.merge to: to, encode: false)
|
24
42
|
end
|
25
43
|
end; end
|
26
44
|
|
@@ -91,34 +91,28 @@ module Kramdown; module AsciiDoc
|
|
91
91
|
rescue ::OptionParser::InvalidOption
|
92
92
|
$stderr.write %(#{opt_parser.program_name}: #{$!.message}\n)
|
93
93
|
$stdout.write opt_parser.help
|
94
|
-
|
94
|
+
1
|
95
95
|
end
|
96
96
|
|
97
97
|
def self.run args = ARGV
|
98
|
-
code, options = new.parse args
|
98
|
+
code, options = new.parse (Array args)
|
99
99
|
return code unless code == 0 && options
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
if output_file == '-'
|
108
|
-
pipe_out = true
|
109
|
-
else
|
110
|
-
(output_file = ::Pathname.new output_file).dirname.mkpath
|
111
|
-
end
|
112
|
-
else
|
113
|
-
output_file = (::Pathname.new input_file).sub_ext '.adoc'
|
114
|
-
end
|
115
|
-
if !pipe_in && !pipe_out && (::File.expand_path input_file) == output_file.expand_path.to_s
|
116
|
-
$stderr.write %(kramdoc: input and output file cannot be the same: #{input_file}\n)
|
100
|
+
pipe_in = (input_file = options.delete :input_file) == '-'
|
101
|
+
pipe_out = (output_file = options.delete :output_file) == '-'
|
102
|
+
if pipe_in
|
103
|
+
options[:to] = pipe_out || !output_file ? $stdout : output_file
|
104
|
+
::Kramdoc.convert $stdin.read, options
|
105
|
+
elsif output_file && !pipe_out && (::File.expand_path input_file) == (::File.expand_path output_file)
|
106
|
+
$stderr.write %(kramdoc: input and output cannot be the same file: #{input_file}\n)
|
117
107
|
return 1
|
108
|
+
else
|
109
|
+
options[:to] = pipe_out ? $stdout : output_file if output_file
|
110
|
+
::Kramdoc.convert_file input_file, options
|
118
111
|
end
|
119
|
-
# QUESTION should we set :from option?
|
120
|
-
::Kramdoc.convert markdown, (options.merge to: (pipe_out ? $stdout : output_file))
|
121
112
|
0
|
113
|
+
rescue ::IOError => e
|
114
|
+
$stderr.write %(kramdoc: #{e.message}\n)
|
115
|
+
1
|
122
116
|
end
|
123
117
|
end
|
124
118
|
end; end
|
@@ -51,6 +51,7 @@ module Kramdown; module AsciiDoc
|
|
51
51
|
ADMON_TYPE_MAP = ADMON_LABELS.map {|l, _| [l, l.upcase] }.to_h.merge 'Attention' => 'IMPORTANT', 'Hint' => 'TIP'
|
52
52
|
BLOCK_TYPES = [:p, :blockquote, :codeblock, :table]
|
53
53
|
DLIST_MARKERS = %w(:: ;; ::: ::::)
|
54
|
+
PUNCTUATION = %w(. ? !)
|
54
55
|
# FIXME here we reverse the smart quotes; add option to allow them (needs to be handled carefully)
|
55
56
|
SMART_QUOTE_ENTITY_TO_MARKUP = { ldquo: ?", rdquo: ?", lsquo: ?', rsquo: ?' }
|
56
57
|
TYPOGRAPHIC_SYMBOL_TO_MARKUP = {
|
@@ -83,7 +84,7 @@ module Kramdown; module AsciiDoc
|
|
83
84
|
|
84
85
|
CommentPrefixRx = /^ *! ?/m
|
85
86
|
CssPropDelimRx = /\s*;\s*/
|
86
|
-
FullStopRx = /(
|
87
|
+
FullStopRx = /(?<=\S\.|.\?|.!)\p{Blank}+/
|
87
88
|
InadvertentReplacementsRx = /[-=]>|<[-=]|\.\.\.|\{\p{Word}[\p{Word}-]*\}/
|
88
89
|
MenuRefRx = /^([\p{Word}&].*?)\s>\s([\p{Word}&].*(?:\s>\s|$))+/
|
89
90
|
ReplaceableTextRx = /[-=]>|<[-=]| -- |\p{Word}--\p{Word}|\*\*|\.\.\.|&\S+;|\{\p{Word}[\p{Word}-]*\}|(?:https?|ftp):\/\/\p{Word}|\((?:C|R|TM)\)/
|
@@ -686,7 +687,9 @@ module Kramdown; module AsciiDoc
|
|
686
687
|
end
|
687
688
|
end
|
688
689
|
if ventilate
|
689
|
-
result.map {|line|
|
690
|
+
result.map {|line|
|
691
|
+
(line.start_with? '//') || !(PUNCTUATION.any? {|punc| line.include? punc }) ? line : (line.gsub FullStopRx, LF)
|
692
|
+
}.join LF
|
690
693
|
else
|
691
694
|
result.join LF
|
692
695
|
end
|
data/spec/api_spec.rb
CHANGED
@@ -20,13 +20,53 @@ describe Kramdown::AsciiDoc do
|
|
20
20
|
(expect subject.convert input).to eql expected
|
21
21
|
end
|
22
22
|
|
23
|
-
it '
|
24
|
-
|
23
|
+
it 'encodes Markdown source to UTF-8' do
|
24
|
+
input = %(bien s\u00fbr !).encode Encoding::ISO_8859_1
|
25
|
+
output = subject.convert input
|
26
|
+
(expect output.encoding).to eql Encoding::UTF_8
|
27
|
+
(expect output).to eql %(bien s\u00fbr !\n)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'converts CRLF newlines in Markdown source to LF newlines' do
|
31
|
+
input = %(\r\n\r\none\r\ntwo\r\nthree\r\n)
|
32
|
+
output = subject.convert input
|
33
|
+
(expect output.encoding).to eql Encoding::UTF_8
|
34
|
+
(expect output).to eql %(one\ntwo\nthree\n)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'converts CR newlines in Markdown source to LF newlines' do
|
38
|
+
input = %(\r\rone\rtwo\rthree\r)
|
39
|
+
output = subject.convert input
|
40
|
+
(expect output.encoding).to eql Encoding::UTF_8
|
41
|
+
(expect output).to eql %(one\ntwo\nthree\n)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'writes AsciiDoc to string path specified by :to option' do
|
45
|
+
the_output_file = output_file 'convert-to-string-path.adoc'
|
25
46
|
(expect subject.convert 'Converted using the API', to: the_output_file).to be_nil
|
26
47
|
(expect (IO.read the_output_file)).to eql %(Converted using the API\n)
|
27
48
|
end
|
28
49
|
|
29
|
-
it '
|
50
|
+
it 'creates intermediary directories when writing to string path specified by :to option' do
|
51
|
+
the_output_file = output_file 'path/to/convert-to-string-path.adoc'
|
52
|
+
the_output_dir = (Pathname.new the_output_file).dirname
|
53
|
+
(expect subject.convert 'Converted using the API', to: the_output_file).to be_nil
|
54
|
+
(expect the_output_dir).to exist
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'writes AsciiDoc to pathname specified by :to option' do
|
58
|
+
the_output_file = Pathname.new output_file 'convert-to-pathname.adoc'
|
59
|
+
(expect subject.convert 'Converted using the API', to: the_output_file).to be_nil
|
60
|
+
(expect the_output_file.read).to eql %(Converted using the API\n)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'creates intermediary directories when writing to pathname specified by :to option' do
|
64
|
+
the_output_file = Pathname.new output_file 'path/to/convert-to-pathname.adoc'
|
65
|
+
(expect subject.convert 'Converted using the API', to: the_output_file).to be_nil
|
66
|
+
(expect the_output_file.dirname).to exist
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'writes AsciiDoc to IO object specified by :to option' do
|
30
70
|
old_stdout, $stdout = $stdout, StringIO.new
|
31
71
|
begin
|
32
72
|
(expect subject.convert 'text', to: $stdout).to be_nil
|
@@ -46,12 +86,63 @@ describe Kramdown::AsciiDoc do
|
|
46
86
|
end
|
47
87
|
|
48
88
|
context '#convert_file' do
|
89
|
+
let(:source) { 'Markdown was *here*, but it has become **AsciiDoc**!' }
|
90
|
+
let(:expected_output) { %(Markdown was _here_, but it has become *AsciiDoc*!\n) }
|
91
|
+
let!(:the_source_file) { (output_file %(convert-file-api-#{object_id}.md)).tap {|file| IO.write file, source } }
|
92
|
+
|
49
93
|
it 'converts Markdown file to AsciiDoc file' do
|
50
|
-
|
51
|
-
the_output_file = output_file 'convert-file-api.adoc'
|
52
|
-
IO.write the_source_file, 'Converted using the API'
|
94
|
+
the_output_file = output_file %(convert-file-api-#{object_id}.adoc)
|
53
95
|
(expect subject.convert_file the_source_file).to be_nil
|
54
|
-
(expect
|
96
|
+
(expect Pathname.new the_output_file).to exist
|
97
|
+
(expect (IO.read the_output_file)).to eql expected_output
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'writes output file to string path specified by :to option' do
|
101
|
+
the_output_file = output_file 'convert-file-to-string-path.adoc'
|
102
|
+
(expect subject.convert_file the_source_file, to: the_output_file).to be_nil
|
103
|
+
(expect (IO.read the_output_file)).to eql expected_output
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'creates intermediary directories when writing to string path specified by :to option' do
|
107
|
+
the_output_file = output_file 'path/to/convert-file-to-string-path.adoc'
|
108
|
+
the_output_dir = (Pathname.new the_output_file).dirname
|
109
|
+
(expect subject.convert_file the_source_file, to: the_output_file).to be_nil
|
110
|
+
(expect the_output_dir).to exist
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'writes output file to pathname specified by :to option' do
|
114
|
+
the_output_file = Pathname.new output_file 'convert-file-to-pathname.adoc'
|
115
|
+
(expect subject.convert_file the_source_file, to: the_output_file).to be_nil
|
116
|
+
(expect (the_output_file.read)).to eql expected_output
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'creates intermediary directories when writing to pathname specified by :to option' do
|
120
|
+
the_output_file = Pathname.new output_file 'path/to/convert-file-to-pathname.adoc'
|
121
|
+
(expect subject.convert_file the_source_file, to: the_output_file).to be_nil
|
122
|
+
(expect the_output_file.dirname).to exist
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'returns output as string if value of :to option is falsy' do
|
126
|
+
(expect subject.convert_file the_source_file, to: nil).to eql expected_output
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'writes output to IO object specified by :to option' do
|
130
|
+
output_sink = StringIO.new
|
131
|
+
(expect subject.convert_file the_source_file, to: output_sink).to be_nil
|
132
|
+
(expect output_sink.string).to eql expected_output
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'writes output file as UTF-8 regardless of default external encoding' do
|
136
|
+
source = %(tr\u00e8s bien !)
|
137
|
+
the_output_file = output_file 'force-encoding.adoc'
|
138
|
+
script_file = output_file 'force-encoding.rb'
|
139
|
+
IO.write script_file, <<~EOS
|
140
|
+
require 'kramdown-asciidoc'
|
141
|
+
Kramdoc.convert '#{source}', to: '#{the_output_file}'
|
142
|
+
EOS
|
143
|
+
# NOTE internal encoding must also be set for test to work on JRuby
|
144
|
+
`#{ruby} -E ISO-8859-1:ISO-8859-1 #{Shellwords.escape script_file}`
|
145
|
+
(expect IO.read the_output_file, mode: 'r:UTF-8').to eql %(#{source}\n)
|
55
146
|
end
|
56
147
|
end
|
57
148
|
end
|
@@ -60,4 +151,8 @@ describe Kramdoc do
|
|
60
151
|
it 'supports Kramdoc as an alias for Kramdown::AsciiDoc' do
|
61
152
|
(expect Kramdoc).to eql Kramdown::AsciiDoc
|
62
153
|
end
|
154
|
+
|
155
|
+
it 'can be required using the alias kramdoc' do
|
156
|
+
require 'kramdoc'
|
157
|
+
end
|
63
158
|
end
|
data/spec/cli_spec.rb
CHANGED
@@ -2,15 +2,17 @@ require_relative 'spec_helper'
|
|
2
2
|
require 'kramdown-asciidoc/cli'
|
3
3
|
|
4
4
|
describe Kramdown::AsciiDoc::Cli do
|
5
|
+
# NOTE override subject to return class object; RSpec returns instance of class by default
|
5
6
|
subject { Kramdown::AsciiDoc::Cli }
|
6
7
|
|
7
8
|
before :each do
|
9
|
+
@old_stdin, $stdin = $stdin, StringIO.new
|
8
10
|
@old_stdout, $stdout = $stdout, StringIO.new
|
9
11
|
@old_stderr, $stderr = $stderr, StringIO.new
|
10
12
|
end
|
11
13
|
|
12
14
|
after :each do
|
13
|
-
$stdout, $stderr = @old_stdout, @old_stderr
|
15
|
+
$stdin, $stdout, $stderr = @old_stdin, @old_stdout, @old_stderr
|
14
16
|
end
|
15
17
|
|
16
18
|
context 'option flags' do
|
@@ -48,7 +50,7 @@ describe Kramdown::AsciiDoc::Cli do
|
|
48
50
|
the_source_file = output_file 'implicit-output.md'
|
49
51
|
the_output_file = output_file 'implicit-output.adoc'
|
50
52
|
IO.write the_source_file, 'This is just a test.'
|
51
|
-
(expect subject.run
|
53
|
+
(expect subject.run the_source_file).to eql 0
|
52
54
|
(expect (IO.read the_output_file).chomp).to eql 'This is just a test.'
|
53
55
|
end
|
54
56
|
|
@@ -71,8 +73,8 @@ describe Kramdown::AsciiDoc::Cli do
|
|
71
73
|
it 'prevents computed output file from overwriting input file' do
|
72
74
|
the_source_file = output_file 'implicit-conflict.adoc'
|
73
75
|
IO.write the_source_file, 'No can do.'
|
74
|
-
expected = %(kramdoc: input and output
|
75
|
-
(expect subject.run
|
76
|
+
expected = %(kramdoc: input and output cannot be the same file: #{the_source_file})
|
77
|
+
(expect subject.run the_source_file).to eql 1
|
76
78
|
(expect $stderr.string.chomp).to eql expected
|
77
79
|
end
|
78
80
|
|
@@ -80,7 +82,7 @@ describe Kramdown::AsciiDoc::Cli do
|
|
80
82
|
the_source_file = output_file 'explicit-conflict.md'
|
81
83
|
the_output_file = the_source_file
|
82
84
|
IO.write the_source_file, 'No can do.'
|
83
|
-
expected = %(kramdoc: input and output
|
85
|
+
expected = %(kramdoc: input and output cannot be the same file: #{the_source_file})
|
84
86
|
(expect subject.run %W(-o #{the_output_file} #{the_source_file})).to eql 1
|
85
87
|
(expect $stderr.string.chomp).to eql expected
|
86
88
|
end
|
@@ -92,15 +94,25 @@ describe Kramdown::AsciiDoc::Cli do
|
|
92
94
|
end
|
93
95
|
|
94
96
|
it 'reads input from stdin when argument is -' do
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
97
|
+
$stdin.puts '- list item'
|
98
|
+
$stdin.rewind
|
99
|
+
(expect subject.run %w(-o - -)).to eql 0
|
100
|
+
(expect $stdout.string.chomp).to eql '* list item'
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'writes output to stdout when input comes from stdin and -o option is not specified' do
|
104
|
+
$stdin.puts '- list item'
|
105
|
+
$stdin.rewind
|
106
|
+
(expect subject.run '-').to eql 0
|
107
|
+
(expect $stdout.string.chomp).to eql '* list item'
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'writes output to file specified by -o option when input comes from stdin' do
|
111
|
+
the_output_file = output_file 'output-from-stdin.adoc'
|
112
|
+
$stdin.puts '- list item'
|
113
|
+
$stdin.rewind
|
114
|
+
(expect subject.run %W(-o #{the_output_file} -)).to eql 0
|
115
|
+
(expect (IO.read the_output_file).chomp).to eql '* list item'
|
104
116
|
end
|
105
117
|
|
106
118
|
it 'removes leading blank lines and trailing whitespace from source' do
|
@@ -0,0 +1 @@
|
|
1
|
+
A horse! A horse! My kingdom for a horse!
|
@@ -0,0 +1 @@
|
|
1
|
+
:wrap: :ventilate
|
@@ -0,0 +1 @@
|
|
1
|
+
Salut mon ami ! As-tu passé un bon weekend ? J'espère.
|
@@ -0,0 +1 @@
|
|
1
|
+
:wrap: :ventilate
|
@@ -0,0 +1 @@
|
|
1
|
+
:wrap: :ventilate
|
data/spec/spec_helper.rb
CHANGED
@@ -10,6 +10,7 @@ end
|
|
10
10
|
require 'kramdown-asciidoc'
|
11
11
|
require 'fileutils'
|
12
12
|
autoload :StringIO, 'stringio'
|
13
|
+
autoload :Shellwords, 'shellwords'
|
13
14
|
|
14
15
|
RSpec.configure do |config|
|
15
16
|
config.after :suite do
|
@@ -33,4 +34,8 @@ RSpec.configure do |config|
|
|
33
34
|
def scenario_file path
|
34
35
|
File.join scenarios_dir, path
|
35
36
|
end
|
37
|
+
|
38
|
+
def ruby
|
39
|
+
Shellwords.escape File.join RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']
|
40
|
+
end
|
36
41
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kramdown-asciidoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.alpha.
|
4
|
+
version: 1.0.0.alpha.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Allen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kramdown
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- Rakefile
|
82
82
|
- bin/kramdoc
|
83
83
|
- kramdown-asciidoc.gemspec
|
84
|
+
- lib/kramdoc.rb
|
84
85
|
- lib/kramdown-asciidoc.rb
|
85
86
|
- lib/kramdown-asciidoc/api.rb
|
86
87
|
- lib/kramdown-asciidoc/cli.rb
|
@@ -214,6 +215,9 @@ files:
|
|
214
215
|
- spec/scenarios/heading/formatting.md
|
215
216
|
- spec/scenarios/heading/leading-anchor.adoc
|
216
217
|
- spec/scenarios/heading/leading-anchor.md
|
218
|
+
- spec/scenarios/heading/no-auto-ids.adoc
|
219
|
+
- spec/scenarios/heading/no-auto-ids.md
|
220
|
+
- spec/scenarios/heading/no-auto-ids.opts
|
217
221
|
- spec/scenarios/heading/not-block-title.adoc
|
218
222
|
- spec/scenarios/heading/not-block-title.md
|
219
223
|
- spec/scenarios/heading/offset.adoc
|
@@ -438,6 +442,15 @@ files:
|
|
438
442
|
- spec/scenarios/wrap/preserve.adoc
|
439
443
|
- spec/scenarios/wrap/preserve.md
|
440
444
|
- spec/scenarios/wrap/preserve.opts
|
445
|
+
- spec/scenarios/wrap/ventilate-exclamation.adoc
|
446
|
+
- spec/scenarios/wrap/ventilate-exclamation.md
|
447
|
+
- spec/scenarios/wrap/ventilate-exclamation.opts
|
448
|
+
- spec/scenarios/wrap/ventilate-french.adoc
|
449
|
+
- spec/scenarios/wrap/ventilate-french.md
|
450
|
+
- spec/scenarios/wrap/ventilate-french.opts
|
451
|
+
- spec/scenarios/wrap/ventilate-question.adoc
|
452
|
+
- spec/scenarios/wrap/ventilate-question.md
|
453
|
+
- spec/scenarios/wrap/ventilate-question.opts
|
441
454
|
- spec/scenarios/wrap/ventilate-table-cell.adoc
|
442
455
|
- spec/scenarios/wrap/ventilate-table-cell.md
|
443
456
|
- spec/scenarios/wrap/ventilate-table-cell.opts
|
@@ -631,6 +644,9 @@ test_files:
|
|
631
644
|
- spec/scenarios/heading/formatting.md
|
632
645
|
- spec/scenarios/heading/leading-anchor.adoc
|
633
646
|
- spec/scenarios/heading/leading-anchor.md
|
647
|
+
- spec/scenarios/heading/no-auto-ids.adoc
|
648
|
+
- spec/scenarios/heading/no-auto-ids.md
|
649
|
+
- spec/scenarios/heading/no-auto-ids.opts
|
634
650
|
- spec/scenarios/heading/not-block-title.adoc
|
635
651
|
- spec/scenarios/heading/not-block-title.md
|
636
652
|
- spec/scenarios/heading/offset.adoc
|
@@ -855,6 +871,15 @@ test_files:
|
|
855
871
|
- spec/scenarios/wrap/preserve.adoc
|
856
872
|
- spec/scenarios/wrap/preserve.md
|
857
873
|
- spec/scenarios/wrap/preserve.opts
|
874
|
+
- spec/scenarios/wrap/ventilate-exclamation.adoc
|
875
|
+
- spec/scenarios/wrap/ventilate-exclamation.md
|
876
|
+
- spec/scenarios/wrap/ventilate-exclamation.opts
|
877
|
+
- spec/scenarios/wrap/ventilate-french.adoc
|
878
|
+
- spec/scenarios/wrap/ventilate-french.md
|
879
|
+
- spec/scenarios/wrap/ventilate-french.opts
|
880
|
+
- spec/scenarios/wrap/ventilate-question.adoc
|
881
|
+
- spec/scenarios/wrap/ventilate-question.md
|
882
|
+
- spec/scenarios/wrap/ventilate-question.opts
|
858
883
|
- spec/scenarios/wrap/ventilate-table-cell.adoc
|
859
884
|
- spec/scenarios/wrap/ventilate-table-cell.md
|
860
885
|
- spec/scenarios/wrap/ventilate-table-cell.opts
|