mirror of
https://github.com/moparisthebest/android.moparisthebest.org
synced 2024-11-16 06:05:00 -05:00
0fcbc225e4
- Unified handling of key, value options - Added url, link_text, and title options - Gists can now accept start, end, range, title, url, link_text, linenos and marks options - Code accessibility improvements (hiding line numbers) #864
41 lines
1.2 KiB
Ruby
41 lines
1.2 KiB
Ruby
require './plugins/pygments_code'
|
|
|
|
module BacktickCodeBlock
|
|
include HighlightCode
|
|
AllOptions = /([^\s]+)\s+(.+?)(https?:\/\/\S+|\/\S+)\s*(.+)?/i
|
|
LangCaption = /([^\s]+)\s*(.+)?/i
|
|
def render_code_block(input)
|
|
input.encode!("UTF-8")
|
|
input.gsub /^`{3}(.+?)`{3}/m do
|
|
str = $1.to_s
|
|
str.gsub /([^\n]+)?\n(.+?)\Z/m do
|
|
markup = $1 || ''
|
|
code = $2.to_s
|
|
|
|
options = parse_markup(markup)
|
|
@lang = options[:lang]
|
|
@title = options[:title]
|
|
@lineos = options[:lineos]
|
|
@marks = options[:marks]
|
|
@url = options[:url]
|
|
@link_text = options[:link_text]
|
|
@start = options[:start]
|
|
markup = clean_markup(markup)
|
|
|
|
if markup =~ AllOptions
|
|
@lang ||= $1
|
|
@title ||= $2
|
|
@url ||= $3
|
|
@link_text ||= $4
|
|
elsif markup =~ LangCaption
|
|
@lang ||= $1
|
|
@title ||= $2
|
|
else
|
|
@lang = 'plain'
|
|
end
|
|
highlight(code, @lang, {title: @title, url: @url, link_text: @link_text, linenos: @linenos, marks: @marks, start: @start })
|
|
end
|
|
end
|
|
end
|
|
end
|