kramdown-asciidoc 1.0.0.alpha.8 → 1.0.0.alpha.9
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 +4 -4
- data/CHANGELOG.adoc +9 -0
- data/README.adoc +43 -1
- data/lib/kramdown-asciidoc/cli.rb +24 -11
- data/lib/kramdown-asciidoc/converter.rb +7 -13
- data/lib/kramdown-asciidoc/version.rb +1 -1
- data/spec/cli_spec.rb +31 -0
- data/spec/scenarios/codespan/literal.adoc +1 -1
- data/spec/scenarios/codespan/plus-plus.adoc +1 -3
- data/spec/scenarios/codespan/plus-plus.md +1 -1
- data/spec/scenarios/img/implicit-imagesdir.opts +1 -2
- data/spec/scenarios/text/typographic_sym/apostrophe.adoc +2 -0
- data/spec/scenarios/text/typographic_sym/apostrophe.md +2 -0
- data/spec/scenarios/wrap/ventilate-table-cell.adoc +3 -0
- data/spec/scenarios/wrap/ventilate-table-cell.md +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7666c4f1e1efbdee6e39c2506ecec46b77df092366ca3762af7a00d5c926c7c0
|
4
|
+
data.tar.gz: ee1c0de6b84814b1eff1d1c655d2099df112890d36ba11c60ac5bd4e00ae453b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 692a6a4801eaaca673ed8b590544929eeaa76425b5c87859fd9c4819e9cf96f3f8bea606bcbe3f72e19251a498497822dd13d81de6f6de8edc89e72056c460a4
|
7
|
+
data.tar.gz: 5b382ae595d9c4f68d76a1bcd6f8749836b7f5d064ce0963cc1478b31d12fa413c88fbecff2a91c0af8fb15d1c609eaf6b6edc49f69b72d2f3d90fa787c727a3
|
data/CHANGELOG.adoc
CHANGED
@@ -5,6 +5,15 @@
|
|
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.9 (2018-07-10) - @mojavelinux
|
9
|
+
|
10
|
+
=== Changed
|
11
|
+
|
12
|
+
* escape codespan using pass macro if text contains double plus
|
13
|
+
* add specialcharacters replacement to inline pass macro
|
14
|
+
* don't add newline after period at start of line when producing ventilated prose
|
15
|
+
* use :imagesdir API option or --imagesdir CLI option to set implicit imagesdir instead of attribute
|
16
|
+
|
8
17
|
== 1.0.0.alpha.8 (2018-07-03) - @mojavelinux
|
9
18
|
|
10
19
|
=== 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.9, 2018-07-10
|
4
4
|
// Aliases:
|
5
5
|
:project-name: Kramdown AsciiDoc
|
6
6
|
:project-handle: kramdown-asciidoc
|
@@ -85,6 +85,48 @@ To see all the options the `kramdoc` command accepts, pass the `-h` option to th
|
|
85
85
|
|
86
86
|
$ kramdoc -h
|
87
87
|
|
88
|
+
== Configure shared images directory
|
89
|
+
|
90
|
+
If the images in the source document share a common directory prefix, such as [.path]_images/_, you can configure the converter to extract that prefix, optionally promoting it to the document header.
|
91
|
+
|
92
|
+
Let's assume you want to convert the following Markdown source:
|
93
|
+
|
94
|
+
[source,markdown]
|
95
|
+
----
|
96
|
+
# Document Title
|
97
|
+
|
98
|
+

|
99
|
+
----
|
100
|
+
|
101
|
+
You can extract the [.path]_images/_ prefix from the image reference and promote this value to the header of the output document by setting the `imagesdir` attribute:
|
102
|
+
|
103
|
+
$ kramdoc -a imagesdir=images sample.md
|
104
|
+
|
105
|
+
Setting this attribute will produce the following document:
|
106
|
+
|
107
|
+
[source,asciidoc]
|
108
|
+
----
|
109
|
+
= Document Title
|
110
|
+
:imagesdir: images
|
111
|
+
|
112
|
+
image::octocat.png[Octocat]
|
113
|
+
----
|
114
|
+
|
115
|
+
If you want the [.path]_images/_ prefix to be removed altogether and not added to the document header (i.e., an implied prefix), set the `--imagesdir` option instead:
|
116
|
+
|
117
|
+
$ kramdoc --imagesdir=images sample.md
|
118
|
+
|
119
|
+
Setting this option will produce the following document:
|
120
|
+
|
121
|
+
[source,asciidoc]
|
122
|
+
----
|
123
|
+
= Document Title
|
124
|
+
|
125
|
+
image::octocat.png[Octocat]
|
126
|
+
----
|
127
|
+
|
128
|
+
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.
|
129
|
+
|
88
130
|
== Development
|
89
131
|
|
90
132
|
To help develop {project-name}, or to simply test-drive the development version, you need to retrieve the source from GitHub.
|
@@ -20,7 +20,7 @@ module Kramdown; module AsciiDoc
|
|
20
20
|
EOS
|
21
21
|
|
22
22
|
opts.on '-o FILE', '--output=FILE', 'Set the output filename or stream' do |file|
|
23
|
-
options[:
|
23
|
+
options[:output_file] = file
|
24
24
|
end
|
25
25
|
|
26
26
|
opts.on '--format=GFM|kramdown|markdown', %w(kramdown markdown GFM), 'Set the flavor of Markdown to parse (default: GFM)' do |format|
|
@@ -33,11 +33,15 @@ module Kramdown; module AsciiDoc
|
|
33
33
|
options[:attributes][key] = val
|
34
34
|
end
|
35
35
|
|
36
|
-
opts.on '--wrap=preserve|none|ventilate',
|
37
|
-
options[:wrap] = wrap
|
36
|
+
opts.on '--wrap=preserve|none|ventilate', [:none, :preserve, :ventilate], 'Set how lines are wrapped in the AsciiDoc document (default: preserve)' do |wrap|
|
37
|
+
options[:wrap] = wrap
|
38
38
|
end
|
39
39
|
|
40
|
-
opts.on '--
|
40
|
+
opts.on '--imagesdir=DIR', 'Set the leading directory to remove from image references' do |dir|
|
41
|
+
options[:imagesdir] = dir
|
42
|
+
end
|
43
|
+
|
44
|
+
opts.on '--heading-offset=NUMBER', ::Integer, 'Shift the heading level by the specified number' do |offset|
|
41
45
|
options[:heading_offset] = offset
|
42
46
|
end
|
43
47
|
|
@@ -69,7 +73,7 @@ module Kramdown; module AsciiDoc
|
|
69
73
|
end
|
70
74
|
|
71
75
|
if args.size == 1
|
72
|
-
options[:
|
76
|
+
options[:input_file] = args[0]
|
73
77
|
[0, options]
|
74
78
|
else
|
75
79
|
opt_parser.warn %(extra arguments detected (unparsed arguments: #{(args.drop 1).join ' '}))
|
@@ -85,22 +89,31 @@ module Kramdown; module AsciiDoc
|
|
85
89
|
def self.run args = ARGV
|
86
90
|
code, options = new.parse args
|
87
91
|
return code unless code == 0 && options
|
88
|
-
if (
|
92
|
+
if (input_file = options.delete :input_file) == '-'
|
93
|
+
pipe_in = true
|
89
94
|
markdown = $stdin.read.rstrip
|
90
95
|
else
|
91
|
-
markdown = (::IO.read
|
96
|
+
markdown = (::IO.read input_file, mode: 'r:UTF-8', newline: :universal).rstrip
|
92
97
|
end
|
93
|
-
if (output_file = options.delete :
|
94
|
-
|
98
|
+
if (output_file = options.delete :output_file)
|
99
|
+
if output_file == '-'
|
100
|
+
pipe_out = true
|
101
|
+
else
|
102
|
+
(::Pathname.new output_file).dirname.mkpath
|
103
|
+
end
|
95
104
|
else
|
96
|
-
output_file = ((Pathname
|
105
|
+
output_file = ((::Pathname.new input_file).sub_ext '.adoc').to_s
|
106
|
+
end
|
107
|
+
if !(pipe_in || pipe_out) && (::File.absolute_path input_file) == (::File.absolute_path output_file)
|
108
|
+
$stderr.puts %(kramdoc: input and output file cannot be the same: #{input_file})
|
109
|
+
return 1
|
97
110
|
end
|
98
111
|
markdown = markdown.slice 1, markdown.length while markdown.start_with? ?\n
|
99
112
|
attributes = options[:attributes]
|
100
113
|
markdown = ::Kramdown::AsciiDoc.extract_front_matter markdown, attributes
|
101
114
|
markdown = ::Kramdown::AsciiDoc.replace_toc markdown, attributes
|
102
115
|
doc = ::Kramdown::Document.new markdown, (::Kramdown::AsciiDoc::DEFAULT_PARSER_OPTS.merge options)
|
103
|
-
if
|
116
|
+
if pipe_out
|
104
117
|
$stdout.puts doc.to_asciidoc
|
105
118
|
else
|
106
119
|
::IO.write output_file, doc.to_asciidoc
|
@@ -81,10 +81,10 @@ module Kramdown; module AsciiDoc
|
|
81
81
|
|
82
82
|
NON_DEFAULT_TABLE_ALIGNMENTS = [:center, :right]
|
83
83
|
|
84
|
-
AccidentalReplacementsRx = /[-=]>|<[-=]|\.\.\.|\{\p{Word}[\p{Word}-]*\}/
|
85
84
|
CommentPrefixRx = /^ *! ?/m
|
86
85
|
CssPropDelimRx = /\s*;\s*/
|
87
|
-
FullStopRx = /(
|
86
|
+
FullStopRx = /(?<=.\.)\p{Blank}+(?!\Z)/
|
87
|
+
InadvertentReplacementsRx = /[-=]>|<[-=]|\.\.\.|\{\p{Word}[\p{Word}-]*\}/
|
88
88
|
MenuRefRx = /^([\p{Word}&].*?)\s>\s([\p{Word}&].*(?:\s>\s|$))+/
|
89
89
|
ReplaceableTextRx = /[-=]>|<[-=]| -- |\p{Word}--\p{Word}|\*\*|\.\.\.|&\S+;|\{\p{Word}[\p{Word}-]*\}|\((?:C|R|TM)\)/
|
90
90
|
SmartApostropheRx = /\b’\b/
|
@@ -102,7 +102,7 @@ module Kramdown; module AsciiDoc
|
|
102
102
|
def initialize root, opts
|
103
103
|
super
|
104
104
|
@attributes = opts[:attributes] || {}
|
105
|
-
@imagesdir =
|
105
|
+
@imagesdir = opts[:imagesdir] || @attributes['imagesdir']
|
106
106
|
@heading_offset = opts[:heading_offset] || 0
|
107
107
|
@current_heading_level = nil
|
108
108
|
@wrap = opts[:wrap] || :preserve
|
@@ -426,18 +426,11 @@ module Kramdown; module AsciiDoc
|
|
426
426
|
mark = (unconstrained? opts[:prev], opts[:next], :codespan) ? '``' : '`'
|
427
427
|
text = el.value
|
428
428
|
pass = (replaceable? text) ? :shorthand : nil
|
429
|
-
if text.include? '++'
|
430
|
-
if pass
|
431
|
-
pass = :macro
|
432
|
-
else
|
433
|
-
@attributes['pp'] = '{plus}{plus}'
|
434
|
-
text = text.gsub '++', '{pp}'
|
435
|
-
end
|
436
|
-
end
|
429
|
+
pass = :macro if text.include? '++'
|
437
430
|
if pass == :shorthand
|
438
431
|
opts[:writer].append %(#{mark}+#{text}+#{mark})
|
439
432
|
elsif pass == :macro
|
440
|
-
opts[:writer].append %(#{mark}pass:[#{text}]#{mark})
|
433
|
+
opts[:writer].append %(#{mark}pass:c[#{text}]#{mark})
|
441
434
|
else
|
442
435
|
opts[:writer].append %(#{mark}#{text}#{mark})
|
443
436
|
end
|
@@ -489,7 +482,8 @@ module Kramdown; module AsciiDoc
|
|
489
482
|
end
|
490
483
|
|
491
484
|
def escape_replacements text
|
492
|
-
|
485
|
+
# NOTE the replacement \\\\\& inserts a single backslash in front of the matched text
|
486
|
+
text = text.gsub InadvertentReplacementsRx, '\\\\\&' if InadvertentReplacementsRx.match? text
|
493
487
|
text = text.gsub '^', '{caret}' if (text.include? '^') && text != '^'
|
494
488
|
unless text.ascii_only?
|
495
489
|
text = (text.gsub SmartApostropheRx, ?').gsub TypographicSymbolRx, TYPOGRAPHIC_SYMBOL_TO_MARKUP
|
data/spec/cli_spec.rb
CHANGED
@@ -69,6 +69,23 @@ describe Kramdown::AsciiDoc::Cli do
|
|
69
69
|
(expect (IO.read the_output_file).chomp).to eql 'Everything is going to be fine.'
|
70
70
|
end
|
71
71
|
|
72
|
+
it 'prevents computed output file from overwriting input file' do
|
73
|
+
the_source_file = output_file 'implicit-conflict.adoc'
|
74
|
+
IO.write the_source_file, 'No can do.'
|
75
|
+
expected = %(kramdoc: input and output file cannot be the same: #{the_source_file})
|
76
|
+
(expect subject.run %W(#{the_source_file})).to eql 1
|
77
|
+
(expect $stderr.string.chomp).to eql expected
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'prevents explicit output file from overwriting input file' do
|
81
|
+
the_source_file = output_file 'explicit-conflict.md'
|
82
|
+
the_output_file = the_source_file
|
83
|
+
IO.write the_source_file, 'No can do.'
|
84
|
+
expected = %(kramdoc: input and output file cannot be the same: #{the_source_file})
|
85
|
+
(expect subject.run %W(-o #{the_output_file} #{the_source_file})).to eql 1
|
86
|
+
(expect $stderr.string.chomp).to eql expected
|
87
|
+
end
|
88
|
+
|
72
89
|
it 'writes output to stdout when -o option equals -' do
|
73
90
|
the_source_file = scenario_file 'p/single-line.md'
|
74
91
|
(expect subject.run %W(-o - #{the_source_file})).to eql 0
|
@@ -100,6 +117,13 @@ describe Kramdown::AsciiDoc::Cli do
|
|
100
117
|
(expect $stdout.string.chomp).to eql %(= Heading\n\nBody content.)
|
101
118
|
end
|
102
119
|
|
120
|
+
it 'converts all newlines to line feed characters' do
|
121
|
+
the_source_file = output_file 'newlines.md'
|
122
|
+
IO.write the_source_file, %(\r\n\r\n# Document Title\r\n\r\nFirst paragraph.\r\n\r\nSecond paragraph.\r\n)
|
123
|
+
(expect subject.run %W(-o - #{the_source_file})).to eql 0
|
124
|
+
(expect $stdout.string.chomp).to eql %(= Document Title\n\nFirst paragraph.\n\nSecond paragraph.)
|
125
|
+
end
|
126
|
+
|
103
127
|
it 'processes front matter in source' do
|
104
128
|
the_source_file = output_file 'front-matter.md'
|
105
129
|
IO.write the_source_file, <<~EOS
|
@@ -136,6 +160,13 @@ describe Kramdown::AsciiDoc::Cli do
|
|
136
160
|
(expect $stdout.string.chomp).to eql '= Heading'
|
137
161
|
end
|
138
162
|
|
163
|
+
it 'removes directory prefix from image references specified by the --imagesdir option' do
|
164
|
+
the_source_file = scenario_file 'img/implicit-imagesdir.md'
|
165
|
+
expected = IO.read scenario_file 'img/implicit-imagesdir.adoc'
|
166
|
+
(expect subject.run %W(-o - --imagesdir=images #{the_source_file})).to eql 0
|
167
|
+
(expect $stdout.string).to eql expected
|
168
|
+
end
|
169
|
+
|
139
170
|
it 'wraps output as specified by the --wrap option' do
|
140
171
|
the_source_file = scenario_file 'wrap/ventilate.md'
|
141
172
|
expected = IO.read scenario_file 'wrap/ventilate.adoc'
|
@@ -8,6 +8,6 @@ Use an `+<!-- XML comment -->+` to disable or hide markup.
|
|
8
8
|
|
9
9
|
In AsciiDoc, `+{name}+` is the syntax for an attribute reference.
|
10
10
|
|
11
|
-
`pass:[{lang}++]` is simply better than `+{lang}+`.
|
11
|
+
`pass:c[{lang}++]` is simply better than `+{lang}+`.
|
12
12
|
|
13
13
|
Type `+©+` or `+(C)+` to enter a copyright symbol.
|
@@ -1 +1 @@
|
|
1
|
-
`C++` is
|
1
|
+
`C++` is a programming language. The name comes from the `++` operator, which increments the value of a variable by one.
|
@@ -1,2 +1 @@
|
|
1
|
-
:
|
2
|
-
implicit-imagesdir: images
|
1
|
+
:imagesdir: images
|
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.9
|
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-07-
|
11
|
+
date: 2018-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kramdown
|