mirror of
https://github.com/moparisthebest/android.moparisthebest.org
synced 2024-12-25 08:58:58 -05:00
improved backtick codeblock's handling of the raw option
This commit is contained in:
parent
36d15a9051
commit
aa509ef364
@ -5,18 +5,19 @@ module BacktickCodeBlock
|
|||||||
AllOptions = /([^\s]+)\s+(.+?)(https?:\/\/\S+)\s*(.+)?/i
|
AllOptions = /([^\s]+)\s+(.+?)(https?:\/\/\S+)\s*(.+)?/i
|
||||||
LangCaption = /([^\s]+)\s*(.+)?/i
|
LangCaption = /([^\s]+)\s*(.+)?/i
|
||||||
def render_code_block(input)
|
def render_code_block(input)
|
||||||
|
@options = nil
|
||||||
@caption = nil
|
@caption = nil
|
||||||
@lang = nil
|
@lang = nil
|
||||||
@url = nil
|
@url = nil
|
||||||
@title = nil
|
@title = nil
|
||||||
input.gsub /^`{3} *([^\n]+)?\n(.+?)\n`{3}/m do
|
input.gsub /^`{3} *([^\n]+)?\n(.+?)\n`{3}/m do
|
||||||
options = $1
|
@options = $1 || ''
|
||||||
str = $2
|
str = $2
|
||||||
|
|
||||||
if options =~ AllOptions
|
if @options =~ AllOptions
|
||||||
@lang = $1
|
@lang = $1
|
||||||
@caption = "<figcaption><span>#{$2}</span><a href='#{$3}'>#{$4 || 'link'}</a></figcaption>"
|
@caption = "<figcaption><span>#{$2}</span><a href='#{$3}'>#{$4 || 'link'}</a></figcaption>"
|
||||||
elsif options =~ LangCaption
|
elsif @options =~ LangCaption
|
||||||
@lang = $1
|
@lang = $1
|
||||||
@caption = "<figcaption><span>#{$2}</span></figcaption>"
|
@caption = "<figcaption><span>#{$2}</span></figcaption>"
|
||||||
end
|
end
|
||||||
@ -29,7 +30,7 @@ module BacktickCodeBlock
|
|||||||
"<figure role=code>#{@caption}#{code}</figure>"
|
"<figure role=code>#{@caption}#{code}</figure>"
|
||||||
else
|
else
|
||||||
if @lang.include? "-raw"
|
if @lang.include? "-raw"
|
||||||
raw = "``` #{@lang.sub('-raw', '')}\n"
|
raw = "``` #{@options.sub('-raw', '')}\n"
|
||||||
raw += str
|
raw += str
|
||||||
raw += "\n```\n"
|
raw += "\n```\n"
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user