Skip to content

Commit

Permalink
fix: inline code corrupted in table (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreytse committed Oct 7, 2020
1 parent 6973d6a commit 7847cac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/jekyll-spaceship/cores/processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def dispatch(page, container, event)
if self.respond_to? method
@page.content = self.pre_exclude @page.content
@page.content = self.send method, @page.content
@page.content = self.after_exclude @page.content
@page.content = self.post_exclude @page.content
end
else
if Type.html? output_ext
Expand Down Expand Up @@ -151,8 +151,8 @@ def on_handled
logger.log file
end

def pre_exclude(content)
@exclusion_store = []
def exclusion_regexs()
regexs = []
@exclusions.each do |type|
regex = nil
if type == :code
Expand All @@ -162,7 +162,14 @@ def pre_exclude(content)
elsif type == :liquid_filter
regex = /((?<!\\)((\{\{[^\n]*?\}\})|(\{%[^\n]*?%\})))/
end
next if regex.nil?
regexs.push regex unless regex.nil?
end
regexs
end

def pre_exclude(content, regexs = self.exclusion_regexs())
@exclusion_store = []
regexs.each do |regex|
content.scan(regex) do |match_data|
match = match_data[0]
id = @exclusion_store.size
Expand All @@ -173,7 +180,7 @@ def pre_exclude(content)
content
end

def after_exclude(content)
def post_exclude(content)
while @exclusion_store.size > 0
match = @exclusion_store.pop
id = @exclusion_store.size
Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll-spaceship/processors/table-processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,12 @@ def handle_format(data)
cvter = self.converter('markdown')
return if cvter.nil?
content = cell.inner_html
content = self.pre_exclude(content, [/(\<code.*\>.*\<\/code\>)/])
.gsub(/(?<!\\)\|/, '\\|')
.gsub(/^\s+|\s+$/, '')
.gsub(/&lt;/, '<')
.gsub(/&gt;/, '>')
content = self.post_exclude(content)
content = cvter.convert(content)
content = Nokogiri::HTML.fragment(content)
if content.children.first&.name == 'p'
Expand Down

0 comments on commit 7847cac

Please sign in to comment.