Skip to content

Commit b06f420

Browse files
committed
fix: weird inline mathjax processing (#50)
This issue is caused by the wrongly scanning no any mathjax in a page while the `optimize` option is on, the core issue is that the processor just check the node that has no chindren, but <ul> node may has several children.
1 parent 986f53f commit b06f420

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

lib/jekyll-spaceship/processors/mathjax-processor.rb

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,22 @@ def get_math_patterns()
107107

108108
def scan_mathjax_expression(doc, &block)
109109
patterns = get_math_patterns()
110-
doc.css('*').each do |node|
111-
next if ['code', 'pre', 'figure'].include? node.name
112-
next if node.ancestors('code, pre, figure').size > 0
113-
next if node.children.size > 1
110+
doc = doc.clone
111+
112+
# remove code, pre, figure nodes
113+
doc.css('body code, body pre, body figure').each do |node|
114+
node.remove
115+
end
116+
117+
# remove scripting mathjax expression
118+
doc.css('body script').each do |node|
119+
next if node['type']&.match(/math\/tex/)
120+
node.remove
121+
end
122+
123+
# scan mathjax expressions
124+
doc.css('body *').each do |node|
114125
patterns['include'].each do |pattern|
115-
# check scripting mathjax expression
116-
if node.name == 'script'
117-
type = node['type']
118-
next unless type
119-
next unless type.match(/math\/tex/)
120-
end
121126
# check normal mathjax expression
122127
node.content.scan(pattern) do |result|
123128
expr = result[0]

0 commit comments

Comments
 (0)