asciidoctor-html5s 0.1.0.beta.9 → 0.1.0.beta.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +82 -0
- data/data/templates/helpers.rb +33 -2
- data/data/templates/inline_quoted.html.slim +2 -2
- data/lib/asciidoctor/html5s.rb +1 -0
- data/lib/asciidoctor/html5s/converter.rb +35 -4
- data/lib/asciidoctor/html5s/replacements.rb +15 -0
- data/lib/asciidoctor/html5s/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9dd49e828ffd4bb710c4d52a5f5bb290b5a3a83a9c5f8914bfc57750445d7c4
|
4
|
+
data.tar.gz: 9c22dddaab49d8bd4bf19c46431f8682bf0bb7747a568982863818c09df514ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4da3a9fe59f111342e69c30c03852a66a61e48140a81d236fc69201d312858338e3870def8af77bf1b1c2080b21bf957c10742c4b0348526a68af2b2d1ac851b
|
7
|
+
data.tar.gz: 14111e7154edd3c1cfc12e330133ff5011576f7701b1e9a4e460e4ebb175e539f9c12d9d7e6ea568fe0e35d6fc4ad6c453ef301d44d0e6ec0eec66e494a87c1a
|
data/README.adoc
CHANGED
@@ -28,6 +28,88 @@ This project provides alternative HTML5 converter (backend) for http://asciidoct
|
|
28
28
|
* Compatibility with existing Asciidoctor CSS styles.
|
29
29
|
|
30
30
|
|
31
|
+
== Text Substitutions
|
32
|
+
|
33
|
+
=== Quotes
|
34
|
+
|
35
|
+
Asciidoctor provides syntax for so-called https://asciidoctor.org/docs/user-manual/#curved[“curved quotation marks”] (which are actually just the _correct_ quotation marks), but the built-in converters outputs only one (hard-coded) type of the single/double quotation marks -- that one used in English and few other languages.
|
36
|
+
This converter outputs the correct type of the quotation marks based on the specified language (using standard `lang` attribute).
|
37
|
+
|
38
|
+
|
39
|
+
[cols="2,^1l,3,^1l,^1"]
|
40
|
+
|===
|
41
|
+
| Name | Syntax | Languages (:lang:) | HTML | Rendered
|
42
|
+
|
43
|
+
.4+| double quotes
|
44
|
+
.4+| "`word`"
|
45
|
+
| af, en, eo, ga, hi, ia, id, ko, mt, th, tr, zh
|
46
|
+
| “word”
|
47
|
+
| “word”
|
48
|
+
|
49
|
+
| bs, fi, sv
|
50
|
+
| ”word”
|
51
|
+
| ”word”
|
52
|
+
|
53
|
+
| cs, da, de, is, lt, sl, sk, sr
|
54
|
+
| „word“
|
55
|
+
| „word“
|
56
|
+
|
57
|
+
| hu, pl, nl, ro
|
58
|
+
| „word”
|
59
|
+
| „word”
|
60
|
+
|
61
|
+
.5+| single quotes
|
62
|
+
.5+| '`word`'
|
63
|
+
| af, en, eo, ga, hi, ia, id, ko, mt, th, tr, zh
|
64
|
+
| ‘word’
|
65
|
+
| ‘word’
|
66
|
+
|
67
|
+
| bs, fi, sv
|
68
|
+
| ’word’
|
69
|
+
| ’word’
|
70
|
+
|
71
|
+
| cs, da, de, is, lt, sl, sk, sr
|
72
|
+
| ‚word‘
|
73
|
+
| ‚word‘
|
74
|
+
|
75
|
+
| nl
|
76
|
+
| ‚word’
|
77
|
+
| ‚word’
|
78
|
+
|
79
|
+
| hu, pl, ro
|
80
|
+
| «word»
|
81
|
+
| «word»
|
82
|
+
|===
|
83
|
+
|
84
|
+
The default (fallback) type is the first one.
|
85
|
+
|
86
|
+
|
87
|
+
=== Replacements
|
88
|
+
|
89
|
+
Asciidoctor replaces `--` with em dash (—) and does not provide any replacement for en dash (–).
|
90
|
+
That’s not very convenient, because en dash is more common than em dash; at least in (British) English and Czech (actually we don’t use em dash at all).
|
91
|
+
So this extension also modifies the https://asciidoctor.org/docs/user-manual/#replacements[replacements table]: changes `--` to en dash and adds `---` for em dash.
|
92
|
+
|
93
|
+
[cols="2,^1l,^1l,^1,2"]
|
94
|
+
|===
|
95
|
+
| Name | Syntax | Unicode | Rendered | Notes
|
96
|
+
|
97
|
+
| En dash
|
98
|
+
| --
|
99
|
+
| –
|
100
|
+
| –
|
101
|
+
.2+| Only replaced if between two word characters, between a word character and a line boundary, or flanked by spaces.
|
102
|
+
|
103
|
+
When flanked by space characters (e.g. `+a -- b+` or `+a --- b+`), the normal spaces are replaced by thin spaces (\ ).
|
104
|
+
|
105
|
+
| Em dash
|
106
|
+
| ---
|
107
|
+
| —
|
108
|
+
| —
|
109
|
+
|
110
|
+
|===
|
111
|
+
|
112
|
+
|
31
113
|
== Requirements
|
32
114
|
|
33
115
|
* https://www.ruby-lang.org/[Ruby] 2.0+, http://jruby.org/[JRuby] 9.1+ or https://nodejs.org/[Node.js]
|
data/data/templates/helpers.rb
CHANGED
@@ -10,14 +10,27 @@ module Slim::Helpers
|
|
10
10
|
# URIs of external assets.
|
11
11
|
FONT_AWESOME_URI = '//cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css'
|
12
12
|
HIGHLIGHTJS_BASE_URI = '//cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.12.0/build/'
|
13
|
-
KATEX_CSS_URI = '//cdn.jsdelivr.net/npm/katex@0.
|
14
|
-
KATEX_JS_URI = '//cdn.jsdelivr.net/npm/katex@0.
|
13
|
+
KATEX_CSS_URI = '//cdn.jsdelivr.net/npm/katex@0.9.0/dist/katex.min.css'
|
14
|
+
KATEX_JS_URI = '//cdn.jsdelivr.net/npm/katex@0.9.0/dist/katex.min.js'
|
15
15
|
|
16
16
|
# Defaults
|
17
17
|
DEFAULT_HIGHLIGHTJS_THEME = 'github'
|
18
|
+
DEFAULT_LANG = 'en'
|
18
19
|
DEFAULT_SECTNUMLEVELS = 3
|
19
20
|
DEFAULT_TOCLEVELS = 2
|
20
21
|
|
22
|
+
CURLY_QUOTES = [
|
23
|
+
[%w[af en eo ga hi ia id ko mt th tr zh], ['‘', '’', '“', '”']], # ‘…’ “…”
|
24
|
+
[%w[bs fi sv], ['’', '’', '”', '”']], # ’…’ ”…”
|
25
|
+
[%w[cs da de is lt sl sk sr], ['‚', '‘', '„', '“']], # ‚…‘ „…“
|
26
|
+
[%w[nl], ['‚', '’', '„', '”']], # ‚…’ „…”
|
27
|
+
[%w[hu pl ro], ['«', '»', '„', '”']], # «…» „…”
|
28
|
+
].reduce({}) do |hsh, (langs, codes)|
|
29
|
+
langs.each { |lang| hsh[lang] = codes }
|
30
|
+
hsh
|
31
|
+
end
|
32
|
+
CURLY_QUOTES.default = CURLY_QUOTES[DEFAULT_LANG]
|
33
|
+
|
21
34
|
KATEX_RENDER_CODE = <<-JS.gsub(/\s+/, ' ')
|
22
35
|
document.addEventListener("DOMContentLoaded", function() {
|
23
36
|
var elements = document.getElementsByClassName("math");
|
@@ -669,4 +682,22 @@ is book and it's a child of a book part. Excluding block content."
|
|
669
682
|
("fa-flip-#{attr :flip}" if attr? :flip)
|
670
683
|
].compact
|
671
684
|
end
|
685
|
+
|
686
|
+
#--------------------------------------------------------
|
687
|
+
# inline_quoted
|
688
|
+
#
|
689
|
+
|
690
|
+
# @param text [String] the text to wrap in double quotes.
|
691
|
+
# @return [String] quoted *text*.
|
692
|
+
def double_quoted(text)
|
693
|
+
quotes = CURLY_QUOTES[attr(:lang, DEFAULT_LANG, true)]
|
694
|
+
"#{quotes[2]}#{text}#{quotes[3]}"
|
695
|
+
end
|
696
|
+
|
697
|
+
# @param text [String] the text to wrap in single quotes.
|
698
|
+
# @return [String] quoted *text*.
|
699
|
+
def single_quoted(text)
|
700
|
+
quotes = CURLY_QUOTES[attr(:lang, DEFAULT_LANG, true)]
|
701
|
+
"#{quotes[0]}#{text}#{quotes[1]}"
|
702
|
+
end
|
672
703
|
end
|
@@ -15,10 +15,10 @@
|
|
15
15
|
mark class=role =text
|
16
16
|
- when :double
|
17
17
|
= html_tag_if role?, :span, :class=>role
|
18
|
-
|
18
|
+
=(double_quoted text)
|
19
19
|
- when :single
|
20
20
|
= html_tag_if role?, :span, :class=>role
|
21
|
-
|
21
|
+
=(single_quoted text)
|
22
22
|
- when :asciimath, :latexmath
|
23
23
|
span.math data-lang=stem_lang =(delimit_stem text, type)
|
24
24
|
- else
|
data/lib/asciidoctor/html5s.rb
CHANGED
@@ -17,14 +17,27 @@ class Asciidoctor::Html5s::Converter < ::Asciidoctor::Converter::Base
|
|
17
17
|
# URIs of external assets.
|
18
18
|
FONT_AWESOME_URI = '//cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css'
|
19
19
|
HIGHLIGHTJS_BASE_URI = '//cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.12.0/build/'
|
20
|
-
KATEX_CSS_URI = '//cdn.jsdelivr.net/npm/katex@0.
|
21
|
-
KATEX_JS_URI = '//cdn.jsdelivr.net/npm/katex@0.
|
20
|
+
KATEX_CSS_URI = '//cdn.jsdelivr.net/npm/katex@0.9.0/dist/katex.min.css'
|
21
|
+
KATEX_JS_URI = '//cdn.jsdelivr.net/npm/katex@0.9.0/dist/katex.min.js'
|
22
22
|
|
23
23
|
# Defaults
|
24
24
|
DEFAULT_HIGHLIGHTJS_THEME = 'github'
|
25
|
+
DEFAULT_LANG = 'en'
|
25
26
|
DEFAULT_SECTNUMLEVELS = 3
|
26
27
|
DEFAULT_TOCLEVELS = 2
|
27
28
|
|
29
|
+
CURLY_QUOTES = [
|
30
|
+
[%w[af en eo ga hi ia id ko mt th tr zh], ['‘', '’', '“', '”']], # ‘…’ “…”
|
31
|
+
[%w[bs fi sv], ['’', '’', '”', '”']], # ’…’ ”…”
|
32
|
+
[%w[cs da de is lt sl sk sr], ['‚', '‘', '„', '“']], # ‚…‘ „…“
|
33
|
+
[%w[nl], ['‚', '’', '„', '”']], # ‚…’ „…”
|
34
|
+
[%w[hu pl ro], ['«', '»', '„', '”']], # «…» „…”
|
35
|
+
].reduce({}) do |hsh, (langs, codes)|
|
36
|
+
langs.each { |lang| hsh[lang] = codes }
|
37
|
+
hsh
|
38
|
+
end
|
39
|
+
CURLY_QUOTES.default = CURLY_QUOTES[DEFAULT_LANG]
|
40
|
+
|
28
41
|
KATEX_RENDER_CODE = <<-JS.gsub(/\s+/, ' ')
|
29
42
|
document.addEventListener("DOMContentLoaded", function() {
|
30
43
|
var elements = document.getElementsByClassName("math");
|
@@ -676,6 +689,24 @@ class Asciidoctor::Html5s::Converter < ::Asciidoctor::Converter::Base
|
|
676
689
|
("fa-flip-#{attr :flip}" if attr? :flip)
|
677
690
|
].compact
|
678
691
|
end
|
692
|
+
|
693
|
+
#--------------------------------------------------------
|
694
|
+
# inline_quoted
|
695
|
+
#
|
696
|
+
|
697
|
+
# @param text [String] the text to wrap in double quotes.
|
698
|
+
# @return [String] quoted *text*.
|
699
|
+
def double_quoted(text)
|
700
|
+
quotes = CURLY_QUOTES[attr(:lang, DEFAULT_LANG, true)]
|
701
|
+
"#{quotes[2]}#{text}#{quotes[3]}"
|
702
|
+
end
|
703
|
+
|
704
|
+
# @param text [String] the text to wrap in single quotes.
|
705
|
+
# @return [String] quoted *text*.
|
706
|
+
def single_quoted(text)
|
707
|
+
quotes = CURLY_QUOTES[attr(:lang, DEFAULT_LANG, true)]
|
708
|
+
"#{quotes[0]}#{text}#{quotes[1]}"
|
709
|
+
end
|
679
710
|
end
|
680
711
|
|
681
712
|
|
@@ -1121,10 +1152,10 @@ class Asciidoctor::Html5s::Converter < ::Asciidoctor::Converter::Base
|
|
1121
1152
|
; _buf << ("<mark"); _temple_html_attributeremover6 = []; _slim_codeattributes7 = role; if Array === _slim_codeattributes7; _slim_codeattributes7 = _slim_codeattributes7.flatten; _slim_codeattributes7.map!(&:to_s); _slim_codeattributes7.reject!(&:empty?); _temple_html_attributeremover6 << (_slim_codeattributes7.join(" ")); else; _temple_html_attributeremover6 << (_slim_codeattributes7); end; _temple_html_attributeremover6 = _temple_html_attributeremover6.join(""); if !_temple_html_attributeremover6.empty?; _buf << (" class=\""); _buf << (_temple_html_attributeremover6); _buf << ("\""); end; _buf << (">"); _buf << (text);
|
1122
1153
|
; _buf << ("</mark>"); when :double;
|
1123
1154
|
; _slim_controls1 = html_tag_if role?, :span, :class=>role do; _slim_controls2 = [];
|
1124
|
-
; _slim_controls2 << (
|
1155
|
+
; _slim_controls2 << ((double_quoted text));
|
1125
1156
|
; _slim_controls2 = _slim_controls2.join(""); end; _buf << (_slim_controls1); when :single;
|
1126
1157
|
; _slim_controls3 = html_tag_if role?, :span, :class=>role do; _slim_controls4 = [];
|
1127
|
-
; _slim_controls4 << (
|
1158
|
+
; _slim_controls4 << ((single_quoted text));
|
1128
1159
|
; _slim_controls4 = _slim_controls4.join(""); end; _buf << (_slim_controls3); when :asciimath, :latexmath;
|
1129
1160
|
; _buf << ("<span class=\"math\""); _slim_codeattributes8 = stem_lang; if _slim_codeattributes8; if _slim_codeattributes8 == true; _buf << (" data-lang"); else; _buf << (" data-lang=\""); _buf << (_slim_codeattributes8); _buf << ("\""); end; end; _buf << (">"); _buf << ((delimit_stem text, type));
|
1130
1161
|
; _buf << ("</span>"); else;
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'asciidoctor' unless RUBY_PLATFORM == 'opal'
|
2
|
+
|
3
|
+
module Asciidoctor
|
4
|
+
# XXX: Modifies constant defined in Asciidoctor.
|
5
|
+
REPLACEMENTS.unshift(
|
6
|
+
# foo --- bar ->  — 
|
7
|
+
[/(^|\n| |\\)---( |\n|$)/, ' — ', :none],
|
8
|
+
# foo---bar -> —{ZERO WIDTH SPACE}
|
9
|
+
[/(#{CG_WORD})\\?---(?=#{CG_WORD})/, '—​', :leading],
|
10
|
+
# foo -- bar -> &thinksp;– 
|
11
|
+
[/(^|\n| |\\)--( |\n|$)/, ' – ', :none],
|
12
|
+
# foo--bar -> –
|
13
|
+
[/(#{CG_WORD})\\?--(?=#{CG_WORD})/, '–', :leading],
|
14
|
+
)
|
15
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asciidoctor-html5s
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.beta.
|
4
|
+
version: 0.1.0.beta.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jakub Jirutka
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|
@@ -201,6 +201,7 @@ files:
|
|
201
201
|
- lib/asciidoctor/html5s/attached_colist_treeprocessor.rb
|
202
202
|
- lib/asciidoctor/html5s/converter.rb
|
203
203
|
- lib/asciidoctor/html5s/logger.rb
|
204
|
+
- lib/asciidoctor/html5s/replacements.rb
|
204
205
|
- lib/asciidoctor/html5s/version.rb
|
205
206
|
homepage: https://github.com/jirutka/asciidoctor-html5s
|
206
207
|
licenses:
|