mirror of
https://github.com/SharpeTronics/jekyll-spaceship.git
synced 2025-12-20 00:01:55 -05:00
feat: add excluding content to skip markdown code
This commit is contained in:
parent
169bdf1343
commit
7b21c0640b
@ -7,6 +7,7 @@ module Jekyll::Spaceship
|
||||
@@_hooks = {}
|
||||
@@_registers = []
|
||||
@@_processers = []
|
||||
@@_exclusions = []
|
||||
@@_priority = nil
|
||||
|
||||
attr_accessor :priority
|
||||
@ -40,6 +41,7 @@ module Jekyll::Spaceship
|
||||
def initialize()
|
||||
self.initialize_priority
|
||||
self.initialize_register
|
||||
self.initialize_exclusions
|
||||
end
|
||||
|
||||
def initialize_priority
|
||||
@ -71,6 +73,14 @@ module Jekyll::Spaceship
|
||||
@@_registers.clear
|
||||
end
|
||||
|
||||
def initialize_exclusions
|
||||
if @@_exclusions.size.zero?
|
||||
self.class.exclude :code, :block_quotes
|
||||
end
|
||||
@_exclusions = @@_exclusions.uniq
|
||||
@@_exclusions.clear
|
||||
end
|
||||
|
||||
def self.priority(value)
|
||||
value = value.to_sym
|
||||
if PRIORITY_MAP.has_key? value
|
||||
@ -145,7 +155,9 @@ module Jekyll::Spaceship
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
else
|
||||
if html? output_ext
|
||||
@ -162,6 +174,10 @@ module Jekyll::Spaceship
|
||||
end
|
||||
end
|
||||
|
||||
def self.exclude(*types)
|
||||
@@_exclusions = types
|
||||
end
|
||||
|
||||
def html?(_ext)
|
||||
self.class.html? _ext
|
||||
end
|
||||
@ -217,6 +233,34 @@ module Jekyll::Spaceship
|
||||
html?(output_ext) or markdown?(ext)
|
||||
end
|
||||
|
||||
def pre_exclude(content)
|
||||
@_exclusion_store = []
|
||||
@_exclusions.each do |type|
|
||||
regex = nil
|
||||
if type == :code
|
||||
regex = /(`{3}\s*(\w*)((?:.|\n)*?)`{3})/
|
||||
end
|
||||
next if regex.nil?
|
||||
content.scan(regex) do |match_data|
|
||||
match = match_data[0]
|
||||
id = @_exclusion_store.size
|
||||
content = content.gsub(match, "[//]: JEKYLL_EXCLUDE_##{id}")
|
||||
@_exclusion_store.push match
|
||||
end
|
||||
end
|
||||
content
|
||||
end
|
||||
|
||||
def after_exclude(content)
|
||||
while @_exclusion_store.size > 0
|
||||
match = @_exclusion_store.pop
|
||||
id = @_exclusion_store.size
|
||||
content = content.gsub("[//]: JEKYLL_EXCLUDE_##{id}", match)
|
||||
end
|
||||
@_exclusion_store = []
|
||||
content
|
||||
end
|
||||
|
||||
def on_handled
|
||||
processor = self.class.name.split('::').last
|
||||
file = page.path.gsub(/.*_posts\//, '')
|
||||
@ -251,7 +295,9 @@ module Jekyll::Spaceship
|
||||
|
||||
# dispatch to other handlers
|
||||
if processor.respond_to? method
|
||||
blk_content = processor.pre_exclude blk_content
|
||||
blk_content = processor.send method, blk_content
|
||||
blk_content = processor.after_exclude blk_content
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
|
||||
module Jekyll::Spaceship
|
||||
class PlantUMLProcessor < Processor
|
||||
exclude :none
|
||||
|
||||
def on_handle_markdown(content)
|
||||
# match default plantuml block and code block
|
||||
pattern = Regexp.union(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user