kramdown-math-sskatex 1.0.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: eea0ebeb94d328134576b141281e3a6171453e178a89914883741dd791af3500
4
+ data.tar.gz: f146f00e8f64211f8d110b396435360eda48899e73699aea93d7f84670676fac
5
+ SHA512:
6
+ metadata.gz: 06c146ff1190a226bb860d1351dacc328ee20d0e8b261ae908b62f3fe62e375ab3a145e5a4ebd6c6c48e892b1345269c969a926599cd6406ad27bd9024a467d9
7
+ data.tar.gz: e1f11778786850f53c758e3cc8d236faedeb9d384c045ec02ed1bcf12e1c34eda9708aa359953f2ef35ccdf802504c0c9e1ee49ed06b9cecdbac654590ddc73e
@@ -0,0 +1,3 @@
1
+ Count Name
2
+ ======= ====
3
+ 1 Thomas Leitner <t_leitner@gmx.at>
data/COPYING ADDED
@@ -0,0 +1,21 @@
1
+ kramdown-math-sskatex
2
+ Copyright (C) 2019 Thomas Leitner <t_leitner@gmx.at>
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a
5
+ copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included
13
+ in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,10 @@
1
+ # -*- coding: utf-8; frozen_string_literal: true -*-
2
+ #
3
+ #--
4
+ # Copyright (C) 2019 Thomas Leitner <t_leitner@gmx.at>
5
+ #
6
+ # This file is part of kramdown-math-sskatex which is licensed under the MIT.
7
+ #++
8
+ #
9
+
10
+ require 'kramdown/converter/math_engine/sskatex'
@@ -0,0 +1,94 @@
1
+ # -*- coding: utf-8; frozen_string_literal: true -*-
2
+ #
3
+ #--
4
+ # Copyright (C) 2017 Christian Cornelssen <ccorn@1tein.de>
5
+ #
6
+ # This file is part of kramdown-math-sskatex which is licensed under the MIT.
7
+ #++
8
+
9
+ require 'kramdown/converter'
10
+ require 'sskatex'
11
+
12
+ module Kramdown::Converter #:nodoc:
13
+ module MathEngine #:nodoc
14
+
15
+ # Consider this a lightweight alternative to MathjaxNode. Uses KaTeX and ExecJS (via ::SsKaTeX)
16
+ # instead of MathJax and Node.js. Javascript execution context initialization is done only once.
17
+ # As a result, the performance is reasonable.
18
+ module SsKaTeX
19
+
20
+ VERSION = '1.0.0'
21
+
22
+ # Class-level cache for ::SsKaTeX converter state, queried by configuration. Note: KTXC
23
+ # contents may become stale if the contents of used JS files change while the configuration
24
+ # remains unchanged.
25
+ KTXC = ::Kramdown::Utils::LRUCache.new(10)
26
+
27
+ # A logger that routes messages to the debug channel only. No need to create this dynamically.
28
+ DEBUG_LOGGER = lambda {|_level, &expr| warn(expr.call) }
29
+
30
+ class << self
31
+
32
+ private
33
+
34
+ # Given a Kramdown::Converter::Base object _converter_, retrieves the logging options and
35
+ # builds an object usable for ::SsKaTeX#logger. The result is either +nil+ (no logging) or a
36
+ # +Proc+ object which, when given a _level_ (either +:verbose+ or +:debug+) and a block,
37
+ # decides whether logging is enabled, and if so, evaluates the given block for the message
38
+ # and routes that message to the appropriate channels. With <tt>level == :verbose+</tt>,
39
+ # messages are passed to _converter_.warning if the _converter_'s +:verbose+ option is set.
40
+ # All messages are passed to +warn+ if the _converter_'s +:debug+ option is set.
41
+ #
42
+ # Note that the returned logger may contain references to the given _converter_ and is not
43
+ # affected by subsequent changes in the _converter_'s logging options.
44
+ def logger(converter)
45
+ config = converter.options[:math_engine_opts]
46
+ debug = config[:debug]
47
+ if config[:verbose]
48
+ # Need a closure
49
+ lambda do |level, &expr|
50
+ verbose = (level == :verbose)
51
+ msg = expr.call if debug || verbose
52
+ warn(msg) if debug
53
+ converter.warning(msg) if verbose
54
+ end
55
+ elsif debug
56
+ DEBUG_LOGGER
57
+ end
58
+ end
59
+
60
+ # Given a Kramdown::Converter::Base object _converter_, return a ::SsKaTeX converter _sktx_
61
+ # that has been configured with _converter_'s +math_engine_opts+, but not for logging. Cache
62
+ # _sktx_ for reuse, without references to _converter_.
63
+ def katex_conv(converter)
64
+ config = converter.options[:math_engine_opts]
65
+ # Could .reject { |key, _| [:verbose, :debug].include?(key.to_sym) }
66
+ # because the JS engine setup can be reused for different logging settings.
67
+ # But then the +math_engine_opts+ dict would be essentially dup'ed every time,
68
+ # and late activation of logging would miss the initialization if the engine is reused.
69
+ KTXC[config] ||= ::SsKaTeX.new(config)
70
+ end
71
+
72
+ public
73
+
74
+ # The function used by kramdown for rendering TeX math to HTML
75
+ def call(converter, el, opts)
76
+ display_mode = el.options[:category]
77
+ ans = katex_conv(converter).call(el.value, display_mode == :block, &logger(converter))
78
+ attr = el.attr.dup
79
+ attr.delete('xmlns')
80
+ attr.delete('display')
81
+ ans.insert(ans =~ /[[:space:]>]/, converter.html_attributes(attr))
82
+ ans = ' ' * opts[:indent] << ans << "\n" if display_mode == :block
83
+ ans
84
+ end
85
+
86
+ end
87
+
88
+ end
89
+
90
+ end
91
+
92
+ add_math_engine(:sskatex, MathEngine::SsKaTeX)
93
+
94
+ end
@@ -0,0 +1,33 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ #--
4
+ # Copyright (C) 2019 Thomas Leitner <t_leitner@gmx.at>
5
+ #
6
+ # This file is part of kramdown-math-sskatex which is licensed under the MIT.
7
+ #++
8
+ #
9
+
10
+ require 'minitest/autorun'
11
+ require 'kramdown'
12
+ require 'kramdown-math-sskatex'
13
+ require 'yaml'
14
+ require 'tmpdir'
15
+
16
+ Encoding.default_external = 'utf-8'
17
+
18
+ class TestFiles < Minitest::Test
19
+
20
+ Dir[File.dirname(__FILE__) + '/testcases/**/*.text'].each do |text_file|
21
+ basename = text_file.sub(/\.text$/, '')
22
+
23
+ html_file = basename + '.html'
24
+ define_method('test_' + text_file.tr('.', '_') + "_to_html") do
25
+ opts_file = basename + '.options'
26
+ opts_file = File.join(File.dirname(html_file), 'options') if !File.exist?(opts_file)
27
+ options = File.exist?(opts_file) ? YAML::load(File.read(opts_file)) : {auto_ids: false, footnote_nr: 1}
28
+ doc = Kramdown::Document.new(File.read(text_file), options)
29
+ assert_equal(File.read(html_file), doc.to_html)
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1 @@
1
+ <p>Erst einmal eine Formel wie <span class="katex"><span class="katex-mathml"><math><semantics><mrow><msup><mi>a</mi><mn>2</mn></msup><mo>+</mo><msup><mi>b</mi><mn>2</mn></msup><mo>=</mo><msup><mi>c</mi><mn>2</mn></msup></mrow><annotation encoding="application/x-tex">a^2+b^2=c^2</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.8141079999999999em;"></span><span class="strut bottom" style="height:0.897438em;vertical-align:-0.08333em;"></span><span class="base"><span class="mord"><span class="mord mathit">a</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8141079999999999em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathrm mtight">2</span></span></span></span></span></span></span></span><span class="mbin">+</span><span class="mord"><span class="mord mathit">b</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8141079999999999em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathrm mtight">2</span></span></span></span></span></span></span></span><span class="mrel">=</span><span class="mord"><span class="mord mathit">c</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8141079999999999em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathrm mtight">2</span></span></span></span></span></span></span></span></span></span></span> innerhalb eines Satzes.</p>
@@ -0,0 +1 @@
1
+ :math_engine: sskatex
@@ -0,0 +1 @@
1
+ Erst einmal eine Formel wie $$a^2+b^2=c^2$$ innerhalb eines Satzes.
@@ -0,0 +1,2 @@
1
+ <span class="katex-display"><span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi mathvariant="normal">&#x394;</mi><mo>=</mo><mfrac><mrow><mn>1</mn></mrow><mrow><mn>2</mn></mrow></mfrac><mrow><mo fence="true">&#x2223;</mo><mtable><mtr><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mi>a</mi></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mi>b</mi></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mi>c</mi></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mi>d</mi></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mi>e</mi></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mi>f</mi></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mi>g</mi></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mi>h</mi></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mi>i</mi></mrow></mstyle></mtd></mtr></mtable><mo fence="true">&#x2223;</mo></mrow></mrow><annotation encoding="application/x-tex">\Delta = \frac{1}{2}
2
+ \begin{vmatrix}a &amp; b &amp; c \\ d &amp; e &amp; f \\ g &amp; h &amp; i\end{vmatrix}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:2.08597em;"></span><span class="strut bottom" style="height:3.636em;vertical-align:-1.5500299999999998em;"></span><span class="base"><span class="mord mathrm">&#x394;</span><span class="mrel">=</span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.32144em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathrm">2</span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathrm">1</span></span></span></span><span class="vlist-s">&#x200b;</span></span><span class="vlist-r"><span class="vlist" style="height:0.686em;"></span></span></span></span><span class="mclose nulldelimiter"></span></span><span class="minner"><span class="mopen"><span class="delimsizing mult"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:2.08597em;"><span style="top:-1.05597em;"><span class="pstrut" style="height:2.606em;"></span><span class="delimsizinginner delim-size1"><span>&#x2223;</span></span></span><span style="top:-1.6619700000000002em;"><span class="pstrut" style="height:2.606em;"></span><span class="delimsizinginner delim-size1"><span>&#x2223;</span></span></span><span style="top:-2.26797em;"><span class="pstrut" style="height:2.606em;"></span><span class="delimsizinginner delim-size1"><span>&#x2223;</span></span></span><span style="top:-2.87397em;"><span class="pstrut" style="height:2.606em;"></span><span class="delimsizinginner delim-size1"><span>&#x2223;</span></span></span><span style="top:-3.47997em;"><span class="pstrut" style="height:2.606em;"></span><span class="delimsizinginner delim-size1"><span>&#x2223;</span></span></span><span style="top:-4.08597em;"><span class="pstrut" style="height:2.606em;"></span><span class="delimsizinginner delim-size1"><span>&#x2223;</span></span></span></span><span class="vlist-s">&#x200b;</span></span><span class="vlist-r"><span class="vlist" style="height:1.5500299999999998em;"></span></span></span></span></span><span class="mord"><span class="mtable"><span class="col-align-c"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:2.05em;"><span style="top:-4.21em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathit">a</span></span></span><span style="top:-3.0099999999999993em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathit">d</span></span></span><span style="top:-1.8099999999999994em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathit" style="margin-right:0.03588em;">g</span></span></span></span><span class="vlist-s">&#x200b;</span></span><span class="vlist-r"><span class="vlist" style="height:1.5500000000000007em;"></span></span></span></span><span class="arraycolsep" style="width:0.5em;"></span><span class="arraycolsep" style="width:0.5em;"></span><span class="col-align-c"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:2.05em;"><span style="top:-4.21em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathit">b</span></span></span><span style="top:-3.0099999999999993em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathit">e</span></span></span><span style="top:-1.8099999999999994em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathit">h</span></span></span></span><span class="vlist-s">&#x200b;</span></span><span class="vlist-r"><span class="vlist" style="height:1.5500000000000007em;"></span></span></span></span><span class="arraycolsep" style="width:0.5em;"></span><span class="arraycolsep" style="width:0.5em;"></span><span class="col-align-c"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:2.05em;"><span style="top:-4.21em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathit">c</span></span></span><span style="top:-3.0099999999999993em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathit" style="margin-right:0.10764em;">f</span></span></span><span style="top:-1.8099999999999994em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathit">i</span></span></span></span><span class="vlist-s">&#x200b;</span></span><span class="vlist-r"><span class="vlist" style="height:1.5500000000000007em;"></span></span></span></span></span></span><span class="mclose"><span class="delimsizing mult"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:2.08597em;"><span style="top:-1.05597em;"><span class="pstrut" style="height:2.606em;"></span><span class="delimsizinginner delim-size1"><span>&#x2223;</span></span></span><span style="top:-1.6619700000000002em;"><span class="pstrut" style="height:2.606em;"></span><span class="delimsizinginner delim-size1"><span>&#x2223;</span></span></span><span style="top:-2.26797em;"><span class="pstrut" style="height:2.606em;"></span><span class="delimsizinginner delim-size1"><span>&#x2223;</span></span></span><span style="top:-2.87397em;"><span class="pstrut" style="height:2.606em;"></span><span class="delimsizinginner delim-size1"><span>&#x2223;</span></span></span><span style="top:-3.47997em;"><span class="pstrut" style="height:2.606em;"></span><span class="delimsizinginner delim-size1"><span>&#x2223;</span></span></span><span style="top:-4.08597em;"><span class="pstrut" style="height:2.606em;"></span><span class="delimsizinginner delim-size1"><span>&#x2223;</span></span></span></span><span class="vlist-s">&#x200b;</span></span><span class="vlist-r"><span class="vlist" style="height:1.5500299999999998em;"></span></span></span></span></span></span></span></span></span></span>
@@ -0,0 +1 @@
1
+ :math_engine: sskatex
@@ -0,0 +1,2 @@
1
+ $$\Delta = \frac{1}{2}
2
+ \begin{vmatrix}a & b & c \\ d & e & f \\ g & h & i\end{vmatrix}$$
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kramdown-math-sskatex
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Thomas Leitner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-01-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: kramdown
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sskatex
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.37
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.37
41
+ description:
42
+ email: t_leitner@gmx.at
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - CONTRIBUTERS
48
+ - COPYING
49
+ - VERSION
50
+ - lib/kramdown-math-sskatex.rb
51
+ - lib/kramdown/converter/math_engine/sskatex.rb
52
+ - test/test_files.rb
53
+ - test/testcases/sskatex-span.html
54
+ - test/testcases/sskatex-span.options
55
+ - test/testcases/sskatex-span.text
56
+ - test/testcases/sskatex.html
57
+ - test/testcases/sskatex.options
58
+ - test/testcases/sskatex.text
59
+ homepage: https://github.com/kramdown/math-sskatex
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '2.3'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.7.3
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: kramdown-math-sskatex uses katex to convert math elements to HTML+MathML
83
+ on the server side
84
+ test_files: []