reverse_adoc 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +25 -4
- data/bin/w2a +1 -0
- data/lib/reverse_asciidoctor/converters/a.rb +6 -2
- data/lib/reverse_asciidoctor/converters/img.rb +9 -5
- data/lib/reverse_asciidoctor/version.rb +1 -1
- data/spec/assets/anchors.html +6 -0
- data/spec/components/anchors_spec.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de7821c8ca445117a045f3c2c28ae78f20a2185f61af5de3fff7ed064dd98c3e
|
4
|
+
data.tar.gz: 53151bcdd028e693da6b496df31c7a7da5ffa1dea8b0ee22696011a91fae074a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ae2e50d201e868dc7caa44a599695c6d03f155dd72013888d3cdee5505b074aa37cfc93cfc96435e43fa9bc0096ed46742dd2ff77280957c99cde1ca6454cee
|
7
|
+
data.tar.gz: 8a628ecfe850737831d5f1e10ef30ee65390f9599d7d75f7323de4ca39445c2d873fbaca49db7178b913d696a8fce85c50ce780a7e1715a37a12dce7c4e63cc4
|
data/README.adoc
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
= AsciiDoc from HTML and Microsoft Word: reverse_adoc
|
2
2
|
|
3
|
-
image:https://img.shields.io/gem/v/
|
4
|
-
image:https://
|
5
|
-
image:https://
|
6
|
-
image:https://
|
3
|
+
image:https://img.shields.io/gem/v/reverse_asciidoctor.svg["Gem Version", link="https://rubygems.org/gems/reverse_asciidoctor"]
|
4
|
+
image:https://travis-ci.com/metanorma/reverse_asciidoctor.svg["Build Status", link="https://travis-ci.com/metanorma/reverse_asciidoctor"]
|
5
|
+
image:https://ci.appveyor.com/api/projects/status/9dui2fs4pc590f4k?svg=true["Appveyor Build Status", link="https://ci.appveyor.com/project/metanorma/reverse-asciidoctor"]
|
6
|
+
image:https://codeclimate.com/github/metanorma/reverse_asciidoctor/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/metanorma/reverse_asciidoctor"]
|
7
|
+
image:https://img.shields.io/github/issues-pr-raw/metanorma/reverse_asciidoctor.svg["Pull Requests", link="https://github.com/metanorma/reverse_asciidoctor/pulls"]
|
8
|
+
image:https://img.shields.io/github/commits-since/metanorma/reverse_asciidoctor/latest.svg["Commits since latest",link="https://github.com/metanorma/reverse_asciidoctor/releases"]
|
7
9
|
|
8
10
|
== Purpose
|
9
11
|
|
@@ -92,6 +94,13 @@ document, and it may not cope with ordered lists or headings with customised app
|
|
92
94
|
For best results, reset the styles in the document you're converting to those in
|
93
95
|
the default `Normal.dot` template.
|
94
96
|
|
97
|
+
NOTE: `w2a` requires the command-line version of LibreOffice, `soffice`. As it turns out,
|
98
|
+
LibreOffice v6 appears to render formulae in HTML as images instead of MathML expressions;
|
99
|
+
use LibreOffice v5. If you have both LibreOffice v5 and LibreOffice v6 installed, make sure
|
100
|
+
that your OS path searches for the LibreOffice v5 version of `soffice` first; e.g. on Mac,
|
101
|
+
include something like `/Applications/LibreOffice5.4.7.2.app/Contents/MacOS` in your PATH
|
102
|
+
environment.
|
103
|
+
|
95
104
|
NOTE: Some information in OOMML is not preserved in the export to MathML from LibreOffice;
|
96
105
|
in particular, font shifts such as double-struck fonts.
|
97
106
|
The LibreOffice exporter does seem to drop some text (possibly associated with
|
@@ -242,6 +251,18 @@ AsciiMath, and fail. But of course, MathJax has no problem with MathML, and some
|
|
242
251
|
on the Asciidoctor output can ensure that the MathML is treated by MathJax (or whatever else
|
243
252
|
uses the output) as such; so this is still much better than nothing for stem processing.
|
244
253
|
|
254
|
+
=== Word cleanup
|
255
|
+
|
256
|
+
This gem is routinely used in the Metanorma project to export Word documents to Asciidoctor.
|
257
|
+
The HTML export from Word that the gem uses, from LibreOffice, is much cleaner than the
|
258
|
+
native HTML 4 export from Word; but it has some infelicities which this gem cleans up:
|
259
|
+
|
260
|
+
* The HTML export has trouble with subscripts, and routinely exports them as headings; the `w2a`
|
261
|
+
script tries to clean them up.
|
262
|
+
* The `w2a` cleans up spaces, but it does not strip them.
|
263
|
+
* Spaces are removed from anchors and cross-references.
|
264
|
+
* Double underscores are removed from anchors and cross-references.
|
265
|
+
* Cross-references to `_GoBack` and to `_Toc` followed by numbers (used to construct tables of contents) are ignored.
|
245
266
|
|
246
267
|
== Ruby library usage
|
247
268
|
|
data/bin/w2a
CHANGED
@@ -66,6 +66,7 @@ ReverseAsciidoctor.config.sourcedir = Dir.mktmpdir
|
|
66
66
|
# puts "ReverseAsciidoctor.config.sourcedir #{ReverseAsciidoctor.config.sourcedir}"
|
67
67
|
|
68
68
|
doc = WordToMarkdown.new(filename, ReverseAsciidoctor.config.sourcedir)
|
69
|
+
#File.open("test.html", "w:UTF-8") { |f| f.write doc.document.html }
|
69
70
|
adoc_content = ReverseAsciidoctor.convert(
|
70
71
|
scrub_whitespace(doc.document.html),
|
71
72
|
WordToMarkdown::REVERSE_MARKDOWN_OPTIONS
|
@@ -9,10 +9,14 @@ module ReverseAsciidoctor
|
|
9
9
|
title = extract_title(node)
|
10
10
|
id = node['id'] || node['name']
|
11
11
|
|
12
|
-
|
12
|
+
id = id&.gsub(/\s/, "")&.gsub(/__+/, "_")
|
13
|
+
|
14
|
+
if /^_Toc\d+$|^_GoBack$/.match id
|
15
|
+
""
|
16
|
+
elsif !id.nil? && !id.empty?
|
13
17
|
"[[#{id}]]"
|
14
18
|
elsif href.to_s.start_with?('#')
|
15
|
-
|
19
|
+
href = href.sub(/^#/, "").gsub(/\s/, "").gsub(/__+/, "_")
|
16
20
|
if name.empty?
|
17
21
|
"<<#{href}>>"
|
18
22
|
else
|
@@ -26,11 +26,15 @@ module ReverseAsciidoctor
|
|
26
26
|
ext = ""
|
27
27
|
|
28
28
|
if imgdata
|
29
|
-
file = Tempfile.
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
file = Tempfile.open(["radoc", ".jpg"]) do |f|
|
30
|
+
begin
|
31
|
+
f.binmode
|
32
|
+
f.write(Base64.strict_decode64(imgdata))
|
33
|
+
f.rewind
|
34
|
+
ext = MimeMagic.by_magic(f)
|
35
|
+
ensure
|
36
|
+
f.close!
|
37
|
+
end
|
34
38
|
end
|
35
39
|
|
36
40
|
image_src_path = file.path
|
data/spec/assets/anchors.html
CHANGED
@@ -14,6 +14,12 @@
|
|
14
14
|
|
15
15
|
some text...
|
16
16
|
|
17
|
+
<a href="#a__b spaced">Double __ anchor with space</a>
|
18
|
+
|
19
|
+
Double __ anchor with space <a id="a__b spaced"/>
|
20
|
+
|
21
|
+
<a id="_Toc12345"/>
|
22
|
+
|
17
23
|
<img src="http://foobar.com/logo.png">
|
18
24
|
<img alt="foobar image" src="http://foobar.com/foobar.png">
|
19
25
|
<img alt="foobar image 2" title="this is the foobar image 2" src="http://foobar.com/foobar2.png">
|
@@ -18,4 +18,8 @@ describe ReverseAsciidoctor do
|
|
18
18
|
it { is_expected.to include ' link <<content2>>internal jumplinks without anchors ' }
|
19
19
|
it { is_expected.to include ' treat [[content]] as bookmarks ' }
|
20
20
|
|
21
|
+
it { is_expected.to include "<<a_bspaced,Double \\_\\_ anchor with space>>" }
|
22
|
+
it { is_expected.to include "[[a_bspaced]]" }
|
23
|
+
it { is_expected.not_to include "[[_Toc12345]]" }
|
24
|
+
|
21
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reverse_adoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|