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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9949bf88aa17ad0064e393ab78e67057841e1b1da5a5fa1cdd3d916e0c203c94
4
- data.tar.gz: fa1298c9b61194d9e2e21883580654008e5e5c576b77b71ac04ee4340c92f626
3
+ metadata.gz: a9dd49e828ffd4bb710c4d52a5f5bb290b5a3a83a9c5f8914bfc57750445d7c4
4
+ data.tar.gz: 9c22dddaab49d8bd4bf19c46431f8682bf0bb7747a568982863818c09df514ac
5
5
  SHA512:
6
- metadata.gz: cd4f1dc8b891c1af710b7a71f0460d696d3b1b4407339324f9968f7eed7b42699e77caf240bdb409cd7d550a21ef9ec39047139b1536f50496c04321f13c5fc4
7
- data.tar.gz: e8f0a3088f2da2e244194592f932497b9dc55a6390ab6825e7261daa6e676ae8a8c0d8c71f3d45fa1d63a5e6379ede5b397e36ee6bf84a4afb81e34ded930d8b
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]
@@ -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.8.3/dist/katex.min.css'
14
- KATEX_JS_URI = '//cdn.jsdelivr.net/npm/katex@0.8.3/dist/katex.min.js'
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
- | &#8220;#{text}&#8221;
18
+ =(double_quoted text)
19
19
  - when :single
20
20
  = html_tag_if role?, :span, :class=>role
21
- | &#8216;#{text}&#8217;
21
+ =(single_quoted text)
22
22
  - when :asciimath, :latexmath
23
23
  span.math data-lang=stem_lang =(delimit_stem text, type)
24
24
  - else
@@ -1,5 +1,6 @@
1
1
  require 'asciidoctor/html5s/version'
2
2
  require 'asciidoctor/html5s/converter'
3
+ require 'asciidoctor/html5s/replacements'
3
4
  require 'asciidoctor/html5s/attached_colist_treeprocessor'
4
5
 
5
6
  unless RUBY_PLATFORM == 'opal'
@@ -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.8.3/dist/katex.min.css'
21
- KATEX_JS_URI = '//cdn.jsdelivr.net/npm/katex@0.8.3/dist/katex.min.js'
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], ['&#x2018;', '&#x2019;', '&#x201c;', '&#x201d;']], # ‘…’ “…”
31
+ [%w[bs fi sv], ['&#x2019;', '&#x2019;', '&#x201d;', '&#x201d;']], # ’…’ ”…”
32
+ [%w[cs da de is lt sl sk sr], ['&#x201a;', '&#x2018;', '&#x201e;', '&#x201c;']], # ‚…‘ „…“
33
+ [%w[nl], ['&#x201a;', '&#x2019;', '&#x201e;', '&#x201d;']], # ‚…’ „…”
34
+ [%w[hu pl ro], ['&#x00ab;', '&#x00bb;', '&#x201e;', '&#x201d;']], # «…» „…”
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 << ("&#8220;"); _slim_controls2 << (text); _slim_controls2 << ("&#8221;");
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 << ("&#8216;"); _slim_controls4 << (text); _slim_controls4 << ("&#8217;");
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 -> &thinsp;&mdash;&thinsp;
7
+ [/(^|\n| |\\)---( |\n|$)/, '&#8201;&#8212;&#8201;', :none],
8
+ # foo---bar -> &mdash;{ZERO WIDTH SPACE}
9
+ [/(#{CG_WORD})\\?---(?=#{CG_WORD})/, '&#8212;&#8203;', :leading],
10
+ # foo -- bar -> &thinksp;&ndash;&thinsp;
11
+ [/(^|\n| |\\)--( |\n|$)/, '&#8201;&#8211;&#8201;', :none],
12
+ # foo--bar -> &ndash;
13
+ [/(#{CG_WORD})\\?--(?=#{CG_WORD})/, '&#8211;', :leading],
14
+ )
15
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Asciidoctor
4
4
  module Html5s
5
- VERSION = '0.1.0.beta.9'
5
+ VERSION = '0.1.0.beta.10'
6
6
  end
7
7
  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.9
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-09-28 00:00:00.000000000 Z
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: