kramdown-math-mathjaxnode 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.
- checksums.yaml +7 -0
- data/CONTRIBUTERS +3 -0
- data/COPYING +21 -0
- data/VERSION +1 -0
- data/lib/kramdown-math-mathjaxnode.rb +10 -0
- data/lib/kramdown/converter/math_engine/mathjaxnode.rb +69 -0
- data/test/test_files.rb +33 -0
- data/test/testcases/mathjaxnode-span.html +27 -0
- data/test/testcases/mathjaxnode-span.options +1 -0
- data/test/testcases/mathjaxnode-span.text +1 -0
- data/test/testcases/mathjaxnode.html +27 -0
- data/test/testcases/mathjaxnode.options +1 -0
- data/test/testcases/mathjaxnode.text +1 -0
- data/test/testcases/mathjaxnode_notexhints.html +23 -0
- data/test/testcases/mathjaxnode_notexhints.options +3 -0
- data/test/testcases/mathjaxnode_notexhints.text +1 -0
- data/test/testcases/mathjaxnode_semantics.html +32 -0
- data/test/testcases/mathjaxnode_semantics.options +3 -0
- data/test/testcases/mathjaxnode_semantics.text +1 -0
- metadata +75 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ad99951db7cc187e81f6085d0ce0896b1cb73f42a285b8b98b8c4c3526f6236c
|
4
|
+
data.tar.gz: 2c0d0aac53a3c91c4120701dc0cdf105b62267e1aa8675780acce8f60016ed3e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5fc4264e014c2608cd9b255c3012e48cd13e04fa2359fc1dddf180764fd9e46d6b3dfde255eaf6a0db29001c881ebb8f6d929dfe9a0cfb68a79584a16ad29c9a
|
7
|
+
data.tar.gz: 03a56fe3b29882318a5b7ec14e6d36e130c238d432dedc38417ef94e2081d1e0259beadbda17337f675d6d9fe4b2d5c11ea4980e61db9ae9b3d4470cbac4c0ba
|
data/CONTRIBUTERS
ADDED
data/COPYING
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
kramdown-math-mathjaxnode
|
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-mathjaxnode which is licensed under the MIT.
|
7
|
+
#++
|
8
|
+
#
|
9
|
+
|
10
|
+
require 'kramdown/converter/math_engine/mathjaxnode'
|
@@ -0,0 +1,69 @@
|
|
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-mathjaxnode which is licensed under the MIT.
|
7
|
+
#++
|
8
|
+
#
|
9
|
+
|
10
|
+
require 'kramdown/converter'
|
11
|
+
|
12
|
+
module Kramdown::Converter #:nodoc:
|
13
|
+
module MathEngine #:nodoc
|
14
|
+
|
15
|
+
# Uses the mathjax-node-cli library for converting math formulas to MathML.
|
16
|
+
module MathjaxNode
|
17
|
+
|
18
|
+
VERSION = '1.0.0'
|
19
|
+
|
20
|
+
# MathjaxNode is available if this constant is +true+.
|
21
|
+
AVAILABLE = begin
|
22
|
+
%x{node --version}[1..-2] >= '4.5'
|
23
|
+
rescue
|
24
|
+
begin
|
25
|
+
%x{nodejs --version}[1..-2] >= '4.5'
|
26
|
+
rescue
|
27
|
+
false
|
28
|
+
end
|
29
|
+
end && begin
|
30
|
+
npm = %x{npm --global --depth=1 list mathjax-node-cli 2>&1}
|
31
|
+
|
32
|
+
unless /mathjax-node-cli@/ === npm.lines.drop(1).join("\n")
|
33
|
+
npm = %x{npm --depth=1 list mathjax-node-cli 2>&1}
|
34
|
+
end
|
35
|
+
|
36
|
+
T2MPATH = File.join(npm.lines.first.strip, "node_modules/mathjax-node-cli/bin/tex2mml")
|
37
|
+
/mathjax-node-cli@/ === npm.lines.drop(1).join("\n") && File.exist?(T2MPATH)
|
38
|
+
rescue
|
39
|
+
false
|
40
|
+
end
|
41
|
+
|
42
|
+
unless AVAILABLE
|
43
|
+
raise "Needed dependencies (node, mathjax-node-cli) not found"
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.call(converter, el, opts)
|
47
|
+
type = el.options[:category]
|
48
|
+
|
49
|
+
cmd = [T2MPATH]
|
50
|
+
cmd << "--inline" unless type == :block
|
51
|
+
cmd << "--semantics" if converter.options[:math_engine_opts][:semantics] == true
|
52
|
+
cmd << "--notexhints" if converter.options[:math_engine_opts][:texhints] == false
|
53
|
+
result = IO.popen(cmd << el.value).read.strip
|
54
|
+
|
55
|
+
attr = el.attr.dup
|
56
|
+
attr.delete('xmlns')
|
57
|
+
attr.delete('display')
|
58
|
+
result.insert("<math".length, converter.html_attributes(attr))
|
59
|
+
|
60
|
+
(type == :block ? "#{' '*opts[:indent]}#{result}\n" : result)
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
add_math_engine(:mathjaxnode, MathEngine::MathjaxNode)
|
68
|
+
|
69
|
+
end
|
data/test/test_files.rb
ADDED
@@ -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-mathjaxnode which is licensed under the MIT.
|
7
|
+
#++
|
8
|
+
#
|
9
|
+
|
10
|
+
require 'minitest/autorun'
|
11
|
+
require 'kramdown'
|
12
|
+
require 'kramdown-math-mathjaxnode'
|
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,27 @@
|
|
1
|
+
<p>This is <math xmlns="http://www.w3.org/1998/Math/MathML" alttext="f left-parenthesis x right-parenthesis equals a x cubed plus b x squared plus c x plus d">
|
2
|
+
<mi>f</mi>
|
3
|
+
<mo stretchy="false">(</mo>
|
4
|
+
<mi>x</mi>
|
5
|
+
<mo stretchy="false">)</mo>
|
6
|
+
<mo>=</mo>
|
7
|
+
<mi>a</mi>
|
8
|
+
<mrow class="MJX-TeXAtom-ORD">
|
9
|
+
<msup>
|
10
|
+
<mi>x</mi>
|
11
|
+
<mn>3</mn>
|
12
|
+
</msup>
|
13
|
+
</mrow>
|
14
|
+
<mo>+</mo>
|
15
|
+
<mi>b</mi>
|
16
|
+
<mrow class="MJX-TeXAtom-ORD">
|
17
|
+
<msup>
|
18
|
+
<mi>x</mi>
|
19
|
+
<mn>2</mn>
|
20
|
+
</msup>
|
21
|
+
</mrow>
|
22
|
+
<mo>+</mo>
|
23
|
+
<mi>c</mi>
|
24
|
+
<mi>x</mi>
|
25
|
+
<mo>+</mo>
|
26
|
+
<mi>d</mi>
|
27
|
+
</math> something!</p>
|
@@ -0,0 +1 @@
|
|
1
|
+
:math_engine: mathjaxnode
|
@@ -0,0 +1 @@
|
|
1
|
+
This is $$f(x) = a{x^3} + b{x^2} + cx + d$$ something!
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block" alttext="f left-parenthesis x right-parenthesis equals a x cubed plus b x squared plus c x plus d">
|
2
|
+
<mi>f</mi>
|
3
|
+
<mo stretchy="false">(</mo>
|
4
|
+
<mi>x</mi>
|
5
|
+
<mo stretchy="false">)</mo>
|
6
|
+
<mo>=</mo>
|
7
|
+
<mi>a</mi>
|
8
|
+
<mrow class="MJX-TeXAtom-ORD">
|
9
|
+
<msup>
|
10
|
+
<mi>x</mi>
|
11
|
+
<mn>3</mn>
|
12
|
+
</msup>
|
13
|
+
</mrow>
|
14
|
+
<mo>+</mo>
|
15
|
+
<mi>b</mi>
|
16
|
+
<mrow class="MJX-TeXAtom-ORD">
|
17
|
+
<msup>
|
18
|
+
<mi>x</mi>
|
19
|
+
<mn>2</mn>
|
20
|
+
</msup>
|
21
|
+
</mrow>
|
22
|
+
<mo>+</mo>
|
23
|
+
<mi>c</mi>
|
24
|
+
<mi>x</mi>
|
25
|
+
<mo>+</mo>
|
26
|
+
<mi>d</mi>
|
27
|
+
</math>
|
@@ -0,0 +1 @@
|
|
1
|
+
:math_engine: mathjaxnode
|
@@ -0,0 +1 @@
|
|
1
|
+
$$f(x) = a{x^3} + b{x^2} + cx + d$$
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block" alttext="f left-parenthesis x right-parenthesis equals a x cubed plus b x squared plus c x plus d">
|
2
|
+
<mi>f</mi>
|
3
|
+
<mo stretchy="false">(</mo>
|
4
|
+
<mi>x</mi>
|
5
|
+
<mo stretchy="false">)</mo>
|
6
|
+
<mo>=</mo>
|
7
|
+
<mi>a</mi>
|
8
|
+
<msup>
|
9
|
+
<mi>x</mi>
|
10
|
+
<mn>3</mn>
|
11
|
+
</msup>
|
12
|
+
<mo>+</mo>
|
13
|
+
<mi>b</mi>
|
14
|
+
<msup>
|
15
|
+
<mi>x</mi>
|
16
|
+
<mn>2</mn>
|
17
|
+
</msup>
|
18
|
+
<mo>+</mo>
|
19
|
+
<mi>c</mi>
|
20
|
+
<mi>x</mi>
|
21
|
+
<mo>+</mo>
|
22
|
+
<mi>d</mi>
|
23
|
+
</math>
|
@@ -0,0 +1 @@
|
|
1
|
+
$$f(x) = a{x^3} + b{x^2} + cx + d$$
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block" alttext="f left-parenthesis x right-parenthesis equals a x cubed plus b x squared plus c x plus d">
|
2
|
+
<semantics>
|
3
|
+
<mrow>
|
4
|
+
<mi>f</mi>
|
5
|
+
<mo stretchy="false">(</mo>
|
6
|
+
<mi>x</mi>
|
7
|
+
<mo stretchy="false">)</mo>
|
8
|
+
<mo>=</mo>
|
9
|
+
<mi>a</mi>
|
10
|
+
<mrow class="MJX-TeXAtom-ORD">
|
11
|
+
<msup>
|
12
|
+
<mi>x</mi>
|
13
|
+
<mn>3</mn>
|
14
|
+
</msup>
|
15
|
+
</mrow>
|
16
|
+
<mo>+</mo>
|
17
|
+
<mi>b</mi>
|
18
|
+
<mrow class="MJX-TeXAtom-ORD">
|
19
|
+
<msup>
|
20
|
+
<mi>x</mi>
|
21
|
+
<mn>2</mn>
|
22
|
+
</msup>
|
23
|
+
</mrow>
|
24
|
+
<mo>+</mo>
|
25
|
+
<mi>c</mi>
|
26
|
+
<mi>x</mi>
|
27
|
+
<mo>+</mo>
|
28
|
+
<mi>d</mi>
|
29
|
+
</mrow>
|
30
|
+
<annotation encoding="application/x-tex">f(x) = a{x^3} + b{x^2} + cx + d</annotation>
|
31
|
+
</semantics>
|
32
|
+
</math>
|
@@ -0,0 +1 @@
|
|
1
|
+
$$f(x) = a{x^3} + b{x^2} + cx + d$$
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kramdown-math-mathjaxnode
|
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
|
+
description:
|
28
|
+
email: t_leitner@gmx.at
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- CONTRIBUTERS
|
34
|
+
- COPYING
|
35
|
+
- VERSION
|
36
|
+
- lib/kramdown-math-mathjaxnode.rb
|
37
|
+
- lib/kramdown/converter/math_engine/mathjaxnode.rb
|
38
|
+
- test/test_files.rb
|
39
|
+
- test/testcases/mathjaxnode-span.html
|
40
|
+
- test/testcases/mathjaxnode-span.options
|
41
|
+
- test/testcases/mathjaxnode-span.text
|
42
|
+
- test/testcases/mathjaxnode.html
|
43
|
+
- test/testcases/mathjaxnode.options
|
44
|
+
- test/testcases/mathjaxnode.text
|
45
|
+
- test/testcases/mathjaxnode_notexhints.html
|
46
|
+
- test/testcases/mathjaxnode_notexhints.options
|
47
|
+
- test/testcases/mathjaxnode_notexhints.text
|
48
|
+
- test/testcases/mathjaxnode_semantics.html
|
49
|
+
- test/testcases/mathjaxnode_semantics.options
|
50
|
+
- test/testcases/mathjaxnode_semantics.text
|
51
|
+
homepage: https://github.com/kramdown/math-mathjaxnode
|
52
|
+
licenses:
|
53
|
+
- MIT
|
54
|
+
metadata: {}
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '2.3'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 2.7.3
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: kramdown-math-mathjaxnode uses mathjax-node to convert math elements to MathML
|
75
|
+
test_files: []
|