mirror of
https://github.com/moparisthebest/android.moparisthebest.org
synced 2024-11-16 06:05:00 -05:00
Fixes for Redcarpet
- 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
This commit is contained in:
parent
a3eea15ac5
commit
a25787a204
@ -118,7 +118,7 @@ figure.code {
|
||||
}
|
||||
}
|
||||
|
||||
.highlight {
|
||||
figure .highlight {
|
||||
border: 1px solid $pre-border;
|
||||
background: $base03;
|
||||
overflow-y: hidden;
|
||||
@ -228,7 +228,7 @@ $solar-scroll-thumb: rgba(#fff, .2);
|
||||
$solar-scroll-thumb: rgba(#000, .15);
|
||||
}
|
||||
|
||||
pre, .highlight {
|
||||
pre, figure .highlight {
|
||||
&::-webkit-scrollbar { height: .5em; background: $solar-scroll-bg; }
|
||||
&::-webkit-scrollbar-thumb:horizontal { background: $solar-scroll-thumb; -webkit-border-radius: 4px; border-radius: 4px }
|
||||
}
|
||||
|
@ -4,7 +4,8 @@ module BacktickCodeBlock
|
||||
include HighlightCode
|
||||
AllOptions = /([^\s]+)\s+(.+?)\s+(https?:\/\/\S+|\/\S+)\s*(.+)?/i
|
||||
LangCaption = /([^\s]+)\s*(.+)?/i
|
||||
def render_code_block(input)
|
||||
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
|
||||
@ -21,6 +22,7 @@ module BacktickCodeBlock
|
||||
url: opts[:url],
|
||||
link_text: opts[:link_text] || 'link',
|
||||
start: opts[:start] || 1,
|
||||
escape: opts[:escape] || escape
|
||||
}
|
||||
markup = clean_markup(markup)
|
||||
|
||||
|
@ -55,7 +55,7 @@ module Jekyll
|
||||
code = get_range(code, @options[:start], @options[:end])
|
||||
code = highlight(code, @options)
|
||||
end
|
||||
code || safe_wrap(cache)
|
||||
code || cache
|
||||
else
|
||||
"Gist formatting error, format should be {% gist gist_id [filename] %}"
|
||||
end
|
||||
|
@ -8,15 +8,8 @@ require 'rubypants'
|
||||
module OctopressFilters
|
||||
include BacktickCodeBlock
|
||||
include TemplateWrapper
|
||||
def pre_filter(input)
|
||||
input.gsub /(<figure.+?>.+?<\/figure>)/m do
|
||||
safe_wrap($1)
|
||||
end
|
||||
input = render_code_block(input)
|
||||
end
|
||||
def post_filter(input)
|
||||
input = unwrap(input)
|
||||
RubyPants.new(input).to_html
|
||||
def pre_filter(input, ext)
|
||||
input = render_code_block(input, ext)
|
||||
end
|
||||
end
|
||||
|
||||
@ -25,12 +18,7 @@ module Jekyll
|
||||
include OctopressFilters
|
||||
def pre_render(post)
|
||||
if post.ext.match('html|textile|markdown|haml|slim|xml')
|
||||
post.content = pre_filter(post.content)
|
||||
end
|
||||
end
|
||||
def post_render(post)
|
||||
if post.ext.match('html|textile|markdown|haml|slim|xml')
|
||||
post.content = post_filter(post.content)
|
||||
post.content = pre_filter(post.content, post.ext)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -31,7 +31,7 @@ module HighlightCode
|
||||
url = options[:url] || nil
|
||||
title = options[:title] || (url ? ' ' : nil)
|
||||
link_text = options[:link_text] || nil
|
||||
wrap = options[:wrap] || true
|
||||
escape = options[:escape] || false
|
||||
marks = options[:marks]
|
||||
linenos = options[:linenos]
|
||||
start = options[:start] || 1
|
||||
@ -55,14 +55,14 @@ module HighlightCode
|
||||
code = tableize_code(code, lang, {linenos: linenos, start: start, marks: marks })
|
||||
title = captionize(title, url, link_text) if title
|
||||
code = "<figure class='code'>#{title}#{code}</figure>"
|
||||
code = safe_wrap(code) if escape
|
||||
File.open(path, 'w') {|f| f.print(code) } unless no_cache
|
||||
end
|
||||
code = safe_wrap(cache || code) if wrap
|
||||
code
|
||||
cache || code
|
||||
end
|
||||
|
||||
def read_cache (path)
|
||||
code = File.exist?(path) ? File.read(path) : nil unless path.nil?
|
||||
File.exist?(path) ? File.read(path) : nil unless path.nil?
|
||||
end
|
||||
|
||||
def get_cache_path (dir, name, str)
|
||||
@ -114,6 +114,7 @@ module HighlightCode
|
||||
lang = input.match(/\s*lang:(\w+)/i)
|
||||
title = input.match(/\s*title:\s*(("(.+?)")|('(.+?)')|(\S+))/i)
|
||||
linenos = input.match(/\s*linenos:(\w+)/i)
|
||||
escape = input.match(/\s*escape:(\w+)/i)
|
||||
marks = get_marks(input)
|
||||
url = input.match(/\s*url:\s*(("(.+?)")|('(.+?)')|(\S+))/i)
|
||||
link_text = input.match(/\s*link[-_]text:\s*(("(.+?)")|('(.+?)')|(\S+))/i)
|
||||
@ -124,6 +125,7 @@ module HighlightCode
|
||||
lang: (lang.nil? ? nil : lang[1]),
|
||||
title: (title.nil? ? nil : title[3] || title[5] || title[6]),
|
||||
linenos: (linenos.nil? ? nil : linenos[1]),
|
||||
escape: (escape.nil? ? nil : escape[1]),
|
||||
marks: marks,
|
||||
url: (url.nil? ? nil : url[3] || url[5] || url[6]),
|
||||
start: (start.nil? ? nil : start[1].to_i),
|
||||
@ -134,15 +136,15 @@ module HighlightCode
|
||||
end
|
||||
|
||||
def clean_markup (input)
|
||||
input.sub(/\s*lang:\w+/i, ''
|
||||
input.sub(/\s*lang:\s*\w+/i, ''
|
||||
).sub(/\s*title:\s*(("(.+?)")|('(.+?)')|(\S+))/i, ''
|
||||
).sub(/\s*url:(\S+)/i, ''
|
||||
).sub(/\s*url:\s*(\S+)/i, ''
|
||||
).sub(/\s*link_text:\s*(("(.+?)")|('(.+?)')|(\S+))/i, ''
|
||||
).sub(/\s*mark:\d\S*/i,''
|
||||
).sub(/\s*linenos:false/i,''
|
||||
).sub(/\s*start:\d+/i,''
|
||||
).sub(/\s*end:\d+/i,''
|
||||
).sub(/\s*range:\d+-\d+/i,'')
|
||||
).sub(/\s*linenos:\s*\w+/i,''
|
||||
).sub(/\s*start:\s*\d+/i,''
|
||||
).sub(/\s*end:\s*\d+/i,''
|
||||
).sub(/\s*range:\s*\d+-\d+/i,'')
|
||||
end
|
||||
|
||||
def get_marks (input)
|
||||
|
@ -1,16 +1,10 @@
|
||||
# Author: Brandon Mathis
|
||||
# Description: Provides plugins with a method for wrapping and unwrapping input to prevent Markdown and Textile from parsing it.
|
||||
# Purpose: This is useful for preventing Markdown and Textile from being too aggressive and incorrectly parsing in-line HTML.
|
||||
# Description: Provides plugins with a method for wrapping and unwrapping input to prevent Textile from parsing it.
|
||||
# Purpose: This is useful for preventing Textile from being too aggressive and incorrectly parsing in-line HTML.
|
||||
module TemplateWrapper
|
||||
# Wrap input with a <div>
|
||||
# Escape content for Textile with <notextile>
|
||||
def safe_wrap(input)
|
||||
"<!--escape--><div class='escape-wrapper'><notextile><!--content-->#{input}<!--end-content--></notextile></div><!--end-escape-->"
|
||||
end
|
||||
# This must be applied after the
|
||||
def unwrap(input)
|
||||
input.gsub /<!--escape-->([\s\S]*?)<!--content-->(.+?)<!--end-content-->([\s\S]*?)<!--end-escape-->/m do
|
||||
$2
|
||||
end
|
||||
"<notextile>#{input}</notextile>"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -42,6 +42,7 @@ module Jekyll
|
||||
file_dir = (context.registers[:site].source || 'source')
|
||||
file_path = Pathname.new(file_dir).expand_path
|
||||
file = file_path + @file
|
||||
ext = File.extname(@file)
|
||||
|
||||
unless file.file?
|
||||
return "File #{file} could not be found"
|
||||
@ -52,7 +53,7 @@ module Jekyll
|
||||
if contents =~ /\A-{3}.+[^\A]-{3}\n(.+)/m
|
||||
contents = $1.lstrip
|
||||
end
|
||||
contents = pre_filter(contents)
|
||||
contents = pre_filter(contents, ext)
|
||||
if @raw
|
||||
contents
|
||||
else
|
||||
@ -61,7 +62,6 @@ module Jekyll
|
||||
contents = partial.render(context)
|
||||
|
||||
site = context.registers[:site]
|
||||
ext = File.extname(@file)
|
||||
converter = site.converters.find { |c| c.matches(ext) }
|
||||
|
||||
if converter.nil?
|
||||
|
Loading…
Reference in New Issue
Block a user