kramdown-asciidoc 1.0.1 → 2.0.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 +26 -0
- data/Gemfile +18 -3
- data/LICENSE.adoc +1 -1
- data/README.adoc +23 -28
- data/bin/kramdoc +1 -0
- data/kramdown-asciidoc.gemspec +7 -7
- data/lib/kramdoc.rb +2 -0
- data/lib/kramdown-asciidoc.rb +2 -0
- data/lib/kramdown-asciidoc/api.rb +10 -6
- data/lib/kramdown-asciidoc/cli.rb +8 -4
- data/lib/kramdown-asciidoc/converter.rb +61 -38
- data/lib/kramdown-asciidoc/core_ext/regexp/is_match.rb +12 -4
- 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
- metadata +19 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be0108c05d441dbc4125ed5fa6f51d152ae238d769cf5add12a0c35000c237e4
|
4
|
+
data.tar.gz: 77fec67f63c28cb7611c45aaca839292cb19686e8d9e02cd87ed31a129fd939a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 309476de155735f63f125bf1c91349f2d261b02c4e69b0ca5e154381893ec6d340429f348d14dd42e08ec4039db7d531a5de36e13089ee2e4ff9609696e161a7
|
7
|
+
data.tar.gz: e4e265aae1a393d0f1b2038bce02aae9ffaa24d4b8e219458bf557ff219c3629c27d9788a9b1a69115d1e1522b60ec28d3771884cc68c2cfc4dbfa52f15f35b0
|
data/CHANGELOG.adoc
CHANGED
@@ -5,6 +5,32 @@
|
|
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.0.0 (2021-07-11) - @mojavelinux
|
9
|
+
|
10
|
+
=== Added
|
11
|
+
|
12
|
+
* Add support for converting block LaTeX math to stem block
|
13
|
+
* Add support for converting span LaTeX math to inline stem macro
|
14
|
+
* Add basic support for footnotes (#74)
|
15
|
+
|
16
|
+
=== Fixed
|
17
|
+
|
18
|
+
* Use File.read instead of IO.read to suppress magic subprocess behavior
|
19
|
+
* Enable compatibility with Ruby 3 by declaring rexml as a runtime dependency (#84)
|
20
|
+
* Don't crash when converting list item that only contains spaces (#83)
|
21
|
+
|
22
|
+
=== Changed
|
23
|
+
|
24
|
+
* Upgrade kramdown to 2.3.x and declare kramdown-parser-gfm as runtime dependency (#85)
|
25
|
+
* Don't add source style to listing block when language is specified
|
26
|
+
* Switch CI to GitHub Actions
|
27
|
+
* Run test suite in CI environment on Windows and macOS
|
28
|
+
* Apply style rules to source code
|
29
|
+
|
30
|
+
=== Details
|
31
|
+
|
32
|
+
{uri-repo}/releases/tag/v2.0.0[git tag] | {uri-repo}/compare/v1.0.1\...v2.0.0[full diff]
|
33
|
+
|
8
34
|
== 1.0.1 (2018-11-28) - @mojavelinux
|
9
35
|
|
10
36
|
=== 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.18.0', require: false
|
16
|
+
gem 'rubocop-rake', '~> 0.6.0', require: false
|
17
|
+
gem 'rubocop-rspec', '~> 2.4.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. (on behalf of the Asciidoctor Project)
|
3
|
+
Copyright (C) 2016-2019 OpenDevise Inc. (on behalf of the Asciidoctor Project)
|
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.0.0, 2021-07-11
|
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-2019 OpenDevise Inc. (on behalf of the Asciidoctor Project).
|
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
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.3.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.10.0'
|
40
40
|
end
|
data/lib/kramdoc.rb
CHANGED
data/lib/kramdown-asciidoc.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.
|
@@ -92,7 +95,7 @@ module Kramdown; module AsciiDoc
|
|
92
95
|
markdown_file = markdown_file.path
|
93
96
|
encode = true
|
94
97
|
else
|
95
|
-
markdown = ::
|
98
|
+
markdown = ::File.read markdown_file, mode: 'r:UTF-8', newline: :universal
|
96
99
|
encode = false
|
97
100
|
end
|
98
101
|
if (to = opts[:to])
|
@@ -104,10 +107,11 @@ module Kramdown; module AsciiDoc
|
|
104
107
|
convert markdown, (opts.merge to: to, encode: encode)
|
105
108
|
end
|
106
109
|
|
107
|
-
private
|
108
|
-
|
109
110
|
CR = ?\r
|
110
111
|
LF = ?\n
|
111
112
|
TAB = ?\t
|
112
113
|
UTF_8 = ::Encoding::UTF_8
|
113
|
-
|
114
|
+
|
115
|
+
private_constant :CR, :LF, :TAB, :UTF_8
|
116
|
+
end
|
117
|
+
end
|
@@ -1,12 +1,15 @@
|
|
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|
|
@@ -28,7 +31,7 @@ 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
|
|
@@ -122,4 +125,5 @@ module Kramdown; module AsciiDoc
|
|
122
125
|
1
|
123
126
|
end
|
124
127
|
end
|
125
|
-
end
|
128
|
+
end
|
129
|
+
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,6 +90,7 @@ 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
|
92
95
|
@heading_offset = opts[:heading_offset] || 0
|
93
96
|
@imagesdir = opts[:imagesdir] || @attributes['imagesdir']
|
@@ -166,8 +169,7 @@ module Kramdown; module AsciiDoc
|
|
166
169
|
# Kramdown incorrectly uses the term header for headings
|
167
170
|
alias convert_header convert_heading
|
168
171
|
|
169
|
-
def convert_blank el, opts
|
170
|
-
end
|
172
|
+
def convert_blank el, opts; end
|
171
173
|
|
172
174
|
def convert_p el, opts
|
173
175
|
(writer = opts[:writer]).start_block
|
@@ -229,9 +231,9 @@ module Kramdown; module AsciiDoc
|
|
229
231
|
if (lang = el.attr['class'])
|
230
232
|
# NOTE Kramdown always prefixes class with language-
|
231
233
|
# TODO remap lang if requested
|
232
|
-
writer.add_line %([
|
234
|
+
writer.add_line %([,#{lang = lang.slice 9, lang.length}])
|
233
235
|
elsif (prompt = lines[0].start_with? '$ ')
|
234
|
-
writer.add_line %([
|
236
|
+
writer.add_line %([,#{lang = 'console'}]) if lines.include? ''
|
235
237
|
end
|
236
238
|
if lang || (el.options[:fenced] && !prompt)
|
237
239
|
writer.add_line '----'
|
@@ -244,7 +246,7 @@ module Kramdown; module AsciiDoc
|
|
244
246
|
else
|
245
247
|
# NOTE clear the list continuation as it isn't required
|
246
248
|
writer.clear_line if writer.current_line == '+'
|
247
|
-
writer.add_line
|
249
|
+
writer.add_line(lines.map {|l| %( #{l}) })
|
248
250
|
end
|
249
251
|
end
|
250
252
|
|
@@ -263,8 +265,8 @@ module Kramdown; module AsciiDoc
|
|
263
265
|
block = true
|
264
266
|
end
|
265
267
|
macro_attrs = [nil]
|
266
|
-
if (alt_text = el.attr['alt'])
|
267
|
-
macro_attrs[0] = alt_text
|
268
|
+
if (alt_text = el.attr['alt']) && !alt_text.empty?
|
269
|
+
macro_attrs[0] = alt_text
|
268
270
|
end
|
269
271
|
if (width = el.attr['width'])
|
270
272
|
macro_attrs << width
|
@@ -293,7 +295,7 @@ module Kramdown; module AsciiDoc
|
|
293
295
|
end
|
294
296
|
end
|
295
297
|
|
296
|
-
def
|
298
|
+
def _convert_list el, opts
|
297
299
|
kin = el.type == :dl ? :dlist : :list
|
298
300
|
(writer = opts[:writer]).start_list (parent = opts[:parent]).type == :dd || parent.options[:compound], kin
|
299
301
|
traverse el, opts
|
@@ -301,15 +303,16 @@ module Kramdown; module AsciiDoc
|
|
301
303
|
writer.add_blank_line if writer.in_list? && opts[:next]
|
302
304
|
end
|
303
305
|
|
304
|
-
alias
|
305
|
-
alias
|
306
|
+
alias convert_ul _convert_list
|
307
|
+
alias convert_ol _convert_list
|
308
|
+
alias convert_dl _convert_list
|
306
309
|
|
307
310
|
def convert_li el, opts
|
308
311
|
writer = opts[:writer]
|
309
312
|
writer.add_blank_line if (prev = opts[:prev]) && prev.options[:compound]
|
310
313
|
marker = opts[:parent].type == :ol ? '.' : '*'
|
311
314
|
indent = (level = writer.list_level) - 1
|
312
|
-
if (children = el.children)[0].type == :p
|
315
|
+
if !(children = el.children).empty? && children[0].type == :p
|
313
316
|
primary, remaining = [(children = children.dup).shift, children]
|
314
317
|
primary_lines = compose_text [primary], parent: el, strip: true, split: true, wrap: @wrap
|
315
318
|
else
|
@@ -320,7 +323,7 @@ module Kramdown; module AsciiDoc
|
|
320
323
|
writer.add_lines primary_lines
|
321
324
|
unless remaining.empty?
|
322
325
|
if remaining.find {|n| (type = n.type) == :blank ? nil : ((BLOCK_TYPES.include? type) ? true : break) }
|
323
|
-
el.options[:compound] = true
|
326
|
+
el.options[:compound] = true
|
324
327
|
end
|
325
328
|
traverse remaining, (opts.merge parent: el)
|
326
329
|
end
|
@@ -402,7 +405,7 @@ module Kramdown; module AsciiDoc
|
|
402
405
|
opts[:writer].add_lines table_buffer
|
403
406
|
end
|
404
407
|
|
405
|
-
def convert_hr
|
408
|
+
def convert_hr _el, opts
|
406
409
|
(writer = opts[:writer]).start_block
|
407
410
|
writer.add_line '\'\'\''
|
408
411
|
end
|
@@ -411,11 +414,11 @@ module Kramdown; module AsciiDoc
|
|
411
414
|
if (url = el.attr['href']).start_with? '#'
|
412
415
|
opts[:writer].append %(<<#{url.slice 1, url.length},#{compose_text el, strip: true}>>)
|
413
416
|
elsif url.start_with? 'https://', 'http://'
|
414
|
-
if (children = el.children).size == 1 && (child_i =
|
417
|
+
if (children = el.children).size == 1 && (child_i = children[0]).type == :img
|
415
418
|
convert_img child_i, parent: opts[:parent], index: 0, url: url, writer: opts[:writer]
|
416
419
|
else
|
417
420
|
bare = ((text = compose_text el, strip: true).chomp '/') == (url.chomp '/')
|
418
|
-
url = url.gsub '__', '%5F%5F' if
|
421
|
+
url = url.gsub '__', '%5F%5F' if url.include? '__'
|
419
422
|
opts[:writer].append bare ? url : %(#{url}[#{text.gsub ']', '\]'}])
|
420
423
|
end
|
421
424
|
elsif url.end_with? '.md'
|
@@ -425,7 +428,7 @@ module Kramdown; module AsciiDoc
|
|
425
428
|
else
|
426
429
|
opts[:writer].append %(link:#{url}[#{(compose_text el, strip: true).gsub ']', '\]'}])
|
427
430
|
end
|
428
|
-
end
|
431
|
+
end
|
429
432
|
|
430
433
|
def convert_codespan el, opts
|
431
434
|
attrlist, mark = '', '`'
|
@@ -446,9 +449,10 @@ module Kramdown; module AsciiDoc
|
|
446
449
|
text = el.value
|
447
450
|
pass = (replaceable? text) ? :shorthand : nil
|
448
451
|
pass = :macro if text.include? '++'
|
449
|
-
|
452
|
+
case pass
|
453
|
+
when :shorthand
|
450
454
|
opts[:writer].append %(#{mark}+#{text}+#{mark})
|
451
|
-
|
455
|
+
when :macro
|
452
456
|
opts[:writer].append %(#{mark}pass:c[#{text}]#{mark})
|
453
457
|
else
|
454
458
|
opts[:writer].append %(#{attrlist}#{mark}#{text}#{mark})
|
@@ -489,7 +493,7 @@ module Kramdown; module AsciiDoc
|
|
489
493
|
@attributes['pp'] = '{plus}{plus}'
|
490
494
|
text = text.gsub '++', '{pp}'
|
491
495
|
end
|
492
|
-
if (
|
496
|
+
if (writer = opts[:writer]).current_line.to_s.empty?
|
493
497
|
writer.append text.lstrip
|
494
498
|
else
|
495
499
|
writer.append text
|
@@ -519,15 +523,19 @@ module Kramdown; module AsciiDoc
|
|
519
523
|
else
|
520
524
|
writer.append %(#{(writer.current_line.end_with? ' ') ? '' : ' '}+)
|
521
525
|
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
|
526
|
+
writer.add_blank_line if el.options[:html_tag] && ((next_el = to_element opts[:next]).type != :text || !(next_el.value.start_with? LF))
|
525
527
|
end
|
526
528
|
|
527
529
|
def convert_entity el, opts
|
528
530
|
opts[:writer].append RESOLVE_ENTITY_TABLE[el.value.code_point] || el.options[:original]
|
529
531
|
end
|
530
532
|
|
533
|
+
def convert_footnote el, opts
|
534
|
+
id = el.options[:name]
|
535
|
+
composed_text = (@footnote_ids.add? id) ? ((compose_text el.value).gsub ']', '\]') : ''
|
536
|
+
opts[:writer].append %(footnote:#{id}[#{composed_text}])
|
537
|
+
end
|
538
|
+
|
531
539
|
def convert_smart_quote el, opts
|
532
540
|
opts[:writer].append SMART_QUOTE_ENTITY_TO_MARKUP[el.value]
|
533
541
|
end
|
@@ -583,7 +591,7 @@ module Kramdown; module AsciiDoc
|
|
583
591
|
lines = val.split LF
|
584
592
|
end
|
585
593
|
#siblings = (parent = opts[:parent]) ? parent.children : []
|
586
|
-
if
|
594
|
+
if el.options[:category] == :block # || (!opts[:result][-1] && siblings[-1] == el)
|
587
595
|
writer.start_block
|
588
596
|
if lines.empty?
|
589
597
|
writer.add_line '//'
|
@@ -611,10 +619,24 @@ module Kramdown; module AsciiDoc
|
|
611
619
|
end
|
612
620
|
end
|
613
621
|
|
622
|
+
def convert_math el, opts
|
623
|
+
writer = opts[:writer]
|
624
|
+
@attributes['stem'] = 'latexmath'
|
625
|
+
if el.options[:category] == :span
|
626
|
+
writer.append %(stem:[#{el.value.gsub ']', '\]'}])
|
627
|
+
else
|
628
|
+
writer.start_block
|
629
|
+
writer.add_line '[stem]'
|
630
|
+
writer.add_line '++++'
|
631
|
+
writer.add_lines el.value.rstrip.split LF
|
632
|
+
writer.add_line '++++'
|
633
|
+
end
|
634
|
+
end
|
635
|
+
|
614
636
|
private
|
615
637
|
|
616
638
|
def extract_prologue el, opts
|
617
|
-
if (
|
639
|
+
if (to_element (children = el.children)[0]).type == :xml_comment
|
618
640
|
(prologue_el = el.dup).children = children.take_while {|child| child.type == :xml_comment || child.type == :blank }
|
619
641
|
(el = el.dup).children = children.drop prologue_el.children.size
|
620
642
|
traverse prologue_el, (opts.merge writer: (prologue_writer = Writer.new))
|
@@ -692,9 +714,9 @@ module Kramdown; module AsciiDoc
|
|
692
714
|
end
|
693
715
|
end
|
694
716
|
if ventilate
|
695
|
-
result.map
|
696
|
-
(
|
697
|
-
|
717
|
+
result.map do |l|
|
718
|
+
(l.start_with? '//') || !(STOP_PUNCTUATION.any? {|punc| l.include? punc }) ? l : (l.gsub StopPunctRx, LF)
|
719
|
+
end.join LF
|
698
720
|
else
|
699
721
|
result.join LF
|
700
722
|
end
|
@@ -741,4 +763,5 @@ module Kramdown; module AsciiDoc
|
|
741
763
|
@ids_seen[id] = idx || UNIQUE_ID_START_INDEX
|
742
764
|
end
|
743
765
|
end
|
744
|
-
end
|
766
|
+
end
|
767
|
+
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
|
@@ -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).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
|
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:
|
4
|
+
version: 2.0.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: 2021-07-11 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.3.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.3.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.10.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.10.0
|
83
83
|
description: A kramdown extension for converting Markdown documents to AsciiDoc.
|
84
84
|
email:
|
85
85
|
- dan.j.allen@gmail.com
|
@@ -128,8 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
128
|
- !ruby/object:Gem::Version
|
129
129
|
version: '0'
|
130
130
|
requirements: []
|
131
|
-
|
132
|
-
rubygems_version: 2.7.8
|
131
|
+
rubygems_version: 3.2.22
|
133
132
|
signing_key:
|
134
133
|
specification_version: 4
|
135
134
|
summary: A Markdown to AsciiDoc converter based on kramdown
|