mirror of
https://github.com/moparisthebest/android.moparisthebest.org
synced 2024-11-16 06:05:00 -05:00
a25787a204
- Removed unnecessary content filtering for escaping markdown - Escaping codeblocks defaults to false and can be enabled by passing escape:true - Backtick codeblocks are automatically escaped when using Textile - Scoped styling of .highlight divs to figure elements
45 lines
1.3 KiB
Ruby
45 lines
1.3 KiB
Ruby
require './plugins/pygments_code'
|
|
|
|
module BacktickCodeBlock
|
|
include HighlightCode
|
|
AllOptions = /([^\s]+)\s+(.+?)\s+(https?:\/\/\S+|\/\S+)\s*(.+)?/i
|
|
LangCaption = /([^\s]+)\s*(.+)?/i
|
|
def render_code_block(input, ext)
|
|
escape = ext ? ext.match(/textile/) != nil : false
|
|
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
|
|
|
|
opts = parse_markup(markup)
|
|
@options = {
|
|
lang: opts[:lang],
|
|
title: opts[:title],
|
|
lineos: opts[:lineos],
|
|
marks: opts[:marks],
|
|
url: opts[:url],
|
|
link_text: opts[:link_text] || 'link',
|
|
start: opts[:start] || 1,
|
|
escape: opts[:escape] || escape
|
|
}
|
|
markup = clean_markup(markup)
|
|
|
|
if markup =~ AllOptions
|
|
@options[:lang] ||= $1
|
|
@options[:title] ||= $2
|
|
@options[:url] ||= $3
|
|
@options[:link_text] ||= $4
|
|
elsif markup =~ LangCaption
|
|
@options[:lang] ||= $1
|
|
@options[:title] ||= $2
|
|
else
|
|
@options[:lang] ||= 'plain'
|
|
end
|
|
highlight(code, @options)
|
|
end
|
|
end
|
|
end
|
|
end
|