asciidoctor-html5s 0.1.0.beta.4 → 0.1.0.beta.5

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
- SHA1:
3
- metadata.gz: 819e3a71952cef839eef80a5e236792f4c580554
4
- data.tar.gz: 51f5722fb9a01deae23ac1f4bb2433e565bd72f3
2
+ SHA256:
3
+ metadata.gz: 6edb5fed9a549c826fe6cee650e693100626d9e1ad1fe464c1c35e458f7ee7b0
4
+ data.tar.gz: 80d81e62638bca8e8df3025dac8f6fe8be758941fa8887368acc12b7d8adae95
5
5
  SHA512:
6
- metadata.gz: 8f88f4dbfccc68c008b6ee5e105cb7fcc1aee7ece21ea28932d1bd9dc82b0f0195ff908814c6125f84f095d0fa5b5a37931cc974a9a2fd16b4060220e8f76647
7
- data.tar.gz: 98c9005fbf4e458e836b42be497fb4aaf1f8ade40ac72988a760266b66f66d8032833372b279fa38114872262a8c2bc30e9f47ae517dd49187f53b1ae83cf91a
6
+ metadata.gz: 7aac1db96dd77420ff7e42deefdf378a0f965cc85b61db850cc37e24bbd81ab037371521049cac9315166a581ba2d9bc5aabda6574eb088b50ecac921209f038
7
+ data.tar.gz: 4a9a897ac7ca4fdba8ca69452a8e5c8b1138f69d6f6fa096cd859022609f1955fa40788c79f328c34575c388feb034fcc28a58cf7cd91745fda8f424f8287ff1
data/README.adoc CHANGED
@@ -7,6 +7,7 @@
7
7
  ifdef::env-github[]
8
8
  image:https://travis-ci.org/{gh-name}.svg?branch={gh-branch}[Build Status, link="https://travis-ci.org/{gh-name}"]
9
9
  image:https://img.shields.io/gem/v/{gem-name}.svg?style=flat[Gem Version, link="https://rubygems.org/gems/{gem-name}"]
10
+ image:https://img.shields.io/npm/v/{gem-name}.svg?style=flat[npm Version, link="https://www.npmjs.org/package/{gem-name}"]
10
11
  endif::env-github[]
11
12
 
12
13
  This project provides alternative HTML5 converter (backend) for http://asciidoctor.org/[Asciidoctor] that focuses on correct semantics, accessibility and compatibility with common typographic CSS styles.
@@ -29,15 +30,17 @@ This project provides alternative HTML5 converter (backend) for http://asciidoct
29
30
 
30
31
  == Requirements
31
32
 
32
- * https://www.ruby-lang.org/[Ruby] 2.0+ or http://jruby.org/[JRuby] 9.1+
33
- * https://rubygems.org/gems/asciidoctor/[Asciidoctor] 1.5.5+
34
- * https://rubygems.org/gems/thread_safe/[thread_safe] (not required, but recommended)
33
+ * https://www.ruby-lang.org/[Ruby] 2.0+, http://jruby.org/[JRuby] 9.1+ or https://nodejs.org/[Node.js]
34
+ * https://rubygems.org/gems/asciidoctor/[Asciidoctor] 1.5.5+ or https://www.npmjs.com/package/asciidoctor.js[asciidoctor.js] 1.5.5
35
+ * https://rubygems.org/gems/thread_safe/[thread_safe] (not required, but recommended for Ruby MRI)
35
36
 
36
37
  Note: This converter consists of https://github.com/slim-template/slim/[Slim] templates, but they are precompiled into pure Ruby code using https://github.com/jirutka/asciidoctor-templates-compiler/[asciidoctor-templates-compiler], so you don’t need Slim to use it!
37
38
 
38
39
 
39
40
  == Installation
40
41
 
42
+ === Ruby
43
+
41
44
  Install {gem-name} from Rubygems:
42
45
 
43
46
  [source, sh, subs="+attributes"]
@@ -49,12 +52,37 @@ or to get the latest development version:
49
52
  gem install --pre {gem-name}
50
53
 
51
54
 
55
+ === Node.js
56
+
57
+ Install {gem-name} from npmjs.com:
58
+
59
+ [source, sh, subs="+attributes"]
60
+ npm install --save {gem-name}
61
+
62
+
52
63
  == Usage
53
64
 
65
+ === CLI
66
+
54
67
  [source, sh, subs="+attributes"]
55
68
  asciidoctor -r {gem-name} -b html5s FILE...
56
69
 
57
70
 
71
+ === Node.js
72
+
73
+ [source, js, subs="+attributes"]
74
+ ----
75
+ // Load asciidoctor.js and {gem-name}.
76
+ const asciidoctor = require('asciidoctor.js')()
77
+ require('{gem-name}')
78
+
79
+ // Convert the content to HTML using html5s converter.
80
+ const content = "Hello, *world!*!"
81
+ const html = asciidoctor.convert(content, { backend: 'html5s' })
82
+ console.log(html)
83
+ ----
84
+
85
+
58
86
  == License
59
87
 
60
88
  This project is licensed under http://opensource.org/licenses/MIT/[MIT License].
@@ -1,7 +1,5 @@
1
- require 'asciidoctor'
2
1
  require 'asciidoctor/html5s'
3
- require 'date'
4
- require 'json'
2
+ require 'date' unless RUBY_PLATFORM == 'opal'
5
3
 
6
4
  # Add custom functions to this module that you want to use in your Slim
7
5
  # templates. Within the template you can invoke them as top-level functions
@@ -9,27 +7,31 @@ require 'json'
9
7
  module Slim::Helpers
10
8
 
11
9
  # URIs of external assets.
12
- FONT_AWESOME_URI = '//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css'
13
- HIGHLIGHTJS_BASE_URI = '//cdnjs.cloudflare.com/ajax/libs/highlight.js/7.4'
14
- MATHJAX_JS_URI = '//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_HTMLorMML'
10
+ FONT_AWESOME_URI = '//cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css'
11
+ HIGHLIGHTJS_BASE_URI = '//cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.12.0/build/'
12
+ KATEX_CSS_URI = '//cdn.jsdelivr.net/npm/katex@0.8.3/dist/katex.min.css'
13
+ KATEX_JS_URI = '//cdn.jsdelivr.net/npm/katex@0.8.3/dist/katex.min.js'
15
14
 
16
15
  # Defaults
17
16
  DEFAULT_HIGHLIGHTJS_THEME = 'github'
18
17
  DEFAULT_SECTNUMLEVELS = 3
19
18
  DEFAULT_TOCLEVELS = 2
20
19
 
21
- # The MathJax configuration.
22
- MATHJAX_CONFIG = {
23
- tex2jax: {
24
- inlineMath: [::Asciidoctor::INLINE_MATH_DELIMITERS[:latexmath].inspect],
25
- displayMath: [::Asciidoctor::BLOCK_MATH_DELIMITERS[:latexmath].inspect],
26
- ignoreClass: 'nostem|nolatexmath',
27
- },
28
- asciimath2jax: {
29
- delimiters: [::Asciidoctor::BLOCK_MATH_DELIMITERS[:asciimath].inspect],
30
- ignoreClass: 'nostem|noasciimath',
31
- }
32
- }.to_json
20
+ KATEX_RENDER_CODE = <<-JS.gsub(/\s+/, ' ')
21
+ document.addEventListener("DOMContentLoaded", function() {
22
+ var elements = document.getElementsByClassName("math");
23
+ for (var i = 0; i < elements.length; i++) {
24
+ var el = elements[i];
25
+ if (el.getAttribute("data-lang") !== "tex") {
26
+ continue;
27
+ }
28
+ katex.render(el.textContent.slice(2, -2), el, {
29
+ "displayMode": el.nodeName.toUpperCase() !== "SPAN",
30
+ "throwOnError": false,
31
+ });
32
+ }
33
+ });
34
+ JS
33
35
 
34
36
  VOID_ELEMENTS = %w(area base br col command embed hr img input keygen link
35
37
  meta param source track wbr)
@@ -214,6 +216,9 @@ module Slim::Helpers
214
216
  ##
215
217
  # Delimite the given equation as a STEM of the specified type.
216
218
  #
219
+ # Note: This is not needed nor used for KaTeX, but keep this for the case
220
+ # user wants to use a different method.
221
+ #
217
222
  # @param equation [String] the equation to delimite.
218
223
  # @param type [#to_sym] the type of the STEM renderer (latexmath, or asciimath).
219
224
  # @return [String] the delimited equation.
@@ -360,6 +365,13 @@ module Slim::Helpers
360
365
  end
361
366
  end
362
367
 
368
+ ##
369
+ # @return [String] language of STEM block or inline node (tex or asciimath).
370
+ def stem_lang
371
+ value = (inline? ? type : style).to_s
372
+ value == 'latexmath' ? 'tex' : value
373
+ end
374
+
363
375
  def link_rel
364
376
  'noopener' if option?('noopener') || attr(:window) == '_blank'
365
377
  end
@@ -514,7 +526,7 @@ is book and it's a child of a book part. Excluding block content."
514
526
  # @return [String, nil] the revision date in ISO 8601, or nil if not
515
527
  # available or in invalid format.
516
528
  def revdate_iso
517
- ::Date.parse(revdate).iso8601
529
+ ::Date.parse(revdate).iso8601 if defined? ::Date
518
530
  rescue ArgumentError
519
531
  nil
520
532
  end
@@ -560,8 +572,9 @@ is book and it's a child of a book part. Excluding block content."
560
572
  end
561
573
 
562
574
  if attr? 'stem'
563
- scripts << { src: MATHJAX_JS_URI }
564
- scripts << { type: 'text/x-mathjax-config', text: "MathJax.Hub.Config(#{MATHJAX_CONFIG});" }
575
+ styles << { href: KATEX_CSS_URI }
576
+ scripts << { src: KATEX_JS_URI }
577
+ scripts << { text: KATEX_RENDER_CODE }
565
578
  end
566
579
 
567
580
  case attr 'source-highlighter'
@@ -579,7 +592,6 @@ is book and it's a child of a book part. Excluding block content."
579
592
  hjs_theme = attr 'highlightjs-theme', DEFAULT_HIGHLIGHTJS_THEME
580
593
 
581
594
  scripts << { src: [hjs_base, 'highlight.min.js'] }
582
- scripts << { src: [hjs_base, 'lang/common.min.js'] }
583
595
  scripts << { text: 'hljs.initHighlightingOnLoad()' }
584
596
  styles << { href: [hjs_base, "styles/#{hjs_theme}.min.css"] }
585
597
  end
@@ -20,7 +20,10 @@
20
20
  = html_tag_if role?, :span, :class=>role
21
21
  | &#8216;#{text}&#8217;
22
22
  - when :asciimath, :latexmath
23
- span.math =delimit_stem text, type
23
+ span.math data-lang=stem_lang =(delimit_stem text, type)
24
24
  - else
25
- = html_tag_if role?, :span, :class=>role
26
- =text
25
+ - if role == 'line-through' || role == 'del'
26
+ del =text
27
+ - else
28
+ = html_tag_if role?, :span, :class=>role
29
+ =text
@@ -1,2 +1,2 @@
1
1
  = block_with_caption :top, :class=>'stem-block'
2
- .math =(delimit_stem content, style)
2
+ .math data-lang=stem_lang =(delimit_stem content, style)
@@ -1,5 +1,5 @@
1
1
  require 'asciidoctor/html5s/version'
2
- require 'asciidoctor/extensions'
2
+ require 'asciidoctor/extensions' unless RUBY_PLATFORM == 'opal'
3
3
 
4
4
  module Asciidoctor::Html5s
5
5