asciidoctor-katex-2 0.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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/asciidoctor-katex-2.rb +90 -0
  3. metadata +58 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d636e79ff0b770e3644ebfa0abb1151881e6b045609bc94226d22e2d72f269b9
4
+ data.tar.gz: 1fe11bcccf37b232fdcd9ab39ca39d65b604a6c65159af85feb3e7e9c59c2e34
5
+ SHA512:
6
+ metadata.gz: 7e79f3a97655ddf51511e9e3c9769bf772de61fb0c4b8ca309766f1c2dffb44b97611491fab2f54f3e84260ad8abd17b9a89b52fbcf62260a34c05f30702b495
7
+ data.tar.gz: d6915248e11746ba7cbe4f1d26aa2c92be84d1e51aedbfd45c7b7dc4c7e8b4f70a49459f97aa7ee4c80ab60e8b3ae8c4f4f27aba3fba2d3e0dd0629a694ad784
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'asciidoctor'
4
+ require 'asciidoctor/extensions'
5
+ require 'schmooze'
6
+
7
+ class KatexSchmoozer < Schmooze::Base
8
+ dependencies katex: 'katex'
9
+
10
+ # We need this because Schmooze cannot serialize macros
11
+ # due to circular reference at: macros['key'].token[0].loc
12
+ # which is a complex class.
13
+ #
14
+ # Also keeping it in the JavaScript is the most efficient thing we can do.
15
+ #
16
+ # Setting a property of katex because I don't know how to create globals from
17
+ # a function in Node: but we already have this katex global lying around.
18
+ method :init, <<-'EOS'
19
+ function() {
20
+ katex.cirosantilli_macros = {
21
+ "\\cirosantilliApiMacro": "cirosantilli \\ #1 \\ api \\ #2 \\ macro",
22
+ };
23
+ }
24
+ EOS
25
+ method :renderToString, <<-'EOS'
26
+ function(latex) {
27
+ return katex.renderToString(
28
+ latex,
29
+ {
30
+ macros: katex.cirosantilli_macros,
31
+ throwOnError: true
32
+ }
33
+ )
34
+ }
35
+ EOS
36
+ end
37
+ $katex = KatexSchmoozer.new('.')
38
+ $katex.init
39
+
40
+ class KatexBlockProcessor < Asciidoctor::Extensions::BlockProcessor
41
+ use_dsl
42
+ named :katex
43
+ on_context :literal
44
+ parse_content_as :raw
45
+ def process parent, reader, attrs
46
+ html = $katex.renderToString(reader.lines.join("\n"))
47
+ create_paragraph parent, html, attrs, subs: nil
48
+ end
49
+ end
50
+
51
+ class KatexBlockMacroProcessor < Asciidoctor::Extensions::BlockMacroProcessor
52
+ use_dsl
53
+ named :katex
54
+ def process parent, target, attrs
55
+ html = $katex.renderToString(attrs[1])
56
+ create_paragraph parent, html, attrs, subs: nil
57
+ end
58
+ end
59
+
60
+ class KatexInlineMacroProcessor < Asciidoctor::Extensions::InlineMacroProcessor
61
+ use_dsl
62
+ named :katex
63
+ using_format :short
64
+ def process parent, target, attrs
65
+ html = $katex.renderToString(attrs[1])
66
+ create_inline parent, :quoted, html
67
+ end
68
+ end
69
+
70
+ class KatexDocinfoProcessor < Asciidoctor::Extensions::DocinfoProcessor
71
+ use_dsl
72
+ def process doc
73
+ %{<link
74
+ rel="stylesheet"
75
+ href="https://cdn.jsdelivr.net/npm/katex@#{doc.attributes.fetch('katex-version', '0.10.2')}/dist/katex.min.css"
76
+ crossorigin="anonymous"
77
+ >
78
+ <style>
79
+ .katex { font-size: #{doc.attributes.fetch('katex-font-size', '1.5em')}; }
80
+ </style>
81
+ }
82
+ end
83
+ end
84
+
85
+ Asciidoctor::Extensions.register do
86
+ block KatexBlockProcessor
87
+ block_macro KatexBlockMacroProcessor
88
+ docinfo_processor KatexDocinfoProcessor
89
+ inline_macro KatexInlineMacroProcessor
90
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asciidoctor-katex-2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ciro Santilli
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-08-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: asciidoctor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.10
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.10
27
+ description:
28
+ email:
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/asciidoctor-katex-2.rb
34
+ homepage: https://github.com/cirosantilli/asciidoctor-katex-2
35
+ licenses:
36
+ - MIT
37
+ metadata: {}
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubygems_version: 3.0.1
54
+ signing_key:
55
+ specification_version: 4
56
+ summary: Asciidoctor extension to render Katex mathematics server side to HTML fast
57
+ with Schmooze
58
+ test_files: []