reverse_adoc 1.0.1 → 2.0.1
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/.github/workflows/rake.yml +16 -3
- data/.github/workflows/release.yml +19 -2
- data/Gemfile +5 -3
- data/README.adoc +21 -280
- data/Rakefile +4 -10
- data/lib/reverse_adoc/version.rb +3 -1
- data/lib/reverse_adoc.rb +16 -21
- data/reverse_adoc.gemspec +13 -21
- data/spec/reverse_adoc_spec.rb +28 -0
- data/spec/spec_helper.rb +5 -20
- metadata +21 -228
- data/.editorconfig +0 -15
- data/.gitignore +0 -10
- data/.hound.yml +0 -5
- data/.rubocop.yml +0 -10
- data/LICENSE.txt +0 -25
- data/exe/reverse_adoc +0 -70
- data/exe/w2a +0 -72
- data/lib/reverse_adoc/cleaner.rb +0 -113
- data/lib/reverse_adoc/config.rb +0 -54
- data/lib/reverse_adoc/converters/a.rb +0 -42
- data/lib/reverse_adoc/converters/aside.rb +0 -16
- data/lib/reverse_adoc/converters/audio.rb +0 -29
- data/lib/reverse_adoc/converters/base.rb +0 -100
- data/lib/reverse_adoc/converters/blockquote.rb +0 -27
- data/lib/reverse_adoc/converters/br.rb +0 -15
- data/lib/reverse_adoc/converters/bypass.rb +0 -81
- data/lib/reverse_adoc/converters/code.rb +0 -56
- data/lib/reverse_adoc/converters/div.rb +0 -18
- data/lib/reverse_adoc/converters/drop.rb +0 -22
- data/lib/reverse_adoc/converters/em.rb +0 -55
- data/lib/reverse_adoc/converters/figure.rb +0 -25
- data/lib/reverse_adoc/converters/h.rb +0 -42
- data/lib/reverse_adoc/converters/head.rb +0 -23
- data/lib/reverse_adoc/converters/hr.rb +0 -15
- data/lib/reverse_adoc/converters/ignore.rb +0 -16
- data/lib/reverse_adoc/converters/img.rb +0 -93
- data/lib/reverse_adoc/converters/li.rb +0 -17
- data/lib/reverse_adoc/converters/mark.rb +0 -21
- data/lib/reverse_adoc/converters/math.rb +0 -31
- data/lib/reverse_adoc/converters/ol.rb +0 -64
- data/lib/reverse_adoc/converters/p.rb +0 -23
- data/lib/reverse_adoc/converters/pass_through.rb +0 -13
- data/lib/reverse_adoc/converters/pre.rb +0 -55
- data/lib/reverse_adoc/converters/q.rb +0 -16
- data/lib/reverse_adoc/converters/strong.rb +0 -52
- data/lib/reverse_adoc/converters/sub.rb +0 -16
- data/lib/reverse_adoc/converters/sup.rb +0 -16
- data/lib/reverse_adoc/converters/table.rb +0 -69
- data/lib/reverse_adoc/converters/td.rb +0 -83
- data/lib/reverse_adoc/converters/text.rb +0 -65
- data/lib/reverse_adoc/converters/th.rb +0 -14
- data/lib/reverse_adoc/converters/tr.rb +0 -22
- data/lib/reverse_adoc/converters/video.rb +0 -29
- data/lib/reverse_adoc/converters.rb +0 -32
- data/lib/reverse_adoc/errors.rb +0 -10
- data/lib/reverse_adoc/html_converter.rb +0 -61
- data/spec/assets/anchors.html +0 -30
- data/spec/assets/basic.html +0 -61
- data/spec/assets/code.html +0 -22
- data/spec/assets/escapables.html +0 -17
- data/spec/assets/external_images.docx +0 -0
- data/spec/assets/external_images.html +0 -35
- data/spec/assets/from_the_wild.html +0 -23
- data/spec/assets/full_example.html +0 -49
- data/spec/assets/html_fragment.html +0 -3
- data/spec/assets/lists.html +0 -137
- data/spec/assets/minimum.html +0 -4
- data/spec/assets/paragraphs.html +0 -24
- data/spec/assets/quotation.html +0 -12
- data/spec/assets/tables.html +0 -99
- data/spec/assets/unknown_tags.html +0 -9
- data/spec/bin/reverse_adoc_spec.rb +0 -33
- data/spec/bin/w2a_spec.rb +0 -35
- data/spec/components/anchors_spec.rb +0 -32
- data/spec/components/basic_spec.rb +0 -63
- data/spec/components/code_spec.rb +0 -25
- data/spec/components/escapables_spec.rb +0 -30
- data/spec/components/from_the_wild_spec.rb +0 -15
- data/spec/components/html_fragment_spec.rb +0 -9
- data/spec/components/lists_spec.rb +0 -90
- data/spec/components/paragraphs_spec.rb +0 -14
- data/spec/components/quotation_spec.rb +0 -12
- data/spec/components/tables_spec.rb +0 -42
- data/spec/components/unknown_tags_spec.rb +0 -41
- data/spec/lib/reverse_adoc/cleaner_spec.rb +0 -180
- data/spec/lib/reverse_adoc/config_spec.rb +0 -25
- data/spec/lib/reverse_adoc/converters/aside_spec.rb +0 -11
- data/spec/lib/reverse_adoc/converters/audio_spec.rb +0 -15
- data/spec/lib/reverse_adoc/converters/blockquote_spec.rb +0 -23
- data/spec/lib/reverse_adoc/converters/br_spec.rb +0 -9
- data/spec/lib/reverse_adoc/converters/code_spec.rb +0 -15
- data/spec/lib/reverse_adoc/converters/div_spec.rb +0 -15
- data/spec/lib/reverse_adoc/converters/figure_spec.rb +0 -10
- data/spec/lib/reverse_adoc/converters/img_spec.rb +0 -25
- data/spec/lib/reverse_adoc/converters/li_spec.rb +0 -11
- data/spec/lib/reverse_adoc/converters/mark_spec.rb +0 -10
- data/spec/lib/reverse_adoc/converters/p_spec.rb +0 -10
- data/spec/lib/reverse_adoc/converters/pre_spec.rb +0 -43
- data/spec/lib/reverse_adoc/converters/q_spec.rb +0 -10
- data/spec/lib/reverse_adoc/converters/strong_spec.rb +0 -21
- data/spec/lib/reverse_adoc/converters/text_spec.rb +0 -67
- data/spec/lib/reverse_adoc/converters/video_spec.rb +0 -15
- data/spec/lib/reverse_adoc/converters_spec.rb +0 -22
- data/spec/lib/reverse_adoc.rb +0 -90
- data/spec/support/shell_helpers.rb +0 -15
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f001bed15179069c3cf7f80c084eea563df4f8dacff7288fca4294a73e331ed9
|
|
4
|
+
data.tar.gz: 381680a22721c5df61c7dce5151a2905bca961146f7c2eae5568c3b80c023b98
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 637b51f67c80cb7b0a2b8b36979581553e9072f16bdccffbd92ba1eee85fee939ceb97bbbf88eeba92ec6f5e2c057e89b29dfd4a015a72dd88eb0332e94f3c0d
|
|
7
|
+
data.tar.gz: 11b0d2b61a70491a5e9ba921a84e13f781220c97a6302fcd2e7e559156ae90da3518ff7457e4852a7ddc07196cc3623d21e193fc813189ce68fa8b2713b0a8aa
|
data/.github/workflows/rake.yml
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
#
|
|
2
|
-
#
|
|
1
|
+
# Formerly cimas-managed. Now consumer-owned per metanorma/cimas#68
|
|
2
|
+
# (workflow-file conversion from cimas-synced copied stubs to reusable-workflow
|
|
3
|
+
# references). Pins metanorma/ci reusable at @v1 (moving major, three-tier
|
|
4
|
+
# tagging discipline per metanorma/ci#372).
|
|
5
|
+
#
|
|
6
|
+
# cascade is false: reverse_adoc is a facade gem whose releases are dispatched
|
|
7
|
+
# manually (gh workflow run release.yml -f next_version=x.y.z). The default
|
|
8
|
+
# cascade fires do-release on every green push to main, which on a facade gem
|
|
9
|
+
# only re-builds the already-published version and lands a red duplicate-push
|
|
10
|
+
# run on main.
|
|
3
11
|
name: rake
|
|
4
12
|
|
|
5
13
|
on:
|
|
@@ -8,8 +16,13 @@ on:
|
|
|
8
16
|
tags: [ v* ]
|
|
9
17
|
pull_request:
|
|
10
18
|
|
|
19
|
+
permissions:
|
|
20
|
+
contents: read
|
|
21
|
+
|
|
11
22
|
jobs:
|
|
12
23
|
rake:
|
|
13
|
-
uses: metanorma/ci/.github/workflows/
|
|
24
|
+
uses: metanorma/ci/.github/workflows/generic-rake.yml@v1
|
|
25
|
+
with:
|
|
26
|
+
cascade: false
|
|
14
27
|
secrets:
|
|
15
28
|
pat_token: ${{ secrets.METANORMA_CI_PAT_TOKEN }}
|
|
@@ -13,6 +13,21 @@ on:
|
|
|
13
13
|
default: 'skip'
|
|
14
14
|
repository_dispatch:
|
|
15
15
|
types: [ do-release ]
|
|
16
|
+
# The publish leg: when the release PR (head branch `release/v*`) merges,
|
|
17
|
+
# the reusable tags the merge commit and publishes (ci#515). Ordinary PR
|
|
18
|
+
# closes are skipped inside the reusable — no noise on regular merges.
|
|
19
|
+
pull_request:
|
|
20
|
+
types:
|
|
21
|
+
- closed
|
|
22
|
+
|
|
23
|
+
# Least-privilege ceiling for the called rubygems-release.yml: its release job
|
|
24
|
+
# needs contents:write (git tag push), id-token:write (OIDC Trusted Publishing),
|
|
25
|
+
# and pull-requests:write (the release-PR leg opens and auto-merges the release
|
|
26
|
+
# PR — ci#515; reusable workflows are capped by the caller's permissions).
|
|
27
|
+
permissions:
|
|
28
|
+
contents: write
|
|
29
|
+
id-token: write
|
|
30
|
+
pull-requests: write
|
|
16
31
|
|
|
17
32
|
jobs:
|
|
18
33
|
release:
|
|
@@ -20,6 +35,8 @@ jobs:
|
|
|
20
35
|
with:
|
|
21
36
|
next_version: ${{ github.event.inputs.next_version }}
|
|
22
37
|
secrets:
|
|
23
|
-
|
|
38
|
+
# Trusted Publishing (OIDC) is the only publish path: the org
|
|
39
|
+
# METANORMA_CI_RUBYGEMS_API_KEY secret was deleted (metanorma/ci#373),
|
|
40
|
+
# and rubygems-release.yml falls through to the OIDC/TP flow when the
|
|
41
|
+
# rubygems-api-key secret is absent (metanorma/ci#416).
|
|
24
42
|
pat_token: ${{ secrets.METANORMA_CI_PAT_TOKEN }}
|
|
25
|
-
|
data/Gemfile
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
source "https://rubygems.org"
|
|
4
4
|
|
|
5
|
-
# Specify your gem's dependencies in reverse_adoc.gemspec
|
|
6
5
|
gemspec
|
|
6
|
+
|
|
7
|
+
gem "rake"
|
|
8
|
+
gem "rspec"
|
data/README.adoc
CHANGED
|
@@ -1,296 +1,37 @@
|
|
|
1
|
-
= AsciiDoc from HTML
|
|
1
|
+
= AsciiDoc from HTML: reverse_adoc
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
reverse_adoc is a compatibility facade over the ceradoc monorepo (the gem
|
|
4
|
+
formerly known as coradoc, renamed coradoc → coridoc → ceradoc in
|
|
5
|
+
November 2026): since 2.0.0 it ships no converter code of its own. The
|
|
6
|
+
HTML-to-AsciiDoc engine lives in https://github.com/ceradoc/ceradoc as
|
|
7
|
+
`ceradoc-html`, driven by the unified https://rubygems.org/gems/ceradoc[`ceradoc`]
|
|
8
|
+
API.
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Transforms HTML and Microsoft Word into AsciiDoc.
|
|
12
|
-
|
|
13
|
-
Based on https://github.com/xijo/reverse_markdown
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
== Installation
|
|
17
|
-
|
|
18
|
-
Install the gem:
|
|
19
|
-
|
|
20
|
-
[source,console]
|
|
21
|
-
----
|
|
22
|
-
[sudo] gem install reverse_adoc
|
|
23
|
-
----
|
|
24
|
-
|
|
25
|
-
or add it to your `Gemfile`:
|
|
10
|
+
`require "reverse_adoc"` loads that engine, and `ReverseAdoc.convert`
|
|
11
|
+
delegates to it, so existing callers keep working:
|
|
26
12
|
|
|
27
13
|
[source,ruby]
|
|
28
14
|
----
|
|
29
|
-
|
|
30
|
-
----
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
== Command-line usage
|
|
34
|
-
|
|
35
|
-
=== HTML to AsciiDoc: `reverse_adoc`
|
|
15
|
+
require 'reverse_adoc'
|
|
36
16
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
[source,console]
|
|
40
|
-
----
|
|
41
|
-
$ reverse_adoc file.html > file.adoc
|
|
42
|
-
$ cat file.html | reverse_adoc > file.adoc
|
|
43
|
-
----
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
=== Microsoft Word to AsciiDoc: `w2a`
|
|
47
|
-
|
|
48
|
-
Convert Word `.doc` or `.docx` files to AsciiDoc:
|
|
49
|
-
|
|
50
|
-
[source,console]
|
|
51
|
-
----
|
|
52
|
-
$ w2a file.docx > file.adoc
|
|
53
|
-
----
|
|
54
|
-
|
|
55
|
-
[source,console]
|
|
56
|
-
----
|
|
57
|
-
$ w2a input.docx -o output.adoc
|
|
17
|
+
ReverseAdoc.convert("<b>hello</b>")
|
|
58
18
|
----
|
|
59
19
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
[source,console]
|
|
63
|
-
----
|
|
64
|
-
$ w2a -h
|
|
65
|
-
Usage: w2a [options] <file>
|
|
66
|
-
-a, --mathml2asciimath Convert MathML to AsciiMath
|
|
67
|
-
-o, --output=FILENAME Output file to write to
|
|
68
|
-
-e, --external-images Export images if data URI
|
|
69
|
-
-v, --version Version information
|
|
70
|
-
-h, --help Prints this help
|
|
71
|
-
----
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
NOTE: `w2a` requires LibreOffice to be installed. It uses LibreOffice's
|
|
75
|
-
export to XHTML. LibreOffice's export of XHTML is superior to the native Microsoft Word export
|
|
76
|
-
to HTML: it exports lists (which Word keeps as paragraphs), and it exports OOMML into MathML.
|
|
77
|
-
On the other hand, the LibreOffice export relies on default styling being used in the
|
|
78
|
-
document, and it may not cope with ordered lists or headings with customised appearance.
|
|
79
|
-
For best results, reset the styles in the document you're converting to those in
|
|
80
|
-
the default `Normal.dot` template.
|
|
81
|
-
|
|
82
|
-
NOTE: `w2a` requires the command-line version of LibreOffice, `soffice`. As it turns out,
|
|
83
|
-
LibreOffice v6 appears to render formulae in HTML as images instead of MathML expressions;
|
|
84
|
-
use LibreOffice v5. If you have both LibreOffice v5 and LibreOffice v6 installed, make sure
|
|
85
|
-
that your OS path searches for the LibreOffice v5 version of `soffice` first; e.g. on Mac,
|
|
86
|
-
include something like `/Applications/LibreOffice5.4.7.2.app/Contents/MacOS` in your PATH
|
|
87
|
-
environment.
|
|
88
|
-
|
|
89
|
-
NOTE: Some information in OOMML is not preserved in the export to MathML from LibreOffice;
|
|
90
|
-
in particular, font shifts such as double-struck fonts.
|
|
91
|
-
The LibreOffice exporter does seem to drop some text (possibly associated with
|
|
92
|
-
MathML); use with caution.
|
|
93
|
-
|
|
94
|
-
NOTE: Adapted from `w2m` of
|
|
95
|
-
https://github.com/benbalter/word-to-markdown[Ben Balter's word-to-markdown]
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
=== Common options
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
==== MathML to AsciiMath conversion
|
|
102
|
-
|
|
103
|
-
If you wish to convert the MathML in the document to AsciiMath, run the script with the
|
|
104
|
-
`--mathml2asciimath` option:
|
|
105
|
-
|
|
106
|
-
[source,console]
|
|
107
|
-
----
|
|
108
|
-
$ w2a --mathml2asciimath document.docx > document.adoc
|
|
109
|
-
----
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
==== Extracting images
|
|
113
|
-
|
|
114
|
-
Images referred by the HTML can be extracted into the destination output folder by using:
|
|
115
|
-
|
|
116
|
-
[source,console]
|
|
117
|
-
----
|
|
118
|
-
$ reverse_adoc input.docx -o output/file.adoc -e
|
|
119
|
-
$ reverse_adoc input.docx --output output/file.adoc --external-images
|
|
120
|
-
----
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
Word embedded images can be extracted into the destination output folder by using:
|
|
124
|
-
|
|
125
|
-
[source,console]
|
|
126
|
-
----
|
|
127
|
-
$ w2a input.docx -o output/file.adoc -e
|
|
128
|
-
$ w2a input.docx --output output/file.adoc --external-images
|
|
129
|
-
----
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
==== Handling unknown HTML tags
|
|
133
|
-
|
|
134
|
-
The `--unknown_tags` option allows you to specify how to handle unknown tags
|
|
135
|
-
(default `pass_through`).
|
|
136
|
-
|
|
137
|
-
Valid options are:
|
|
138
|
-
|
|
139
|
-
* `pass_through` - Include the unknown tag completely into the result
|
|
140
|
-
* `drop` - Drop the unknown tag and its content
|
|
141
|
-
* `bypass` - Ignore the unknown tag but try to convert its content
|
|
142
|
-
* `raise` - Raise an error to let you know
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
==== Tagging of borders
|
|
146
|
-
|
|
147
|
-
Specify how to handle tag borders with the option `--tag_border` (default `' '`).
|
|
148
|
-
|
|
149
|
-
Valid options are:
|
|
150
|
-
|
|
151
|
-
* `' '` - Add whitespace if there is none at tag borders.
|
|
152
|
-
* `''` - Do not not add whitespace.
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
== Features
|
|
156
|
-
|
|
157
|
-
=== General
|
|
158
|
-
|
|
159
|
-
`reverse_adoc` shares features as a port of `reverse_markdown`:
|
|
160
|
-
|
|
161
|
-
* Module based -- if you miss a tag, just add it
|
|
162
|
-
* Can deal with nested lists
|
|
163
|
-
* Inline and block code is supported
|
|
164
|
-
* Supports blockquote
|
|
165
|
-
|
|
166
|
-
It supports the following HTML tags (these are supported by `reverse_markdown`):
|
|
167
|
-
|
|
168
|
-
* `a`
|
|
169
|
-
* `blockquote`
|
|
170
|
-
* `br`
|
|
171
|
-
* `code`, `tt` (added: `kbd`, `samp`, `var`)
|
|
172
|
-
* `div`, `article`
|
|
173
|
-
* `em`, `i` (added: `cite`)
|
|
174
|
-
* `h1`, `h2`, `h3`, `h4`, `h5`, `h6`, `hr`
|
|
175
|
-
* `img`
|
|
176
|
-
* `li`, `ol`, `ul` (added: `dir`)
|
|
177
|
-
* `p`, `pre`
|
|
178
|
-
* `strong`, `b`
|
|
179
|
-
* `table`, `td`, `th`, `tr`
|
|
180
|
-
|
|
181
|
-
[NOTE]
|
|
182
|
-
====
|
|
183
|
-
* reverse_adoc does *not* support `del` or `strike`, because Asciidoctor does not out of the box.
|
|
184
|
-
* As with reverse_markdown, `pre` is only treated as sourcecode if it is contained in a `div@class = highlight-` element, or has a `@brush` attribute naming the language (Confluence).
|
|
185
|
-
* The gem does not support `p@align`, because Asciidoctor doesn't
|
|
186
|
-
====
|
|
187
|
-
|
|
188
|
-
In addition, it supports:
|
|
189
|
-
|
|
190
|
-
* `aside`
|
|
191
|
-
* `audio`, `video` (with `@src` attributes)
|
|
192
|
-
* `figure`, `figcaption`
|
|
193
|
-
* `mark`
|
|
194
|
-
* `q`
|
|
195
|
-
* `sub`, `sup`
|
|
196
|
-
* `@id` anchors
|
|
197
|
-
* `blockquote@cite`
|
|
198
|
-
* `img/@width`, `img/@height`
|
|
199
|
-
* `ol/@style`, `ol/@start`, `ol/@reversed`, `ul/@type`
|
|
200
|
-
* `td/@colspan`, `td/@rowspan`, `td@/align`, `td@/valign`
|
|
201
|
-
* `table/caption`, `table/@width`, `table/@frame` (partial), `table/@rules` (partial)
|
|
202
|
-
* Lists and paragraphs within cells
|
|
203
|
-
** Not tables within cells: Asciidoctor cannot deal with nested tables
|
|
204
|
-
|
|
205
|
-
The gem does not support:
|
|
206
|
-
|
|
207
|
-
* `col`, `colgroup`
|
|
208
|
-
* `source`, `picture`
|
|
209
|
-
* `bdi`, `bdo`, `ruby`, `rt`, `rp`, `wbr`
|
|
210
|
-
* `frame`, `frameset`, `iframe`, `noframes`, `noscript`, `script`, `input`, `output`, `progress`
|
|
211
|
-
* `map`, `canvas`, `dialog`, `embed`, `object`, `param`, `svg`, `track`
|
|
212
|
-
* `fieldset`, `button`, `datalist`, `form`, `label`, `legend`, `menu`, `menulist`, `optgroup`, `option`, `select`, `textarea`
|
|
213
|
-
* `big`, `dfn`, `font`, `s`, `small`, `span`, `strike`, `u`
|
|
214
|
-
* `center`
|
|
215
|
-
* `data`, `meter`
|
|
216
|
-
* `del`, `ins`
|
|
217
|
-
* `footer`, `header`, `main`, `nav`, `details`, `section`, `summary`, `template`
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
=== MathML support
|
|
221
|
-
|
|
222
|
-
If you are using this gem in the context of https://www.metanorma.com[Metanorma],
|
|
223
|
-
Metanorma AsciiDoc accepts MathML as a native mathematical format. So you do not need
|
|
224
|
-
to convert the MathML to AsciiMath.
|
|
225
|
-
|
|
226
|
-
The gem will optionally invoke the https://github.com/metanorma/mathml2asciimath
|
|
227
|
-
gem, to convert MathML to AsciiMath. The conversion is not perfect, and will need to be
|
|
228
|
-
post-edited; but it's a lot better than nothing.
|
|
229
|
-
|
|
230
|
-
NOTE: Asciidoctor does not support MathML input. HTML uses MathML.
|
|
231
|
-
The gem will recognize MathML expressions in HTML, and will wrap them in Asciidoctor
|
|
232
|
-
`stem:[ ]` macros. The result of this gem is not actually legal Asciidoctor for `stem`:
|
|
233
|
-
Asciidoctor will presumably
|
|
234
|
-
think this is AsciiMath in the `stem:[ ]` macro, try to pass it into MathJax as
|
|
235
|
-
AsciiMath, and fail. But of course, MathJax has no problem with MathML, and some postprocessing
|
|
236
|
-
on the Asciidoctor output can ensure that the MathML is treated by MathJax (or whatever else
|
|
237
|
-
uses the output) as such; so this is still much better than nothing for stem processing.
|
|
238
|
-
|
|
239
|
-
=== Word cleanup
|
|
240
|
-
|
|
241
|
-
This gem is routinely used in the Metanorma project to export Word documents to AsciiDoc.
|
|
242
|
-
The HTML export from Word that the gem uses, from LibreOffice, is much cleaner than the
|
|
243
|
-
native HTML 4 export from Word; but it has some infelicities which this gem cleans up:
|
|
244
|
-
|
|
245
|
-
* The HTML export has trouble with subscripts, and routinely exports them as headings; the `w2a`
|
|
246
|
-
script tries to clean them up.
|
|
247
|
-
* The `w2a` cleans up spaces, but it does not strip them.
|
|
248
|
-
* Spaces are removed from anchors and cross-references.
|
|
249
|
-
* Double underscores are removed from anchors and cross-references.
|
|
250
|
-
* Cross-references to `_GoBack` and to `_Toc` followed by numbers (used to construct tables of contents) are ignored.
|
|
251
|
-
|
|
252
|
-
== Ruby library usage
|
|
253
|
-
|
|
254
|
-
=== General
|
|
255
|
-
|
|
256
|
-
Simple to use.
|
|
257
|
-
|
|
258
|
-
[source,ruby]
|
|
259
|
-
----
|
|
260
|
-
result = ReverseAdoc.convert input
|
|
261
|
-
result.inspect # " *feelings* "
|
|
262
|
-
----
|
|
263
|
-
|
|
264
|
-
=== Configure with options
|
|
265
|
-
|
|
266
|
-
Just pass your chosen configuration options in after the input. The given options will last for this operation only.
|
|
20
|
+
New code should call ceradoc directly:
|
|
267
21
|
|
|
268
22
|
[source,ruby]
|
|
269
23
|
----
|
|
270
|
-
|
|
271
|
-
|
|
24
|
+
require 'ceradoc'
|
|
25
|
+
require 'ceradoc/html'
|
|
26
|
+
require 'ceradoc/asciidoc'
|
|
272
27
|
|
|
273
|
-
|
|
274
|
-
=== Preconfigure using an initializer
|
|
275
|
-
|
|
276
|
-
Or configure it block style on a initializer level. These configurations will last for all conversions until they are set to something different.
|
|
277
|
-
|
|
278
|
-
[source,ruby]
|
|
279
|
-
----
|
|
280
|
-
ReverseAdoc.config do |config|
|
|
281
|
-
config.unknown_tags = :bypass
|
|
282
|
-
config.mathml2asciimath = true
|
|
283
|
-
config.tag_border = ''
|
|
284
|
-
end
|
|
28
|
+
Ceradoc.convert("<b>hello</b>", from: :html, to: :asciidoc)
|
|
285
29
|
----
|
|
286
30
|
|
|
31
|
+
The legacy `ReverseAdoc.convert(input, options)` options hash is accepted
|
|
32
|
+
for arity compatibility and ignored; the conversion tuning moved into the
|
|
33
|
+
ceradoc pipeline.
|
|
287
34
|
|
|
288
|
-
==
|
|
289
|
-
|
|
290
|
-
* https://github.com/xijo/reverse_markdown[Xijo's original reverse_markdown gem]
|
|
291
|
-
* https://github.com/xijo/reverse_markdown/wiki/Write-your-own-converter[Write custom converters] - Wiki entry about how to write your own converter
|
|
292
|
-
* https://github.com/harlantwood/html_massage[html_massage] - A gem by Harlan T. Wood to convert regular sites into markdown using reverse_markdown
|
|
293
|
-
* https://github.com/benbalter/word-to-markdown[word-to-markdown] - Convert word docs into markdown while using reverse_markdown, by Ben Balter
|
|
294
|
-
* https://github.com/asciidocfx/HtmlToAsciidoc[HtmlToAsciidoc] - Javascript regexp-based converter of HTML to Asciidoctor
|
|
295
|
-
* https://asciidoctor.org/docs/user-manual/[The Asciidoctor User Manual]
|
|
35
|
+
== License
|
|
296
36
|
|
|
37
|
+
Copyright Ribose.
|
data/Rakefile
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if File.exist?(".codeclimate")
|
|
4
|
-
ENV["CODECLIMATE_REPO_TOKEN"] = File.read(".codeclimate").strip
|
|
5
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
6
2
|
|
|
3
|
+
require "bundler/gem_tasks"
|
|
7
4
|
require "rspec/core/rake_task"
|
|
5
|
+
|
|
8
6
|
RSpec::Core::RakeTask.new(:spec)
|
|
9
|
-
task default: :spec
|
|
10
7
|
|
|
11
|
-
|
|
12
|
-
task :console do
|
|
13
|
-
sh "irb -rubygems -I lib -r reverse_adoc.rb"
|
|
14
|
-
end
|
|
8
|
+
task default: :spec
|
data/lib/reverse_adoc/version.rb
CHANGED
data/lib/reverse_adoc.rb
CHANGED
|
@@ -1,27 +1,22 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
4
|
-
require "
|
|
5
|
-
|
|
6
|
-
require_relative "reverse_adoc/errors"
|
|
7
|
-
require_relative "reverse_adoc/cleaner"
|
|
8
|
-
require_relative "reverse_adoc/config"
|
|
9
|
-
require_relative "reverse_adoc/converters"
|
|
10
|
-
require_relative "reverse_adoc/converters/base"
|
|
11
|
-
require_relative "reverse_adoc/html_converter"
|
|
3
|
+
require "ceradoc"
|
|
4
|
+
require "ceradoc/html"
|
|
5
|
+
require "ceradoc/asciidoc"
|
|
12
6
|
|
|
7
|
+
# Compatibility entry point of the reverse_adoc gem.
|
|
8
|
+
#
|
|
9
|
+
# Since 2.0.0 reverse_adoc ships no converter code of its own: the
|
|
10
|
+
# HTML-to-AsciiDoc engine moved into coradoc and now lives in the ceradoc
|
|
11
|
+
# monorepo as ceradoc-html (coradoc → coridoc → ceradoc, 2026-11-25).
|
|
12
|
+
# Requiring "reverse_adoc" loads that engine and delegates to its unified
|
|
13
|
+
# API, so downstream `require "reverse_adoc"` calls keep working.
|
|
13
14
|
module ReverseAdoc
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def self.
|
|
19
|
-
|
|
20
|
-
yield @config if block_given?
|
|
21
|
-
@config
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def self.cleaner
|
|
25
|
-
@cleaner ||= Cleaner.new
|
|
15
|
+
# Convert HTML to AsciiDoc.
|
|
16
|
+
#
|
|
17
|
+
# Legacy options are accepted for arity compatibility and ignored: the
|
|
18
|
+
# tuning knobs moved into the ceradoc pipeline (see Ceradoc.convert).
|
|
19
|
+
def self.convert(input, *_options)
|
|
20
|
+
Ceradoc.convert(input, from: :html, to: :asciidoc)
|
|
26
21
|
end
|
|
27
22
|
end
|
data/reverse_adoc.gemspec
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
require "reverse_adoc/version"
|
|
3
|
+
require_relative "lib/reverse_adoc/version"
|
|
5
4
|
|
|
6
5
|
Gem::Specification.new do |s|
|
|
7
6
|
s.name = "reverse_adoc"
|
|
@@ -10,8 +9,9 @@ Gem::Specification.new do |s|
|
|
|
10
9
|
s.email = ["open.source@ribose.com"]
|
|
11
10
|
|
|
12
11
|
s.homepage = "http://github.com/metanorma/reverse_adoc"
|
|
13
|
-
s.summary = "
|
|
14
|
-
s.description = "
|
|
12
|
+
s.summary = "Compatibility facade for ceradoc: generate AsciiDoc from HTML."
|
|
13
|
+
s.description = "Compatibility facade for ceradoc: generate AsciiDoc from HTML. " \
|
|
14
|
+
"The former reverse_adoc converter lives in the ceradoc monorepo."
|
|
15
15
|
s.license = "BSD-2-Clause"
|
|
16
16
|
|
|
17
17
|
s.files = `git ls-files`.split("\n")
|
|
@@ -21,22 +21,14 @@ Gem::Specification.new do |s|
|
|
|
21
21
|
end
|
|
22
22
|
s.bindir = "exe"
|
|
23
23
|
s.require_paths = ["lib"]
|
|
24
|
-
|
|
24
|
+
# >= 3.3.0 is the floor every ceradoc gem carries (ceradoc hub,
|
|
25
|
+
# ceradoc-adoc, ceradoc-html); the facade cannot resolve below it.
|
|
26
|
+
s.required_ruby_version = Gem::Requirement.new(">= 3.3.0")
|
|
25
27
|
|
|
26
|
-
#
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
s.add_dependency "
|
|
30
|
-
s.add_dependency "
|
|
31
|
-
s.
|
|
32
|
-
s.add_development_dependency "rake"
|
|
33
|
-
s.add_development_dependency "redcarpet"
|
|
34
|
-
s.add_development_dependency "rspec"
|
|
35
|
-
s.add_development_dependency "simplecov"
|
|
36
|
-
|
|
37
|
-
# spec.add_runtime_dependency "thor"
|
|
38
|
-
|
|
39
|
-
# All the following are for bin/w2m
|
|
40
|
-
s.add_dependency "premailer", "~> 1.11.0"
|
|
41
|
-
s.add_dependency "word-to-markdown"
|
|
28
|
+
# reverse_adoc is a facade: the HTML-to-AsciiDoc engine lives in the
|
|
29
|
+
# ceradoc monorepo (renamed coradoc → coridoc → ceradoc, 2026-11-25).
|
|
30
|
+
# The hub floors follow the metanorma-plugin-lutaml html2adoc precedent.
|
|
31
|
+
s.add_dependency "ceradoc", "~> 3.0"
|
|
32
|
+
s.add_dependency "ceradoc-adoc", "~> 2.0"
|
|
33
|
+
s.add_dependency "ceradoc-html", "~> 1.1"
|
|
42
34
|
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "reverse_adoc"
|
|
4
|
+
|
|
5
|
+
RSpec.describe ReverseAdoc do
|
|
6
|
+
# Inline formatting (<b>/<i>) is currently dropped by ceradoc-html's
|
|
7
|
+
# html→asciidoc path (1.1.25 registers :b on monorepo main only), so
|
|
8
|
+
# these specs assert the surface that converts today: blocks, links,
|
|
9
|
+
# and plain text.
|
|
10
|
+
it "converts headings" do
|
|
11
|
+
expect(described_class.convert("<h1>Hello</h1>")).to include("= Hello")
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "converts paragraph text" do
|
|
15
|
+
expect(described_class.convert("<p>plain paragraph text</p>"))
|
|
16
|
+
.to include("plain paragraph text")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "converts links" do
|
|
20
|
+
expect(described_class.convert("<p>a <a href=\"http://x.example\">link</a></p>"))
|
|
21
|
+
.to include("http://x.example[link]")
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "accepts and ignores a legacy options hash for arity compatibility" do
|
|
25
|
+
expect(described_class.convert("<h1>Hello</h1>", unknown_tags: :raise))
|
|
26
|
+
.to eq(described_class.convert("<h1>Hello</h1>"))
|
|
27
|
+
end
|
|
28
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,25 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
SimpleCov.profiles.define "gem" do
|
|
4
|
-
add_filter "/spec/"
|
|
5
|
-
add_filter "/autotest/"
|
|
6
|
-
add_group "Libraries", "/lib/"
|
|
7
|
-
end
|
|
8
|
-
SimpleCov.start "gem"
|
|
9
|
-
|
|
10
|
-
require "reverse_adoc"
|
|
11
|
-
require "reverse_adoc/html_converter"
|
|
12
|
-
require "word-to-markdown"
|
|
13
|
-
|
|
14
|
-
Dir[File.join("spec", "support", "**", "*.rb")]
|
|
15
|
-
.each { |f| require File.join(".", f) }
|
|
1
|
+
# frozen_string_literal: true
|
|
16
2
|
|
|
17
3
|
RSpec.configure do |config|
|
|
18
|
-
config.
|
|
19
|
-
|
|
4
|
+
config.expect_with :rspec do |expectations|
|
|
5
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
|
20
6
|
end
|
|
21
|
-
end
|
|
22
7
|
|
|
23
|
-
|
|
24
|
-
|
|
8
|
+
config.disable_monkey_patching!
|
|
9
|
+
config.order = :random
|
|
25
10
|
end
|