Skip to content

Commit

Permalink
fix: weird inline mathjax processing (#50)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jeffreytse committed Apr 2, 2021
1 parent 986f53f commit b06f420
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions lib/jekyll-spaceship/processors/mathjax-processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,22 @@ def get_math_patterns()

def scan_mathjax_expression(doc, &block)
patterns = get_math_patterns()
doc.css('*').each do |node|
next if ['code', 'pre', 'figure'].include? node.name
next if node.ancestors('code, pre, figure').size > 0
next if node.children.size > 1
doc = doc.clone

# remove code, pre, figure nodes
doc.css('body code, body pre, body figure').each do |node|
node.remove
end

# remove scripting mathjax expression
doc.css('body script').each do |node|
next if node['type']&.match(/math\/tex/)
node.remove
end

# scan mathjax expressions
doc.css('body *').each do |node|
patterns['include'].each do |pattern|
# check scripting mathjax expression
if node.name == 'script'
type = node['type']
next unless type
next unless type.match(/math\/tex/)
end
# check normal mathjax expression
node.content.scan(pattern) do |result|
expr = result[0]
Expand Down

0 comments on commit b06f420

Please sign in to comment.