mirror of
https://github.com/moparisthebest/android.moparisthebest.org
synced 2024-11-16 14:15:04 -05:00
8eac9cf471
- The highlight function now accepts only to variables: code, options. - Extracting part of a code snippet is now a method of pygments_code.rb. - Options assignment has been simplified for all code plugins.
43 lines
1.2 KiB
Ruby
43 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
|
|
|
|
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,
|
|
}
|
|
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
|