kramdown-asciidoc 1.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.adoc +65 -0
- data/Gemfile +18 -3
- data/LICENSE.adoc +1 -1
- data/README.adoc +23 -28
- data/bin/kramdoc +2 -3
- data/kramdown-asciidoc.gemspec +7 -7
- data/lib/kramdoc.rb +2 -0
- data/lib/kramdown-asciidoc/api.rb +18 -8
- data/lib/kramdown-asciidoc/cli.rb +17 -11
- data/lib/kramdown-asciidoc/converter.rb +104 -50
- data/lib/kramdown-asciidoc/core_ext/regexp/is_match.rb +12 -4
- data/lib/kramdown-asciidoc/core_ext/yaml.rb +14 -0
- data/lib/kramdown-asciidoc/kramdown_ext/parser/base.rb +2 -0
- data/lib/kramdown-asciidoc/kramdown_ext/parser/html.rb +2 -0
- data/lib/kramdown-asciidoc/preprocessors.rb +12 -10
- data/lib/kramdown-asciidoc/version.rb +7 -3
- data/lib/kramdown-asciidoc/writer.rb +6 -3
- data/lib/kramdown-asciidoc.rb +3 -1
- metadata +20 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72f332cee31234bcb8b870e8216bb76062a85a66cbdaf05c8aa3a1829677564a
|
4
|
+
data.tar.gz: e80097972c53c804615741fa8e4b7fe7eb185d173dbb14242ff3c9d7ab1ddf9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b48abf36246bf94d96f6c5f8ff75962f90ae0ec216c947fd9052d865d0e30a3d2b1cbe50a5d84592c95f2dc830c5c3bd82a56f82410bac3c5c082546d3030407
|
7
|
+
data.tar.gz: 6654bbe89a6e3dea310df6df79cad09ab0cd911ca0c562d057827dc5751ab79a03ad8d1914dfe69b3346b01356c4e0fc46611beb19705573918fee7d77bc6006
|
data/CHANGELOG.adoc
CHANGED
@@ -5,6 +5,71 @@
|
|
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
|
+
== 2.1.0 (2022-07-04) - @mojavelinux
|
9
|
+
|
10
|
+
=== Added
|
11
|
+
|
12
|
+
* Add support for multi-paragraph admonitions (#72)
|
13
|
+
* Add support for GFM-style admonitions (#103)
|
14
|
+
* Convert checkbox at start of items in a checklist (#94)
|
15
|
+
* Allow diagram languages to be specified and convert matching fenced code blocks to diagram literal blocks (#76)
|
16
|
+
|
17
|
+
=== Fixed
|
18
|
+
|
19
|
+
* Separate adjacent delimited literal blocks
|
20
|
+
|
21
|
+
=== Changed
|
22
|
+
|
23
|
+
* Upgrade kramdown to 2.4.x
|
24
|
+
|
25
|
+
=== Details
|
26
|
+
|
27
|
+
{url-repo}/releases/tag/v2.1.0[git tag] | {url-repo}/compare/v2.0.1\...v2.1.0[full diff]
|
28
|
+
|
29
|
+
== 2.0.1 (2022-06-29) - @mojavelinux
|
30
|
+
|
31
|
+
=== Fixed
|
32
|
+
|
33
|
+
* Fix crash when fenced code block is empty and does not specify a language (#93)
|
34
|
+
* Fix crash when input contains `<script>` tag (#98)
|
35
|
+
* Fix crash if blockquote ends with nested block (#96)
|
36
|
+
* Handle text that maps to an abbreviation (#97)
|
37
|
+
* Handle front matter value that is parsed as a date or datetime (#95)
|
38
|
+
|
39
|
+
=== Changed
|
40
|
+
|
41
|
+
* Add JRuby 9.3 to CI matrix
|
42
|
+
|
43
|
+
=== Details
|
44
|
+
|
45
|
+
{url-repo}/releases/tag/v2.0.1[git tag] | {url-repo}/compare/v2.0.0\...v2.0.1[full diff]
|
46
|
+
|
47
|
+
== 2.0.0 (2021-07-11) - @mojavelinux
|
48
|
+
|
49
|
+
=== Added
|
50
|
+
|
51
|
+
* Add support for converting block LaTeX math to stem block
|
52
|
+
* Add support for converting span LaTeX math to inline stem macro
|
53
|
+
* Add basic support for footnotes (#74)
|
54
|
+
|
55
|
+
=== Fixed
|
56
|
+
|
57
|
+
* Use File.read instead of IO.read to suppress magic subprocess behavior
|
58
|
+
* Enable compatibility with Ruby 3 by declaring rexml as a runtime dependency (#84)
|
59
|
+
* Don't crash when converting list item that only contains spaces (#83)
|
60
|
+
|
61
|
+
=== Changed
|
62
|
+
|
63
|
+
* Upgrade kramdown to 2.3.x and declare kramdown-parser-gfm as runtime dependency (#85)
|
64
|
+
* Don't add source style to listing block when language is specified
|
65
|
+
* Switch CI to GitHub Actions
|
66
|
+
* Run test suite in CI environment on Windows and macOS
|
67
|
+
* Apply style rules to source code
|
68
|
+
|
69
|
+
=== Details
|
70
|
+
|
71
|
+
{uri-repo}/releases/tag/v2.0.0[git tag] | {uri-repo}/compare/v1.0.1\...v2.0.0[full diff]
|
72
|
+
|
8
73
|
== 1.0.1 (2018-11-28) - @mojavelinux
|
9
74
|
|
10
75
|
=== Fixed
|
data/Gemfile
CHANGED
@@ -1,8 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source 'https://rubygems.org'
|
2
4
|
|
3
5
|
gemspec
|
4
6
|
|
7
|
+
without = (Bundler.settings['WITHOUT'] || '').split ':'
|
8
|
+
|
5
9
|
group :docs do
|
6
|
-
gem '
|
7
|
-
gem '
|
8
|
-
end
|
10
|
+
gem 'asciidoctor', require: false
|
11
|
+
gem 'yard', require: false
|
12
|
+
end unless without.include? 'docs'
|
13
|
+
|
14
|
+
group :lint do
|
15
|
+
gem 'rubocop', '~> 1.28.0', require: false
|
16
|
+
gem 'rubocop-rake', '~> 0.6.0', require: false
|
17
|
+
gem 'rubocop-rspec', '~> 2.10.0', require: false
|
18
|
+
end unless without.include? 'lint'
|
19
|
+
|
20
|
+
group :coverage do
|
21
|
+
gem 'deep-cover-core', '~> 1.1.0', require: false
|
22
|
+
gem 'simplecov', '~> 0.21.0', require: false
|
23
|
+
end unless without.include? 'coverage'
|
data/LICENSE.adoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
.The MIT License
|
2
2
|
....
|
3
|
-
Copyright (C) 2016 OpenDevise Inc.
|
3
|
+
Copyright (C) 2016-2021 OpenDevise Inc. and the individual contributors to {project-name}.
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.adoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= {project-name} (Markdown to AsciiDoc)
|
2
2
|
Dan Allen <https://github.com/mojavelinux>
|
3
|
-
|
3
|
+
v2.1.0, 2022-07-04
|
4
4
|
// Aliases:
|
5
5
|
:project-name: Kramdown AsciiDoc
|
6
6
|
:project-handle: kramdown-asciidoc
|
@@ -19,28 +19,23 @@ ifdef::env-github[]
|
|
19
19
|
:tip-caption: :bulb:
|
20
20
|
endif::[]
|
21
21
|
// URIs:
|
22
|
-
:
|
23
|
-
:
|
24
|
-
:
|
25
|
-
:
|
26
|
-
:
|
27
|
-
:
|
28
|
-
:
|
29
|
-
:
|
30
|
-
:img-
|
31
|
-
:uri-ci-travis: https://travis-ci.org/asciidoctor/kramdown-asciidoc
|
32
|
-
:img-uri-ci-travis: https://img.shields.io/travis/asciidoctor/kramdown-asciidoc/master.svg
|
33
|
-
:uri-gem: https://rubygems.org/gems/kramdown-asciidoc
|
34
|
-
:img-uri-gem: https://img.shields.io/gem/v/kramdown-asciidoc.svg?label=gem
|
22
|
+
:url-repo: https://github.com/asciidoctor/kramdown-asciidoc
|
23
|
+
:url-asciidoc: https://asciidoctor.org/docs/what-is-asciidoc/#what-is-asciidoc
|
24
|
+
:url-asciidoctor: https://asciidoctor.org
|
25
|
+
:url-kramdown: https://kramdown.gettalong.org
|
26
|
+
:url-rvm: https://rvm.io
|
27
|
+
:url-rvm-install: https://rvm.io/rvm/install
|
28
|
+
:url-api-docs: https://www.rubydoc.info/github/asciidoctor/kramdown-asciidoc/master
|
29
|
+
:url-gem: https://rubygems.org/gems/kramdown-asciidoc
|
30
|
+
:img-url-gem: https://img.shields.io/gem/v/kramdown-asciidoc.svg?label=gem
|
35
31
|
|
36
32
|
ifdef::status[]
|
37
|
-
image:{img-
|
38
|
-
image:{
|
39
|
-
image:{img-uri-ci-appveyor}[Build Status (AppVeyor),link={uri-ci-appveyor}]
|
33
|
+
image:{img-url-gem}[Gem Version,link={url-gem}]
|
34
|
+
image:{url-repo}/workflows/CI/badge.svg[Build Status (GitHub Actions),link={url-repo}/actions?query=workflow%3ACI+branch%3Amain]
|
40
35
|
endif::[]
|
41
36
|
|
42
|
-
{
|
43
|
-
Notably, the converter generates modern AsciiDoc syntax suitable for use with {
|
37
|
+
{url-repo}[{project-name}] (gem: *{project-handle}*, command: `kramdoc`) is a {url-kramdown}[kramdown] extension for converting Markdown documents to {url-asciidoc}[AsciiDoc].
|
38
|
+
Notably, the converter generates modern AsciiDoc syntax suitable for use with {url-asciidoctor}[Asciidoctor].
|
44
39
|
|
45
40
|
== Prerequisites
|
46
41
|
|
@@ -51,7 +46,7 @@ To check whether you have Ruby installed, and which version, run the following c
|
|
51
46
|
|
52
47
|
$ ruby -v
|
53
48
|
|
54
|
-
If Ruby is not installed, you can install it using {
|
49
|
+
If Ruby is not installed, you can install it using {url-rvm}[RVM] (or, if you prefer, the package manager for your system).
|
55
50
|
We generally recommend using RVM because it allows you to install gems without requiring elevated privileges or messing with system libraries.
|
56
51
|
|
57
52
|
== Installation
|
@@ -91,7 +86,7 @@ To see all the options the `kramdoc` command accepts, pass the `-h` option to th
|
|
91
86
|
|
92
87
|
For example, you can inject attributes (key/value pairs) into the header of the AsciiDoc output document using the `-a` option.
|
93
88
|
|
94
|
-
$ kramdoc -a product-name="ACME Cloud" -a hide-
|
89
|
+
$ kramdoc -a product-name="ACME Cloud" -a hide-url-scheme sample.md
|
95
90
|
|
96
91
|
Another use for attributes is setting the shared images directory, which is covered in the next section.
|
97
92
|
|
@@ -164,7 +159,7 @@ If these values do not match the defaults in AsciiDoc, the `idprefix` and/or `id
|
|
164
159
|
|
165
160
|
== API
|
166
161
|
|
167
|
-
In additional to the command-line interface, {project-name} also provides a porcelain API (see {
|
162
|
+
In additional to the command-line interface, {project-name} also provides a porcelain API (see {url-api-docs}[API docs]).
|
168
163
|
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.
|
169
164
|
|
170
165
|
The API consists of two static methods in the Kramdoc module:
|
@@ -220,7 +215,7 @@ Kramdoc.convert markdown, to: 'result.adoc'
|
|
220
215
|
|
221
216
|
The input string is automatically converted to UTF-8.
|
222
217
|
|
223
|
-
For more information about the API, refer to the {
|
218
|
+
For more information about the API, refer to the {url-api-docs}[API documentation].
|
224
219
|
|
225
220
|
== Development
|
226
221
|
|
@@ -229,10 +224,10 @@ Follow the instructions below to learn how to clone the source and run the appli
|
|
229
224
|
|
230
225
|
=== Retrieve the source code
|
231
226
|
|
232
|
-
Simply copy the {
|
227
|
+
Simply copy the {url-repo}[GitHub repository URL] and pass it to the `git clone` command:
|
233
228
|
|
234
229
|
[subs=attributes+]
|
235
|
-
$ git clone {
|
230
|
+
$ git clone {url-repo}
|
236
231
|
|
237
232
|
Next, switch to the project directory:
|
238
233
|
|
@@ -241,9 +236,9 @@ Next, switch to the project directory:
|
|
241
236
|
|
242
237
|
=== Prepare RVM (optional)
|
243
238
|
|
244
|
-
We recommend using {
|
239
|
+
We recommend using {url-rvm}[RVM] when developing applications with Ruby.
|
245
240
|
We like RVM because it keeps the dependencies required by the project isolated from the rest of your system.
|
246
|
-
Follow the {
|
241
|
+
Follow the {url-rvm-install}[installation instructions] on the RVM site to setup RVM and install Ruby.
|
247
242
|
|
248
243
|
Once you have RVM setup, switch to the RVM-managed version of Ruby recommended by the project using this command:
|
249
244
|
|
@@ -372,7 +367,7 @@ To avoid having to do this, or make the `kramdoc` command available from anywher
|
|
372
367
|
|
373
368
|
== Copyright
|
374
369
|
|
375
|
-
Copyright (C) 2016-
|
370
|
+
Copyright (C) 2016-2021 OpenDevise Inc. and the individual contributors to {project-name}.
|
376
371
|
Free use of this software is granted under the terms of the MIT License.
|
377
372
|
|
378
373
|
See the link:LICENSE.adoc[LICENSE] file for details.
|
data/bin/kramdoc
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
kramdown_asciidoc = File.
|
4
|
-
if File.exist? kramdown_asciidoc
|
4
|
+
if File.file? (kramdown_asciidoc = File.join (File.dirname __dir__), 'lib/kramdown-asciidoc.rb')
|
5
5
|
require kramdown_asciidoc
|
6
6
|
else
|
7
7
|
require 'kramdown-asciidoc'
|
8
8
|
end
|
9
|
-
|
10
9
|
require 'kramdown-asciidoc/cli'
|
11
10
|
|
12
11
|
exit Kramdown::AsciiDoc::Cli.run
|
data/kramdown-asciidoc.gemspec
CHANGED
@@ -25,16 +25,16 @@ Gem::Specification.new do |s|
|
|
25
25
|
rescue
|
26
26
|
Dir['**/*']
|
27
27
|
end
|
28
|
-
#s.files = files.grep %r/^(?:lib\/.+|Gemfile|Rakefile|(?:CHANGELOG|CONTRIBUTING|LICENSE|README)\.adoc|#{s.name}\.gemspec)$/
|
29
|
-
#s.test_files = files.grep %r/^(?:spec\/.+)$/
|
30
28
|
s.files = files.grep %r/^(?:lib\/.+|Gemfile|(?:CHANGELOG|LICENSE|README)\.adoc|#{s.name}\.gemspec)$/
|
29
|
+
#s.test_files = files.grep %r/^spec\/./
|
31
30
|
s.executables = ['kramdoc']
|
32
31
|
|
33
32
|
s.require_paths = ['lib']
|
34
33
|
|
35
|
-
s.add_runtime_dependency 'kramdown', '~>
|
36
|
-
s.
|
37
|
-
s.
|
38
|
-
|
39
|
-
s.add_development_dependency '
|
34
|
+
s.add_runtime_dependency 'kramdown', '~> 2.4.0'
|
35
|
+
s.add_runtime_dependency 'rexml', '~> 3.2.0'
|
36
|
+
s.add_runtime_dependency 'kramdown-parser-gfm', '~> 1.1.0'
|
37
|
+
|
38
|
+
s.add_development_dependency 'rake', '~> 13.0.0'
|
39
|
+
s.add_development_dependency 'rspec', '~> 3.11.0'
|
40
40
|
end
|
data/lib/kramdoc.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kramdown
|
4
|
+
module AsciiDoc
|
2
5
|
DEFAULT_PARSER_OPTS = {
|
3
6
|
auto_ids: false,
|
4
7
|
hard_wrap: false,
|
@@ -9,7 +12,7 @@ module Kramdown; module AsciiDoc
|
|
9
12
|
DEFAULT_PREPROCESSORS = [
|
10
13
|
(Preprocessors.method :extract_front_matter),
|
11
14
|
(Preprocessors.method :replace_toc),
|
12
|
-
(Preprocessors.method :
|
15
|
+
(Preprocessors.method :trim_before_leading_comment),
|
13
16
|
]
|
14
17
|
|
15
18
|
# Converts a Markdown string to an AsciiDoc string and either returns the result or writes it to a file.
|
@@ -24,7 +27,10 @@ module Kramdown; module AsciiDoc
|
|
24
27
|
# @option opts [Symbol] :wrap (:preserve) the line wrapping behavior to apply (:preserve, :ventilate, or :none).
|
25
28
|
# @option opts [Integer] :heading_offset (0) the heading offset to apply to heading levels.
|
26
29
|
# @option opts [Boolean] :auto_links (true) whether to allow raw URLs to be recognized as links.
|
27
|
-
# @option opts [Hash] :attributes ({}) AsciiDoc attributes to add to
|
30
|
+
# @option opts [Hash] :attributes ({}) additional AsciiDoc attributes to add to header of output document; reserved
|
31
|
+
# attributes, like stem, may be overridden; some attributes may impact conversion, such as idprefix and idseparator
|
32
|
+
# @option opts [String] :imagesdir (nil) the prefix to remove from image references found in the Markdown document;
|
33
|
+
# if not specified, the value of the imagesdir attribute is used
|
28
34
|
# @option opts [Symbol] :encode (true) whether to reencode the source to UTF-8.
|
29
35
|
# @option opts [Array<Proc>] :preprocessors ([]) a list of preprocessors functions to execute on the cleaned Markdown source.
|
30
36
|
# @option opts [Array<Proc>] :postprocessors ([]) a list of functions through which to run the output document.
|
@@ -79,7 +85,10 @@ module Kramdown; module AsciiDoc
|
|
79
85
|
# @option opts [Symbol] :wrap (:preserve) the line wrapping behavior to apply (:preserve, :ventilate, or :none).
|
80
86
|
# @option opts [Integer] :heading_offset (0) the heading offset to apply to heading levels.
|
81
87
|
# @option opts [Boolean] :auto_links (true) whether to allow raw URLs to be recognized as links.
|
82
|
-
# @option opts [Hash] :attributes ({}) AsciiDoc attributes to add to
|
88
|
+
# @option opts [Hash] :attributes ({}) additional AsciiDoc attributes to add to header of output document; reserved
|
89
|
+
# attributes, like stem, may be overridden; some attributes may impact conversion, such as idprefix and idseparator
|
90
|
+
# @option opts [String] :imagesdir (nil) the prefix to remove from image references found in the Markdown document;
|
91
|
+
# if not specified, the value of the imagesdir attribute is used
|
83
92
|
# @option opts [Array<Proc>] :preprocessors ([]) a list of preprocessors functions to execute on the cleaned Markdown source.
|
84
93
|
# @option opts [Array<Proc>] :postprocessors ([]) a list of functions through which to run the output document.
|
85
94
|
# @option opts [Proc] :postprocess (nil) a function through which to run the output document (if :postprocessors is falsy).
|
@@ -92,7 +101,7 @@ module Kramdown; module AsciiDoc
|
|
92
101
|
markdown_file = markdown_file.path
|
93
102
|
encode = true
|
94
103
|
else
|
95
|
-
markdown = ::
|
104
|
+
markdown = ::File.read markdown_file, mode: 'r:UTF-8', newline: :universal
|
96
105
|
encode = false
|
97
106
|
end
|
98
107
|
if (to = opts[:to])
|
@@ -104,10 +113,11 @@ module Kramdown; module AsciiDoc
|
|
104
113
|
convert markdown, (opts.merge to: to, encode: encode)
|
105
114
|
end
|
106
115
|
|
107
|
-
private
|
108
|
-
|
109
116
|
CR = ?\r
|
110
117
|
LF = ?\n
|
111
118
|
TAB = ?\t
|
112
119
|
UTF_8 = ::Encoding::UTF_8
|
113
|
-
|
120
|
+
|
121
|
+
private_constant :CR, :LF, :TAB, :UTF_8
|
122
|
+
end
|
123
|
+
end
|
@@ -1,18 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'optparse'
|
2
4
|
require 'pathname'
|
3
5
|
|
4
|
-
module Kramdown
|
6
|
+
module Kramdown
|
7
|
+
module AsciiDoc
|
5
8
|
autoload :VERSION, (::File.join __dir__, 'version.rb')
|
6
9
|
class Cli
|
7
10
|
def parse args
|
8
11
|
options = {
|
9
|
-
attributes: {}
|
12
|
+
attributes: {},
|
10
13
|
}
|
11
14
|
|
12
15
|
opt_parser = ::OptionParser.new do |opts|
|
13
16
|
opts.program_name = 'kramdoc'
|
14
17
|
opts.banner = <<~EOS
|
15
|
-
Usage: #{opts.program_name} [OPTION]... FILE
|
18
|
+
Usage: #{opts.program_name} [OPTION]... FILE
|
16
19
|
|
17
20
|
Converts Markdown to AsciiDoc.
|
18
21
|
|
@@ -28,10 +31,14 @@ module Kramdown; module AsciiDoc
|
|
28
31
|
|
29
32
|
opts.on '-a KEY[=VALUE]', '--attribute=KEY[=VALUE]', 'Set an attribute in the AsciiDoc document header (accepts: key, key!, or key=value)' do |attr|
|
30
33
|
key, val = attr.split '=', 2
|
31
|
-
val
|
34
|
+
val ||= ''
|
32
35
|
options[:attributes][key] = val
|
33
36
|
end
|
34
37
|
|
38
|
+
opts.on '--diagram-languages=VALUES', 'Specify source languages to treat as diagrams (default: plantuml,mermaid)' do |names|
|
39
|
+
options[:diagram_languages] = names.split ','
|
40
|
+
end
|
41
|
+
|
35
42
|
opts.on '--wrap=preserve|none|ventilate', [:none, :preserve, :ventilate], 'Set how lines are wrapped in the AsciiDoc document (default: preserve)' do |wrap|
|
36
43
|
options[:wrap] = wrap
|
37
44
|
end
|
@@ -84,10 +91,8 @@ module Kramdown; module AsciiDoc
|
|
84
91
|
if args.empty?
|
85
92
|
opt_parser.warn 'Please specify a Markdown file to convert.'
|
86
93
|
$stdout.write opt_parser.help
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
if args.size == 1
|
94
|
+
1
|
95
|
+
elsif args.size == 1
|
91
96
|
options[:input_file] = args[0]
|
92
97
|
[0, options]
|
93
98
|
else
|
@@ -117,9 +122,10 @@ module Kramdown; module AsciiDoc
|
|
117
122
|
::Kramdoc.convert_file input_file, options
|
118
123
|
end
|
119
124
|
0
|
120
|
-
rescue ::IOError
|
121
|
-
$stderr.write %(kramdoc: #{
|
125
|
+
rescue ::IOError
|
126
|
+
$stderr.write %(kramdoc: #{$!.message}\n)
|
122
127
|
1
|
123
128
|
end
|
124
129
|
end
|
125
|
-
end
|
130
|
+
end
|
131
|
+
end
|
@@ -1,5 +1,7 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kramdown
|
4
|
+
module AsciiDoc
|
3
5
|
class Converter < ::Kramdown::Converter::Base
|
4
6
|
using CoreExt
|
5
7
|
|
@@ -45,12 +47,12 @@ module Kramdown; module AsciiDoc
|
|
45
47
|
InvalidIdCharsRx = /&(?:[a-z][a-z]+\d{0,2}|#\d\d\d{0,4}|#x[\da-f][\da-f][\da-f]{0,3});|[^ \p{Word}\-.]+?/
|
46
48
|
ListMarkerRx = /^[ \t]*(?:(?:-|\*\*{0,4}|\.\.{0,4}|\d+\.|[a-zA-Z]\.|[IVXivx]+\))[ \t]|.*?(?::::{0,2}|;;)(?:$|[ \t]))/
|
47
49
|
MenuRefRx = /^([\p{Word}&].*?)\s>\s([\p{Word}&].*(?:\s>\s|$))+/
|
48
|
-
ReplaceableTextRx =
|
50
|
+
ReplaceableTextRx = %r([-=]>|<[-=]| -- |\p{Word}--\p{Word}|\*\*|\.\.\.|&\S+;|\{\p{Word}[\p{Word}-]*\}|(?:https?|ftp)://\p{Word}|\((?:C|R|TM)\))
|
49
51
|
SmartApostropheRx = /\b’\b/
|
50
|
-
StopPunctRx = /(?<=\S[.;]
|
52
|
+
StopPunctRx = /(?<=\S[.;]|.[?!])\p{Blank}+/
|
51
53
|
TrailingSpaceRx = / +$/
|
52
54
|
TypographicSymbolRx = /[“”‘’—–…]/
|
53
|
-
UriSchemeRx =
|
55
|
+
UriSchemeRx = %r((?:https?|ftp)://\p{Word})
|
54
56
|
WordishRx = /[\p{Word};:<>&]/
|
55
57
|
WordRx = /\p{Word}/
|
56
58
|
XmlCommentRx = /\A<!--(.*)-->\Z/m
|
@@ -67,13 +69,13 @@ module Kramdown; module AsciiDoc
|
|
67
69
|
@lazy_ids = opts[:lazy_ids]
|
68
70
|
if @auto_ids || @lazy_ids
|
69
71
|
if @auto_ids
|
70
|
-
|
72
|
+
@id_pre = opts[:auto_id_prefix]
|
73
|
+
sep = opts[:auto_id_separator] || '-'
|
74
|
+
if @lazy_ids
|
71
75
|
# NOTE only need to set idprefix when lazy_ids is set since otherwise all IDs are explicit
|
72
|
-
@attributes['idprefix'] = @id_pre
|
73
|
-
end
|
74
|
-
unless (sep = opts[:auto_id_separator] || '-') == '_'
|
76
|
+
@attributes['idprefix'] = @id_pre unless @id_pre == '_'
|
75
77
|
# NOTE only need to set idseparator when lazy_ids is set since otherwise all IDs are explicit
|
76
|
-
@attributes['idseparator'] = sep
|
78
|
+
@attributes['idseparator'] = sep unless sep == '_'
|
77
79
|
end
|
78
80
|
else
|
79
81
|
@id_pre = @attributes['idprefix'] || '_'
|
@@ -88,7 +90,9 @@ module Kramdown; module AsciiDoc
|
|
88
90
|
@id_sep_replace = sep_replace
|
89
91
|
end
|
90
92
|
@ids_seen = {}
|
93
|
+
@footnote_ids = ::Set.new
|
91
94
|
@auto_links = opts.fetch :auto_links, true
|
95
|
+
@diagram_languages = opts[:diagram_languages] || %w(plantuml mermaid)
|
92
96
|
@heading_offset = opts[:heading_offset] || 0
|
93
97
|
@imagesdir = opts[:imagesdir] || @attributes['imagesdir']
|
94
98
|
@wrap = opts[:wrap] || :preserve
|
@@ -166,8 +170,7 @@ module Kramdown; module AsciiDoc
|
|
166
170
|
# Kramdown incorrectly uses the term header for headings
|
167
171
|
alias convert_header convert_heading
|
168
172
|
|
169
|
-
def convert_blank el, opts
|
170
|
-
end
|
173
|
+
def convert_blank el, opts; end
|
171
174
|
|
172
175
|
def convert_p el, opts
|
173
176
|
(writer = opts[:writer]).start_block
|
@@ -183,7 +186,8 @@ module Kramdown; module AsciiDoc
|
|
183
186
|
elsif (child_i.type == :strong || child_i.type == :em) &&
|
184
187
|
(marker_el = child_i.children[0]) && ((marker = ADMON_FORMATTED_MARKERS[marker_el.value]) ||
|
185
188
|
((marker = ADMON_LABELS[marker_el.value]) && (child_ii = to_element children[1]).type == :text &&
|
186
|
-
((child_ii_text = child_ii.value).start_with? ': ')
|
189
|
+
(((child_ii_text = child_ii.value).start_with? ': ') ||
|
190
|
+
(opts[:parent].type == :blockquote && (child_ii_text.start_with? ?\n)))))
|
187
191
|
children = children.drop 1
|
188
192
|
children[0] = clone child_ii, value: (child_ii_text.slice 1, child_ii_text.length) if child_ii
|
189
193
|
# Q: should we only rstrip?
|
@@ -201,10 +205,18 @@ module Kramdown; module AsciiDoc
|
|
201
205
|
(writer = opts[:writer]).start_block
|
202
206
|
traverse el, (opts.merge writer: (block_writer = Writer.new), blockquote_depth: (depth = opts[:blockquote_depth] || 0) + 1)
|
203
207
|
contents = block_writer.body
|
204
|
-
if contents[0].start_with?(*ADMON_MARKERS_ASCIIDOC)
|
205
|
-
|
208
|
+
if contents[0].start_with?(*ADMON_MARKERS_ASCIIDOC)
|
209
|
+
if contents.include? ''
|
210
|
+
style, _, contents[0] = contents[0].partition ': '
|
211
|
+
writer.add_line %([#{style}])
|
212
|
+
writer.start_delimited_block '='
|
213
|
+
writer.add_lines contents
|
214
|
+
writer.end_delimited_block
|
215
|
+
else
|
216
|
+
writer.add_lines contents
|
217
|
+
end
|
206
218
|
else
|
207
|
-
if contents.size > 1 && (contents[-1].start_with? '-- ')
|
219
|
+
if contents.size > 1 && ::String === (last_line = contents[-1]) && (last_line.start_with? '-- ')
|
208
220
|
attribution = (attribution_line = contents.pop).slice 3, attribution_line.length
|
209
221
|
writer.add_line %([,#{attribution}])
|
210
222
|
# NOTE there will be at least one non-blank line, but coerce .to_s just to be safe
|
@@ -222,29 +234,38 @@ module Kramdown; module AsciiDoc
|
|
222
234
|
def convert_codeblock el, opts
|
223
235
|
writer = opts[:writer]
|
224
236
|
# NOTE hack to down-convert level-5 heading to block title
|
225
|
-
if (current_line = writer.current_line) &&
|
237
|
+
if (current_line = writer.current_line) &&
|
238
|
+
((current_line.start_with? '.') ? (current_line == '....' || (current_line.start_with? '. ')) : true)
|
226
239
|
writer.start_block
|
227
240
|
end
|
228
241
|
lines = el.value.rstrip.split LF
|
242
|
+
first_line = lines[0]
|
229
243
|
if (lang = el.attr['class'])
|
230
244
|
# NOTE Kramdown always prefixes class with language-
|
231
245
|
# TODO remap lang if requested
|
232
|
-
|
233
|
-
|
234
|
-
|
246
|
+
lang = lang.slice 9, lang.length
|
247
|
+
if @diagram_languages.include? lang
|
248
|
+
diagram = true
|
249
|
+
writer.add_line %([#{lang}])
|
250
|
+
else
|
251
|
+
writer.add_line %([,#{lang}])
|
252
|
+
end
|
253
|
+
elsif (prompt = first_line && (first_line.start_with? '$ '))
|
254
|
+
writer.add_line %([,#{lang = 'console'}]) if lines.include? ''
|
235
255
|
end
|
236
256
|
if lang || (el.options[:fenced] && !prompt)
|
237
|
-
|
257
|
+
delimiter = diagram ? '....' : '----'
|
258
|
+
writer.add_line delimiter
|
238
259
|
writer.add_lines lines
|
239
|
-
writer.add_line
|
240
|
-
elsif !prompt && ((lines.include? '') || (ListMarkerRx.match?
|
260
|
+
writer.add_line delimiter
|
261
|
+
elsif !prompt && ((lines.include? '') || (first_line && (ListMarkerRx.match? first_line)))
|
241
262
|
writer.add_line '....'
|
242
263
|
writer.add_lines lines
|
243
264
|
writer.add_line '....'
|
244
265
|
else
|
245
266
|
# NOTE clear the list continuation as it isn't required
|
246
267
|
writer.clear_line if writer.current_line == '+'
|
247
|
-
writer.add_line
|
268
|
+
writer.add_line(lines.map {|l| %( #{l}) })
|
248
269
|
end
|
249
270
|
end
|
250
271
|
|
@@ -263,8 +284,8 @@ module Kramdown; module AsciiDoc
|
|
263
284
|
block = true
|
264
285
|
end
|
265
286
|
macro_attrs = [nil]
|
266
|
-
if (alt_text = el.attr['alt'])
|
267
|
-
macro_attrs[0] = alt_text
|
287
|
+
if (alt_text = el.attr['alt']) && !alt_text.empty?
|
288
|
+
macro_attrs[0] = alt_text
|
268
289
|
end
|
269
290
|
if (width = el.attr['width'])
|
270
291
|
macro_attrs << width
|
@@ -293,7 +314,7 @@ module Kramdown; module AsciiDoc
|
|
293
314
|
end
|
294
315
|
end
|
295
316
|
|
296
|
-
def
|
317
|
+
def _convert_list el, opts
|
297
318
|
kin = el.type == :dl ? :dlist : :list
|
298
319
|
(writer = opts[:writer]).start_list (parent = opts[:parent]).type == :dd || parent.options[:compound], kin
|
299
320
|
traverse el, opts
|
@@ -301,15 +322,16 @@ module Kramdown; module AsciiDoc
|
|
301
322
|
writer.add_blank_line if writer.in_list? && opts[:next]
|
302
323
|
end
|
303
324
|
|
304
|
-
alias
|
305
|
-
alias
|
325
|
+
alias convert_ul _convert_list
|
326
|
+
alias convert_ol _convert_list
|
327
|
+
alias convert_dl _convert_list
|
306
328
|
|
307
329
|
def convert_li el, opts
|
308
330
|
writer = opts[:writer]
|
309
331
|
writer.add_blank_line if (prev = opts[:prev]) && prev.options[:compound]
|
310
332
|
marker = opts[:parent].type == :ol ? '.' : '*'
|
311
333
|
indent = (level = writer.list_level) - 1
|
312
|
-
if (children = el.children)[0].type == :p
|
334
|
+
if !(children = el.children).empty? && children[0].type == :p
|
313
335
|
primary, remaining = [(children = children.dup).shift, children]
|
314
336
|
primary_lines = compose_text [primary], parent: el, strip: true, split: true, wrap: @wrap
|
315
337
|
else
|
@@ -320,7 +342,7 @@ module Kramdown; module AsciiDoc
|
|
320
342
|
writer.add_lines primary_lines
|
321
343
|
unless remaining.empty?
|
322
344
|
if remaining.find {|n| (type = n.type) == :blank ? nil : ((BLOCK_TYPES.include? type) ? true : break) }
|
323
|
-
el.options[:compound] = true
|
345
|
+
el.options[:compound] = true
|
324
346
|
end
|
325
347
|
traverse remaining, (opts.merge parent: el)
|
326
348
|
end
|
@@ -402,7 +424,7 @@ module Kramdown; module AsciiDoc
|
|
402
424
|
opts[:writer].add_lines table_buffer
|
403
425
|
end
|
404
426
|
|
405
|
-
def convert_hr
|
427
|
+
def convert_hr _el, opts
|
406
428
|
(writer = opts[:writer]).start_block
|
407
429
|
writer.add_line '\'\'\''
|
408
430
|
end
|
@@ -411,11 +433,11 @@ module Kramdown; module AsciiDoc
|
|
411
433
|
if (url = el.attr['href']).start_with? '#'
|
412
434
|
opts[:writer].append %(<<#{url.slice 1, url.length},#{compose_text el, strip: true}>>)
|
413
435
|
elsif url.start_with? 'https://', 'http://'
|
414
|
-
if (children = el.children).size == 1 && (child_i =
|
436
|
+
if (children = el.children).size == 1 && (child_i = children[0]).type == :img
|
415
437
|
convert_img child_i, parent: opts[:parent], index: 0, url: url, writer: opts[:writer]
|
416
438
|
else
|
417
439
|
bare = ((text = compose_text el, strip: true).chomp '/') == (url.chomp '/')
|
418
|
-
url = url.gsub '__', '%5F%5F' if
|
440
|
+
url = url.gsub '__', '%5F%5F' if url.include? '__'
|
419
441
|
opts[:writer].append bare ? url : %(#{url}[#{text.gsub ']', '\]'}])
|
420
442
|
end
|
421
443
|
elsif url.end_with? '.md'
|
@@ -425,7 +447,7 @@ module Kramdown; module AsciiDoc
|
|
425
447
|
else
|
426
448
|
opts[:writer].append %(link:#{url}[#{(compose_text el, strip: true).gsub ']', '\]'}])
|
427
449
|
end
|
428
|
-
end
|
450
|
+
end
|
429
451
|
|
430
452
|
def convert_codespan el, opts
|
431
453
|
attrlist, mark = '', '`'
|
@@ -446,9 +468,10 @@ module Kramdown; module AsciiDoc
|
|
446
468
|
text = el.value
|
447
469
|
pass = (replaceable? text) ? :shorthand : nil
|
448
470
|
pass = :macro if text.include? '++'
|
449
|
-
|
471
|
+
case pass
|
472
|
+
when :shorthand
|
450
473
|
opts[:writer].append %(#{mark}+#{text}+#{mark})
|
451
|
-
|
474
|
+
when :macro
|
452
475
|
opts[:writer].append %(#{mark}pass:c[#{text}]#{mark})
|
453
476
|
else
|
454
477
|
opts[:writer].append %(#{attrlist}#{mark}#{text}#{mark})
|
@@ -483,13 +506,17 @@ module Kramdown; module AsciiDoc
|
|
483
506
|
next_el && next_el.type == :text && (WordRx.match? next_el.value.chr)
|
484
507
|
end
|
485
508
|
|
509
|
+
def convert_abbreviation el, opts
|
510
|
+
opts[:writer].append el.value
|
511
|
+
end
|
512
|
+
|
486
513
|
def convert_text el, opts
|
487
514
|
text = escape_replacements el.value
|
488
515
|
if text.include? '++'
|
489
516
|
@attributes['pp'] = '{plus}{plus}'
|
490
517
|
text = text.gsub '++', '{pp}'
|
491
518
|
end
|
492
|
-
if (
|
519
|
+
if (writer = opts[:writer]).current_line.to_s.empty?
|
493
520
|
writer.append text.lstrip
|
494
521
|
else
|
495
522
|
writer.append text
|
@@ -519,15 +546,19 @@ module Kramdown; module AsciiDoc
|
|
519
546
|
else
|
520
547
|
writer.append %(#{(writer.current_line.end_with? ' ') ? '' : ' '}+)
|
521
548
|
end
|
522
|
-
if el.options[:html_tag]
|
523
|
-
writer.add_blank_line unless (next_el = to_element opts[:next]).type == :text && (next_el.value.start_with? LF)
|
524
|
-
end
|
549
|
+
writer.add_blank_line if el.options[:html_tag] && ((next_el = to_element opts[:next]).type != :text || !(next_el.value.start_with? LF))
|
525
550
|
end
|
526
551
|
|
527
552
|
def convert_entity el, opts
|
528
553
|
opts[:writer].append RESOLVE_ENTITY_TABLE[el.value.code_point] || el.options[:original]
|
529
554
|
end
|
530
555
|
|
556
|
+
def convert_footnote el, opts
|
557
|
+
id = el.options[:name]
|
558
|
+
composed_text = (@footnote_ids.add? id) ? ((compose_text el.value).gsub ']', '\]') : ''
|
559
|
+
opts[:writer].append %(footnote:#{id}[#{composed_text}])
|
560
|
+
end
|
561
|
+
|
531
562
|
def convert_smart_quote el, opts
|
532
563
|
opts[:writer].append SMART_QUOTE_ENTITY_TO_MARKUP[el.value]
|
533
564
|
end
|
@@ -538,7 +569,11 @@ module Kramdown; module AsciiDoc
|
|
538
569
|
end
|
539
570
|
|
540
571
|
def convert_html_element el, opts
|
541
|
-
if (tag = el.value) == '
|
572
|
+
if (tag = el.value) == 'script'
|
573
|
+
opts[:writer].start_block
|
574
|
+
opts[:writer].add_lines ['++++', '<script>', el.children[0].value.strip, '</script>', '++++']
|
575
|
+
return
|
576
|
+
elsif tag == 'div' && (child_i = el.children[0]) && child_i.options[:transparent] && (child_i_i = child_i.children[0])
|
542
577
|
if child_i_i.value == 'span' && ((role = el.attr['class'].to_s).start_with? 'note') && child_i_i.attr['class'] == 'notetitle'
|
543
578
|
marker = ADMON_FORMATTED_MARKERS[(to_element child_i_i.children[0]).value] || 'Note'
|
544
579
|
lines = compose_text (child_i.children.drop 1), parent: child_i, strip: true, split: true, wrap: @wrap
|
@@ -568,8 +603,12 @@ module Kramdown; module AsciiDoc
|
|
568
603
|
when 'sub'
|
569
604
|
opts[:writer].append %(~#{contents}~)
|
570
605
|
else
|
571
|
-
|
572
|
-
|
606
|
+
if tag == 'input' && el.attr['type'] == 'checkbox' && el.attr['class'] == 'task-list-item-checkbox'
|
607
|
+
opts[:writer].append %([#{el.attr['checked'] ? 'x' : ' '}] )
|
608
|
+
else
|
609
|
+
attrs = (attrs = el.attr).empty? ? '' : attrs.map {|k, v| %( #{k}="#{v}") }.join
|
610
|
+
opts[:writer].append %(+++<#{tag}#{attrs}>+++#{contents}+++</#{tag}>+++)
|
611
|
+
end
|
573
612
|
end
|
574
613
|
end
|
575
614
|
|
@@ -583,7 +622,7 @@ module Kramdown; module AsciiDoc
|
|
583
622
|
lines = val.split LF
|
584
623
|
end
|
585
624
|
#siblings = (parent = opts[:parent]) ? parent.children : []
|
586
|
-
if
|
625
|
+
if el.options[:category] == :block # || (!opts[:result][-1] && siblings[-1] == el)
|
587
626
|
writer.start_block
|
588
627
|
if lines.empty?
|
589
628
|
writer.add_line '//'
|
@@ -611,10 +650,24 @@ module Kramdown; module AsciiDoc
|
|
611
650
|
end
|
612
651
|
end
|
613
652
|
|
653
|
+
def convert_math el, opts
|
654
|
+
writer = opts[:writer]
|
655
|
+
@attributes['stem'] = 'latexmath'
|
656
|
+
if el.options[:category] == :span
|
657
|
+
writer.append %(stem:[#{el.value.gsub ']', '\]'}])
|
658
|
+
else
|
659
|
+
writer.start_block
|
660
|
+
writer.add_line '[stem]'
|
661
|
+
writer.add_line '++++'
|
662
|
+
writer.add_lines el.value.rstrip.split LF
|
663
|
+
writer.add_line '++++'
|
664
|
+
end
|
665
|
+
end
|
666
|
+
|
614
667
|
private
|
615
668
|
|
616
669
|
def extract_prologue el, opts
|
617
|
-
if (
|
670
|
+
if (to_element (children = el.children)[0]).type == :xml_comment
|
618
671
|
(prologue_el = el.dup).children = children.take_while {|child| child.type == :xml_comment || child.type == :blank }
|
619
672
|
(el = el.dup).children = children.drop prologue_el.children.size
|
620
673
|
traverse prologue_el, (opts.merge writer: (prologue_writer = Writer.new))
|
@@ -692,9 +745,9 @@ module Kramdown; module AsciiDoc
|
|
692
745
|
end
|
693
746
|
end
|
694
747
|
if ventilate
|
695
|
-
result.map
|
696
|
-
(
|
697
|
-
|
748
|
+
result.map do |l|
|
749
|
+
(l.start_with? '//') || !(STOP_PUNCTUATION.any? {|punc| l.include? punc }) ? l : (l.gsub StopPunctRx, LF)
|
750
|
+
end.join LF
|
698
751
|
else
|
699
752
|
result.join LF
|
700
753
|
end
|
@@ -741,4 +794,5 @@ module Kramdown; module AsciiDoc
|
|
741
794
|
@ids_seen[id] = idx || UNIQUE_ID_START_INDEX
|
742
795
|
end
|
743
796
|
end
|
744
|
-
end
|
797
|
+
end
|
798
|
+
end
|
@@ -1,5 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kramdown
|
4
|
+
module AsciiDoc
|
5
|
+
module CoreExt
|
6
|
+
refine Regexp do
|
7
|
+
# rubocop:disable Style/Alias
|
8
|
+
alias match? === unless method_defined? :match? # nocov
|
9
|
+
# rubocop:enable Style/Alias
|
10
|
+
end
|
4
11
|
end
|
5
|
-
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
autoload :Date, 'time'
|
6
|
+
autoload :Time, 'time'
|
7
|
+
|
8
|
+
unless (YAML.method :safe_load).parameters.include? [:key, :aliases]
|
9
|
+
YAML.singleton_class.prepend (Module.new do
|
10
|
+
def safe_load yaml, permitted_classes: [], permitted_symbols: [], aliases: false, filename: nil
|
11
|
+
super yaml, permitted_classes, permitted_symbols, aliases, filename
|
12
|
+
end
|
13
|
+
end)
|
14
|
+
end
|
@@ -1,4 +1,7 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kramdown
|
4
|
+
module AsciiDoc
|
2
5
|
module Preprocessors
|
3
6
|
# Skims off the front matter from the top of the Markdown source and store the data in the provided attributes Hash.
|
4
7
|
#
|
@@ -15,7 +18,7 @@ module Kramdown; module AsciiDoc
|
|
15
18
|
end
|
16
19
|
return source unless line && line.chomp == '---' && !(front_matter.include? ?\n)
|
17
20
|
lines.shift while (line = lines[0]) && line == ?\n
|
18
|
-
(::YAML.
|
21
|
+
(::YAML.safe_load front_matter.join, permitted_classes: [::Date, ::Time]).each do |key, val|
|
19
22
|
if key == 'layout'
|
20
23
|
attributes['page-layout'] = val unless val == 'default'
|
21
24
|
else
|
@@ -43,22 +46,21 @@ module Kramdown; module AsciiDoc
|
|
43
46
|
end
|
44
47
|
end
|
45
48
|
|
46
|
-
#
|
49
|
+
# Trims space characters that precede a leading XML comment in the Markdown source.
|
47
50
|
#
|
48
51
|
# @param markdown [String] the Markdown source to process.
|
49
52
|
# @param attributes [Hash] a map of AsciiDoc attributes to set on the output document.
|
50
53
|
#
|
51
|
-
# @return [String] the Markdown source with
|
52
|
-
def self.
|
54
|
+
# @return [String] the Markdown source with the space characters preceding a leading XML comment removed.
|
55
|
+
def self.trim_before_leading_comment markdown, _attributes
|
53
56
|
(markdown.start_with? ' ', TAB) && (markdown.lstrip.start_with? '<!--') ? markdown.lstrip : markdown
|
54
57
|
end
|
55
58
|
|
56
|
-
private
|
57
|
-
|
58
59
|
TAB = ?\t
|
59
|
-
|
60
60
|
TocDirectiveTip = '<!-- TOC '
|
61
|
+
TocDirectiveRx = %r(^<!-- TOC .*<!-- /TOC -->)m
|
61
62
|
|
62
|
-
|
63
|
+
private_constant :TAB, :TocDirectiveTip, :TocDirectiveRx
|
63
64
|
end
|
64
|
-
end
|
65
|
+
end
|
66
|
+
end
|
@@ -1,4 +1,7 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kramdown
|
4
|
+
module AsciiDoc
|
2
5
|
class Writer
|
3
6
|
LF = ?\n
|
4
7
|
|
@@ -48,7 +51,6 @@ module Kramdown; module AsciiDoc
|
|
48
51
|
parent_body, @block_delimiter, @block_separator, @list_level = @nesting_stack.pop
|
49
52
|
@body = (parent_body + @body) << @block_delimiter
|
50
53
|
@block_delimiter = nil
|
51
|
-
nil
|
52
54
|
end
|
53
55
|
|
54
56
|
# Q: perhaps do_in_list that takes a block?
|
@@ -130,4 +132,5 @@ module Kramdown; module AsciiDoc
|
|
130
132
|
(header.empty? ? @body : (header + (@body.empty? ? [] : [''] + @body))).join LF
|
131
133
|
end
|
132
134
|
end
|
133
|
-
end
|
135
|
+
end
|
136
|
+
end
|
data/lib/kramdown-asciidoc.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'kramdown'
|
2
4
|
require_relative 'kramdown-asciidoc/kramdown_ext/parser/base'
|
3
5
|
require_relative 'kramdown-asciidoc/kramdown_ext/parser/html'
|
4
6
|
require_relative 'kramdown-asciidoc/core_ext/regexp/is_match'
|
7
|
+
require_relative 'kramdown-asciidoc/core_ext/yaml'
|
5
8
|
require_relative 'kramdown-asciidoc/preprocessors'
|
6
9
|
require_relative 'kramdown-asciidoc/writer'
|
7
10
|
require_relative 'kramdown-asciidoc/converter'
|
@@ -11,4 +14,3 @@ Kramdown::Converter::Asciidoc = Kramdown::AsciiDoc::Converter
|
|
11
14
|
# add Kramdoc alias
|
12
15
|
Kramdoc = Kramdown::AsciiDoc
|
13
16
|
autoload :Pathname, 'pathname'
|
14
|
-
autoload :YAML, 'yaml'
|
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
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Allen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kramdown
|
@@ -16,70 +16,70 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.4.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.4.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rexml
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
34
|
-
type: :
|
33
|
+
version: 3.2.0
|
34
|
+
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 3.2.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: kramdown-parser-gfm
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
48
|
-
type: :
|
47
|
+
version: 1.1.0
|
48
|
+
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 1.1.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 13.0.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 13.0.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 3.11.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 3.11.0
|
83
83
|
description: A kramdown extension for converting Markdown documents to AsciiDoc.
|
84
84
|
email:
|
85
85
|
- dan.j.allen@gmail.com
|
@@ -100,6 +100,7 @@ files:
|
|
100
100
|
- lib/kramdown-asciidoc/cli.rb
|
101
101
|
- lib/kramdown-asciidoc/converter.rb
|
102
102
|
- lib/kramdown-asciidoc/core_ext/regexp/is_match.rb
|
103
|
+
- lib/kramdown-asciidoc/core_ext/yaml.rb
|
103
104
|
- lib/kramdown-asciidoc/kramdown_ext/parser/base.rb
|
104
105
|
- lib/kramdown-asciidoc/kramdown_ext/parser/html.rb
|
105
106
|
- lib/kramdown-asciidoc/preprocessors.rb
|
@@ -128,8 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
129
|
- !ruby/object:Gem::Version
|
129
130
|
version: '0'
|
130
131
|
requirements: []
|
131
|
-
|
132
|
-
rubygems_version: 2.7.8
|
132
|
+
rubygems_version: 3.3.7
|
133
133
|
signing_key:
|
134
134
|
specification_version: 4
|
135
135
|
summary: A Markdown to AsciiDoc converter based on kramdown
|