asciidoctor-mathematical 0.3.4 → 0.3.5
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 +4 -4
- data/lib/asciidoctor-mathematical/extension.rb +40 -78
- metadata +5 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 820fa9ac5cbaa532408ba0899efae0ce7f2b216c2904159dfc3f417687f387ed
|
4
|
+
data.tar.gz: d34b290453b87eba7a3ce17d17d542f6123a3a3c3dce26372d87d22d1e4652d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24b48818b3d70344a114d2c2221d118eb49a4702d6dca8094d9394a7a55ba5f640e4b693cf3bdabeadbfa25a584b61697e4686a06deabd95d4d27379d60b227e
|
7
|
+
data.tar.gz: 884c13bfae4d298b14e42770f93e49698328bbaff4c4f0341ce9b9aae5992619ea1b80d1d1759a26bd3d19d5ea7241d4e38082065f0534ffd225a13a9f51e855
|
@@ -7,20 +7,20 @@ autoload :Mathematical, 'mathematical'
|
|
7
7
|
|
8
8
|
class MathematicalTreeprocessor < Asciidoctor::Extensions::Treeprocessor
|
9
9
|
LineFeed = %(\n)
|
10
|
-
StemInlineMacroRx = /\\?(
|
11
|
-
LatexmathInlineMacroRx = /\\?latexmath:([a-z,]*)\[(.*?[^\\])\]/m
|
12
|
-
AsciiMathInlineMacroRx = /\\?asciimath:([a-z,]*)\[(.*?[^\\])\]/m
|
10
|
+
StemInlineMacroRx = /\\?(stem|(?:latex|ascii)math):([a-z,]*)\[(.*?[^\\])\]/m
|
13
11
|
|
14
12
|
def process document
|
13
|
+
return unless document.attr? 'stem'
|
14
|
+
|
15
15
|
format = ((document.attr 'mathematical-format') || 'png').to_sym
|
16
|
-
|
16
|
+
unless format == :png || format == :svg
|
17
17
|
warn %(Unknown format '#{format}', retreat to 'png')
|
18
18
|
format = :png
|
19
19
|
end
|
20
20
|
ppi = ((document.attr 'mathematical-ppi') || '300.0').to_f
|
21
21
|
ppi = format == :png ? ppi : 72.0
|
22
22
|
inline = document.attr 'mathematical-inline'
|
23
|
-
if inline
|
23
|
+
if inline && format == :png
|
24
24
|
warn 'Can\'t use mathematical-inline together with mathematical-format=png'
|
25
25
|
end
|
26
26
|
# The no-args constructor defaults to SVG and standard delimiters ($..$ for inline, $$..$$ for block)
|
@@ -30,41 +30,22 @@ class MathematicalTreeprocessor < Asciidoctor::Extensions::Treeprocessor
|
|
30
30
|
::Asciidoctor::Helpers.mkdir_p image_output_dir unless ::File.directory? image_output_dir
|
31
31
|
end
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
handle_stem_block stem, mathematical, image_output_dir, image_target_dir, format, inline
|
36
|
-
end
|
33
|
+
(document.find_by context: :stem, traverse_documents: true).each do |stem|
|
34
|
+
handle_stem_block stem, mathematical, image_output_dir, image_target_dir, format, inline
|
37
35
|
end
|
38
36
|
|
39
|
-
|
37
|
+
document.find_by(traverse_documents: true) {|b|
|
40
38
|
(b.content_model == :simple && (b.subs.include? :macros)) || b.context == :list_item
|
41
|
-
}
|
42
|
-
|
43
|
-
handle_prose_block prose, mathematical, image_output_dir, image_target_dir, format, inline
|
44
|
-
end
|
39
|
+
}.each do |prose|
|
40
|
+
handle_prose_block prose, mathematical, image_output_dir, image_target_dir, format, inline
|
45
41
|
end
|
46
42
|
|
47
|
-
|
48
|
-
|
49
|
-
unless (table_blocks = document.find_by context: :table).nil_or_empty?
|
50
|
-
table_blocks.each do |table|
|
51
|
-
(table.rows[:body] + table.rows[:foot]).each do |row|
|
52
|
-
row.each do |cell|
|
53
|
-
if cell.style == :asciidoc
|
54
|
-
process cell.inner_document
|
55
|
-
elsif cell.style != :literal
|
56
|
-
handle_nonasciidoc_table_cell cell, mathematical, image_output_dir, image_target_dir, format, inline
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
43
|
+
(document.find_by content: :section).each do |sect|
|
44
|
+
handle_section_title sect, mathematical, image_output_dir, image_target_dir, format, inline
|
61
45
|
end
|
62
46
|
|
63
|
-
|
64
|
-
|
65
|
-
handle_section_title sect, mathematical, image_output_dir, image_target_dir, format, inline
|
66
|
-
end
|
67
|
-
end
|
47
|
+
document.remove_attr 'stem'
|
48
|
+
(document.instance_variable_get :@header_attributes).delete 'stem' rescue nil
|
68
49
|
|
69
50
|
nil
|
70
51
|
end
|
@@ -106,83 +87,64 @@ class MathematicalTreeprocessor < Asciidoctor::Extensions::Treeprocessor
|
|
106
87
|
end
|
107
88
|
|
108
89
|
def handle_prose_block(prose, mathematical, image_output_dir, image_target_dir, format, inline)
|
109
|
-
|
90
|
+
if prose.context == :list_item || prose.context == :table_cell
|
91
|
+
use_text_property = true
|
92
|
+
text = prose.instance_variable_get :@text
|
93
|
+
else
|
94
|
+
text = prose.lines * LineFeed
|
95
|
+
end
|
110
96
|
text, source_modified = handle_inline_stem prose, text, mathematical, image_output_dir, image_target_dir, format, inline
|
111
97
|
if source_modified
|
112
|
-
if
|
113
|
-
prose.
|
98
|
+
if use_text_property
|
99
|
+
prose.text = text
|
114
100
|
else
|
115
101
|
prose.lines = text.split LineFeed
|
116
102
|
end
|
117
103
|
end
|
118
104
|
end
|
119
105
|
|
120
|
-
def handle_nonasciidoc_table_cell(cell, mathematical, image_output_dir, image_target_dir, format, inline)
|
121
|
-
text = cell.instance_variable_get :@text
|
122
|
-
text, source_modified = handle_inline_stem cell, text, mathematical, image_output_dir, image_target_dir, format, inline
|
123
|
-
if source_modified
|
124
|
-
cell.instance_variable_set :@text, text
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
106
|
def handle_section_title(sect, mathematical, image_output_dir, image_target_dir, format, inline)
|
129
107
|
text = sect.instance_variable_get :@title
|
130
108
|
text, source_modified = handle_inline_stem sect, text, mathematical, image_output_dir, image_target_dir, format, inline
|
131
|
-
if source_modified
|
132
|
-
sect.instance_variable_set :@title, text
|
133
|
-
sect.remove_instance_variable :@subbed_title
|
134
|
-
end
|
109
|
+
sect.title = text if source_modified
|
135
110
|
end
|
136
111
|
|
137
112
|
def handle_inline_stem(node, text, mathematical, image_output_dir, image_target_dir, format, inline)
|
138
113
|
document = node.document
|
139
|
-
|
114
|
+
source_modified = false
|
140
115
|
|
141
|
-
|
142
|
-
when 'latexmath'
|
143
|
-
support_stem_prefix = true
|
144
|
-
stem_rx = LatexmathInlineMacroRx
|
145
|
-
when 'asciimath'
|
146
|
-
support_stem_prefix = true
|
147
|
-
stem_rx = AsciiMathInlineMacroRx
|
148
|
-
else
|
149
|
-
support_stem_prefix = false
|
150
|
-
stem_rx = StemInlineMacroRx
|
151
|
-
end
|
116
|
+
return [text, source_modified] unless document.attr? 'stem'
|
152
117
|
|
153
|
-
|
118
|
+
to_html = document.basebackend? 'html'
|
119
|
+
|
120
|
+
default_equation_type = document.attr('stem').include?('tex') ? :latexmath : :asciimath
|
154
121
|
|
155
122
|
# TODO skip passthroughs in the source (e.g., +stem:[x^2]+)
|
156
|
-
if text
|
157
|
-
text = text.gsub(
|
123
|
+
if text && text.include?(':') && (text.include?('stem:') || text.include?('math:'))
|
124
|
+
text = text.gsub(StemInlineMacroRx) do
|
158
125
|
if (m = $~)[0].start_with? '\\'
|
159
126
|
next m[0][1..-1]
|
160
127
|
end
|
161
128
|
|
162
|
-
if (eq_data = m[
|
163
|
-
next
|
164
|
-
else
|
165
|
-
source_modified = true
|
166
|
-
end
|
129
|
+
next '' if (eq_data = m[3].rstrip).empty?
|
167
130
|
|
168
|
-
if
|
131
|
+
equation_type = default_equation_type if (equation_type = m[1].to_sym) == :stem
|
132
|
+
if equation_type == :asciimath
|
169
133
|
eq_data = AsciiMath.parse(eq_data).to_latex
|
170
|
-
|
171
|
-
eq_data.gsub
|
172
|
-
subs = m[
|
134
|
+
else # :latexmath
|
135
|
+
eq_data = eq_data.gsub('\]', ']')
|
136
|
+
subs = m[2].nil_or_empty? ? (to_html ? [:specialcharacters] : []) : (node.resolve_pass_subs m[2])
|
173
137
|
eq_data = node.apply_subs eq_data, subs unless subs.empty?
|
174
|
-
else
|
175
|
-
source_modified = false
|
176
|
-
return text
|
177
138
|
end
|
178
|
-
|
139
|
+
|
140
|
+
source_modified = true
|
179
141
|
img_target, img_width, img_height = make_equ_image eq_data, nil, true, mathematical, image_output_dir, image_target_dir, format, inline
|
180
142
|
if inline
|
181
|
-
%(pass:[<span class="steminline"
|
143
|
+
%(pass:[<span class="steminline">#{img_target}</span>])
|
182
144
|
else
|
183
145
|
%(image:#{img_target}[width=#{img_width},height=#{img_height}])
|
184
146
|
end
|
185
|
-
|
147
|
+
end
|
186
148
|
end
|
187
149
|
|
188
150
|
[text, source_modified]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asciidoctor-mathematical
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Stumm
|
@@ -12,40 +12,20 @@ bindir: bin
|
|
12
12
|
cert_chain: []
|
13
13
|
date: 2017-01-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
16
|
-
name: ruby-enum
|
17
|
-
requirement: !ruby/object:Gem::Requirement
|
18
|
-
requirements:
|
19
|
-
- - "~>"
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '0.4'
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
requirements:
|
26
|
-
- - "~>"
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
version: '0.4'
|
29
15
|
- !ruby/object:Gem::Dependency
|
30
16
|
name: mathematical
|
31
17
|
requirement: !ruby/object:Gem::Requirement
|
32
18
|
requirements:
|
33
19
|
- - "~>"
|
34
20
|
- !ruby/object:Gem::Version
|
35
|
-
version:
|
36
|
-
- - ">="
|
37
|
-
- !ruby/object:Gem::Version
|
38
|
-
version: 1.5.8
|
21
|
+
version: 1.6.0
|
39
22
|
type: :runtime
|
40
23
|
prerelease: false
|
41
24
|
version_requirements: !ruby/object:Gem::Requirement
|
42
25
|
requirements:
|
43
26
|
- - "~>"
|
44
27
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
46
|
-
- - ">="
|
47
|
-
- !ruby/object:Gem::Version
|
48
|
-
version: 1.5.8
|
28
|
+
version: 1.6.0
|
49
29
|
- !ruby/object:Gem::Dependency
|
50
30
|
name: asciidoctor
|
51
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,9 +33,6 @@ dependencies:
|
|
53
33
|
- - "~>"
|
54
34
|
- !ruby/object:Gem::Version
|
55
35
|
version: '2.0'
|
56
|
-
- - ">="
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
version: 2.0.0
|
59
36
|
type: :runtime
|
60
37
|
prerelease: false
|
61
38
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -63,29 +40,20 @@ dependencies:
|
|
63
40
|
- - "~>"
|
64
41
|
- !ruby/object:Gem::Version
|
65
42
|
version: '2.0'
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 2.0.0
|
69
43
|
- !ruby/object:Gem::Dependency
|
70
44
|
name: asciimath
|
71
45
|
requirement: !ruby/object:Gem::Requirement
|
72
46
|
requirements:
|
73
47
|
- - "~>"
|
74
48
|
- !ruby/object:Gem::Version
|
75
|
-
version: 2.0
|
76
|
-
- - ">="
|
77
|
-
- !ruby/object:Gem::Version
|
78
|
-
version: 2.0.0
|
49
|
+
version: '2.0'
|
79
50
|
type: :runtime
|
80
51
|
prerelease: false
|
81
52
|
version_requirements: !ruby/object:Gem::Requirement
|
82
53
|
requirements:
|
83
54
|
- - "~>"
|
84
55
|
- !ruby/object:Gem::Version
|
85
|
-
version: 2.0
|
86
|
-
- - ">="
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
version: 2.0.0
|
56
|
+
version: '2.0'
|
89
57
|
- !ruby/object:Gem::Dependency
|
90
58
|
name: rake
|
91
59
|
requirement: !ruby/object:Gem::Requirement
|