mirror of
https://github.com/moparisthebest/android.moparisthebest.org
synced 2024-10-31 23:35:00 -04:00
Merge branch '2.1' into site
Conflicts: plugins/backtick_code_block.rb plugins/code_block.rb plugins/include_code.rb plugins/pygments_code.rb
This commit is contained in:
commit
2e51d76681
2
Rakefile
2
Rakefile
@ -295,7 +295,7 @@ multitask :push do
|
|||||||
puts "\n## copying #{public_dir} to #{deploy_dir}"
|
puts "\n## copying #{public_dir} to #{deploy_dir}"
|
||||||
cp_r "#{public_dir}/.", deploy_dir
|
cp_r "#{public_dir}/.", deploy_dir
|
||||||
cd "#{deploy_dir}" do
|
cd "#{deploy_dir}" do
|
||||||
system "touch .nojekyll"
|
File.new(".nojekyll", "w").close
|
||||||
system "git add ."
|
system "git add ."
|
||||||
system "git add -u"
|
system "git add -u"
|
||||||
message = "Site updated at #{Time.now.utc}"
|
message = "Site updated at #{Time.now.utc}"
|
||||||
|
@ -8,23 +8,23 @@ module BacktickCodeBlock
|
|||||||
input.encode!("UTF-8")
|
input.encode!("UTF-8")
|
||||||
input.gsub /^`{3}(.+?)`{3}/m do
|
input.gsub /^`{3}(.+?)`{3}/m do
|
||||||
str = $1.to_s
|
str = $1.to_s
|
||||||
linenos = true
|
|
||||||
start = 1
|
|
||||||
str.gsub /([^\n]+)?\n(.+?)\Z/m do
|
str.gsub /([^\n]+)?\n(.+?)\Z/m do
|
||||||
@options = $1 || ''
|
markup = $1 || ''
|
||||||
code = $2.to_s
|
code = $2.to_s
|
||||||
if @options =~ /\s*linenos:false/i
|
|
||||||
linenos = false
|
linenos = get_linenos(markup)
|
||||||
@options = @options.sub(/\s*linenos:false/i,'')
|
markup = replace_linenos(markup)
|
||||||
end
|
|
||||||
if @options =~ /\s*start:(\d+)/i
|
marks = get_marks(markup)
|
||||||
start = $1.to_i
|
markup = replace_marks(markup)
|
||||||
@options = @options.sub(/\s*start:\d+/i,'')
|
|
||||||
end
|
start = get_start(markup)
|
||||||
if @options =~ AllOptions
|
markup = replace_start(markup)
|
||||||
highlight(code, $1, {caption: $2, url: $3, anchor: $4 || 'Link', linenos: linenos, start: start})
|
|
||||||
elsif @options =~ LangCaption
|
if markup =~ AllOptions
|
||||||
highlight(code, $1, {caption: $2 || '', linenos: linenos, start: start})
|
highlight(code, $1, {caption: $2, url: $3, anchor: $4 || 'Link', linenos: linenos, start: start, marks: marks})
|
||||||
|
elsif markup =~ LangCaption
|
||||||
|
highlight(code, $1, {caption: $2 || '', linenos: linenos, start: start, marks: marks})
|
||||||
else
|
else
|
||||||
highlight(code, 'plain', {linenos: linenos, start: start})
|
highlight(code, 'plain', {linenos: linenos, start: start})
|
||||||
end
|
end
|
||||||
|
@ -54,16 +54,19 @@ module Jekyll
|
|||||||
def initialize(tag_name, markup, tokens)
|
def initialize(tag_name, markup, tokens)
|
||||||
@caption = nil
|
@caption = nil
|
||||||
@url = nil
|
@url = nil
|
||||||
@lang = nil
|
|
||||||
@start = 1
|
@lang = get_lang(markup)
|
||||||
if markup =~ /\s*lang:(\w+)/i
|
markup = replace_lang(markup)
|
||||||
@lang = $1
|
|
||||||
markup = markup.sub(/lang:\w+/i,'')
|
@linenos = get_linenos(markup)
|
||||||
end
|
markup = replace_linenos(markup)
|
||||||
if markup =~ /\s*start:(\d+)/i
|
|
||||||
@start = $1.to_i
|
@mark = get_marks(markup)
|
||||||
markup = markup.sub(/\s*start:\d+/i,'')
|
markup = replace_marks(markup)
|
||||||
end
|
|
||||||
|
@start = get_start(markup)
|
||||||
|
markup = replace_start(markup)
|
||||||
|
|
||||||
if markup =~ CaptionUrlTitle
|
if markup =~ CaptionUrlTitle
|
||||||
@caption = $1
|
@caption = $1
|
||||||
@url = $2 + $3
|
@url = $2 + $3
|
||||||
@ -82,7 +85,7 @@ module Jekyll
|
|||||||
|
|
||||||
def render(context)
|
def render(context)
|
||||||
code = super.strip
|
code = super.strip
|
||||||
code = highlight(code, @lang, {caption: @caption, url: @url, anchor: @anchor, start: @start})
|
code = highlight(code, @lang, {caption: @caption, url: @url, anchor: @anchor, start: @start, marks: @marks, linenos: @linenos})
|
||||||
code = context['pygments_prefix'] + code if context['pygments_prefix']
|
code = context['pygments_prefix'] + code if context['pygments_prefix']
|
||||||
code = code + context['pygments_suffix'] if context['pygments_suffix']
|
code = code + context['pygments_suffix'] if context['pygments_suffix']
|
||||||
code
|
code
|
||||||
|
@ -30,25 +30,27 @@ module Jekyll
|
|||||||
def initialize(tag_name, markup, tokens)
|
def initialize(tag_name, markup, tokens)
|
||||||
@title = nil
|
@title = nil
|
||||||
@file = nil
|
@file = nil
|
||||||
@start = 1
|
|
||||||
@end = nil
|
@lang = get_lang(markup)
|
||||||
if markup.strip =~ /\s*lang:(\w+)/i
|
markup = replace_lang(markup)
|
||||||
@filetype = $1
|
|
||||||
markup = markup.strip.sub(/lang:\w+/i,'')
|
@linenos = get_linenos(markup)
|
||||||
end
|
markup = replace_linenos(markup)
|
||||||
if markup =~ /\s*start:(\d+)/i
|
|
||||||
@start = $1.to_i
|
@marks = get_marks(markup)
|
||||||
markup = markup.sub(/\s*start:\d+/i,'')
|
markup = replace_marks(markup)
|
||||||
end
|
|
||||||
if markup =~ /\s*end:(\d+)/i
|
@start = get_start(markup)
|
||||||
@end = $1.to_i
|
markup = replace_start(markup)
|
||||||
markup = markup.sub(/\s*end:\d+/i,'')
|
|
||||||
end
|
@end = get_end(markup)
|
||||||
if markup =~ /\s*range:(\d+),(\d+)/i
|
markup = replace_end(markup)
|
||||||
@start = $1.to_i
|
|
||||||
@end = $2.to_i
|
range = get_range(markup, @start, @end)
|
||||||
markup = markup.sub(/\s*range:\d+,\d+/i,'')
|
@start = range[:start]
|
||||||
end
|
@end = range[:start]
|
||||||
|
markup = replace_range(markup)
|
||||||
|
|
||||||
if markup.strip =~ /(.*)?(\s+|^)(\/*\S+)/i
|
if markup.strip =~ /(.*)?(\s+|^)(\/*\S+)/i
|
||||||
@title = $1 || nil
|
@title = $1 || nil
|
||||||
@file = $3
|
@file = $3
|
||||||
@ -78,10 +80,10 @@ module Jekyll
|
|||||||
if @start > 1 or @end < length
|
if @start > 1 or @end < length
|
||||||
code = code.split(/\n/).slice(@start -1, @end + 1 - @start).join("\n")
|
code = code.split(/\n/).slice(@start -1, @end + 1 - @start).join("\n")
|
||||||
end
|
end
|
||||||
@filetype = file.extname.sub('.','') if @filetype.nil?
|
@lang = file.extname.sub('.','') unless @lang
|
||||||
title = @title ? "#{@title} (#{file.basename})" : file.basename
|
title = @title ? "#{@title} (#{file.basename})" : file.basename
|
||||||
url = "/#{code_dir}/#{@file}"
|
url = "/#{code_dir}/#{@file}"
|
||||||
highlight(code, @filetype, {caption: title, url: url, anchor: 'download', start: @start})
|
highlight(code, @lang, {caption: title, url: url, anchor: 'download', start: @start, marks: @marks, linenos: @linenos })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -29,12 +29,13 @@ module HighlightCode
|
|||||||
lang = 'perl' if lang == 'pl'
|
lang = 'perl' if lang == 'pl'
|
||||||
lang = 'yaml' if lang == 'yml'
|
lang = 'yaml' if lang == 'yml'
|
||||||
lang = 'coffeescript' if lang == 'coffee'
|
lang = 'coffeescript' if lang == 'coffee'
|
||||||
lang = 'plain' if lang == '' or lang.nil?
|
lang = 'plain' if lang == '' or lang.nil? or !lang
|
||||||
|
|
||||||
caption = options[:caption] || nil
|
caption = options[:caption] || nil
|
||||||
url = options[:url] || nil
|
url = options[:url] || nil
|
||||||
anchor = options[:anchor] || nil
|
anchor = options[:anchor] || nil
|
||||||
wrap = options[:wrap] || true
|
wrap = options[:wrap] || true
|
||||||
|
marks = options[:marks]
|
||||||
linenos = options[:linenos]
|
linenos = options[:linenos]
|
||||||
start = options[:start]
|
start = options[:start]
|
||||||
|
|
||||||
@ -49,7 +50,7 @@ module HighlightCode
|
|||||||
code = pygments(code, lang).match(/<pre>(.+)<\/pre>/m)[1].gsub(/ *$/, '') #strip out divs <div class="highlight">
|
code = pygments(code, lang).match(/<pre>(.+)<\/pre>/m)[1].gsub(/ *$/, '') #strip out divs <div class="highlight">
|
||||||
end
|
end
|
||||||
|
|
||||||
code = tableize_code(code, lang, { linenos: linenos, start: start })
|
code = tableize_code(code, lang, { linenos: linenos, start: start, marks: marks })
|
||||||
caption = captionize(caption, url, anchor) if caption
|
caption = captionize(caption, url, anchor) if caption
|
||||||
|
|
||||||
figure = "<figure class='code'>#{caption}#{code}</figure>"
|
figure = "<figure class='code'>#{caption}#{code}</figure>"
|
||||||
@ -65,20 +66,104 @@ module HighlightCode
|
|||||||
|
|
||||||
def tableize_code (code, lang, options = {})
|
def tableize_code (code, lang, options = {})
|
||||||
start = options[:start]
|
start = options[:start]
|
||||||
lines = options[:linenos] || true
|
lines = options[:linenos].nil? ? true : options[:linenos]
|
||||||
|
marks = options[:marks] || []
|
||||||
table = "<div class='highlight'><table>"
|
table = "<div class='highlight'><table>"
|
||||||
table += number_lines(start, code.lines.count) if lines
|
table += number_lines(start, code.lines.count, marks) if lines
|
||||||
table += "<td class='code'><pre><code class='#{lang}'>"
|
table += "<td class='code'><pre><code class='#{lang}'>"
|
||||||
|
if marks.size
|
||||||
|
code.lines.each_with_index do |line,index|
|
||||||
|
table += "<span class='line#{' marked' if marks.include? index + start}'>#{line}</span>"
|
||||||
|
end
|
||||||
|
else
|
||||||
table += code.gsub /^((.+)?(\n?))/, '<span class=\'line\'>\1</span>'
|
table += code.gsub /^((.+)?(\n?))/, '<span class=\'line\'>\1</span>'
|
||||||
|
end
|
||||||
table +="</code></pre></td></tr></table></div>"
|
table +="</code></pre></td></tr></table></div>"
|
||||||
end
|
end
|
||||||
|
|
||||||
def number_lines (start, count)
|
def number_lines (start, count, marks)
|
||||||
start ||= 1
|
start ||= 1
|
||||||
lines = "<td class='gutter'><pre class='line-numbers'>"
|
lines = "<td class='gutter'><pre class='line-numbers'>"
|
||||||
count.times do |index|
|
count.times do |index|
|
||||||
lines += "<span class='line-number'>#{index + start}</span>\n"
|
lines += "<span class='line-number#{' marked' if marks.include? index + start}'>#{index + start}</span>\n"
|
||||||
end
|
end
|
||||||
lines += "</pre></td>"
|
lines += "</pre></td>"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_lang (input)
|
||||||
|
lang = nil
|
||||||
|
if input =~ /\s*lang:(\w+)/i
|
||||||
|
lang = $1
|
||||||
|
end
|
||||||
|
lang
|
||||||
|
end
|
||||||
|
|
||||||
|
def replace_lang (input)
|
||||||
|
input.sub /\s*lang:\w+/i, ''
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_marks (input)
|
||||||
|
# Matches pattern for line marks and returns array of line numbers to mark
|
||||||
|
# Example input mark:1,5-10,2
|
||||||
|
# Outputs: [1,2,5,6,7,8,9,10]
|
||||||
|
marks = []
|
||||||
|
if input =~ /\s*mark:(\d\S*)/i
|
||||||
|
marks = $1.gsub /(\d+)-(\d+)/ do
|
||||||
|
($1.to_i..$2.to_i).to_a.join(',')
|
||||||
|
end
|
||||||
|
marks = marks.split(',').collect {|s| s.to_i}.sort
|
||||||
|
end
|
||||||
|
marks
|
||||||
|
end
|
||||||
|
|
||||||
|
def replace_marks (input)
|
||||||
|
input.sub(/\s*mark:\d\S*/i,'')
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_linenos (input)
|
||||||
|
linenos = true
|
||||||
|
if input =~ /\s*linenos:false/i
|
||||||
|
linenos = false
|
||||||
|
end
|
||||||
|
linenos
|
||||||
|
end
|
||||||
|
|
||||||
|
def replace_linenos (input)
|
||||||
|
input.sub(/\s*linenos:false/i,'')
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_start (input)
|
||||||
|
start = 1
|
||||||
|
if input =~ /\s*start:(\d+)/i
|
||||||
|
start = $1.to_i
|
||||||
|
end
|
||||||
|
start
|
||||||
|
end
|
||||||
|
|
||||||
|
def replace_start (input)
|
||||||
|
input.sub(/\s*start:\d+/i,'')
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_end (input)
|
||||||
|
endline = nil
|
||||||
|
if input =~ /\s*end:(\d+)/i
|
||||||
|
endline = $1.to_i
|
||||||
|
end
|
||||||
|
endline
|
||||||
|
end
|
||||||
|
|
||||||
|
def replace_end (input)
|
||||||
|
input.sub(/\s*end:\d+/i,'')
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_range (input, start, endline)
|
||||||
|
if input =~ /\s*range:(\d+),(\d+)/i
|
||||||
|
start = $1.to_i
|
||||||
|
eneline = $2.to_i
|
||||||
|
end
|
||||||
|
{start: start, end: endline}
|
||||||
|
end
|
||||||
|
def replace_range (input)
|
||||||
|
input.sub(/\s*range:\d+,\d+/i,'')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user