Skip to content

Commit 5004160

Browse files
committed
feat: add some extras functions to core processor
1 parent d2d9f4b commit 5004160

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

lib/jekyll-spaceship/cores/processor.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,20 @@ def post_exclude(content)
198198
content
199199
end
200200

201+
def get_exclusion(id)
202+
result = nil
203+
match_data = id.match /<!JEKYLL@(.+)@(.+)>/
204+
unless match_data.nil?
205+
id = match_data[2].to_i
206+
result = {
207+
:id => id,
208+
:marker => match_data[0],
209+
:content => @exclusion_store[id]
210+
}
211+
end
212+
result
213+
end
214+
201215
def self.escape_html(content)
202216
# escape link
203217
content.scan(/((https?:)?\/\/\S+\?[a-zA-Z0-9%\-_=\.&;]+)/) do |result|
@@ -241,5 +255,31 @@ def self.make_img_tag(data)
241255
"<img class=\"#{css_class}\" src=\"#{body}\">"
242256
end
243257
end
258+
259+
def self.handle_bang_link(
260+
content,
261+
url = '(https?:)?\\/\\/.*',
262+
title = '("(.*)".*){0,1}',
263+
&block
264+
)
265+
# pre-handle reference-style links
266+
regex = /(\[(.*)\]:\s*(#{url}\s*#{title}))/
267+
content.scan regex do |match_data|
268+
match = match_data[0]
269+
ref_name = match_data[1]
270+
ref_value = match_data[2]
271+
content = content.gsub(match, '')
272+
.gsub(/\!\[(.*)\]\s*\[#{ref_name}\]/,
273+
"![\1](#{ref_value})")
274+
end
275+
276+
# handle inline-style links
277+
regex = /(\!\[(.*)\]\(.*#{url}\s*#{title}\))/
278+
content.scan regex do |match_data|
279+
url = match_data[2]
280+
title = match_data[6]
281+
block.call(url, title)
282+
end
283+
end
244284
end
245285
end

0 commit comments

Comments
 (0)