diff --git a/.themes/classic/sass/partials/_syntax.scss b/.themes/classic/sass/partials/_syntax.scss index 8121755..8938975 100644 --- a/.themes/classic/sass/partials/_syntax.scss +++ b/.themes/classic/sass/partials/_syntax.scss @@ -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 } } diff --git a/plugins/backtick_code_block.rb b/plugins/backtick_code_block.rb index abb9fc7..301d573 100644 --- a/plugins/backtick_code_block.rb +++ b/plugins/backtick_code_block.rb @@ -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) diff --git a/plugins/gist_tag.rb b/plugins/gist_tag.rb index 2decda0..6f03edb 100644 --- a/plugins/gist_tag.rb +++ b/plugins/gist_tag.rb @@ -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 diff --git a/plugins/octopress_filters.rb b/plugins/octopress_filters.rb index 729cff5..62ee080 100644 --- a/plugins/octopress_filters.rb +++ b/plugins/octopress_filters.rb @@ -8,15 +8,8 @@ require 'rubypants' module OctopressFilters include BacktickCodeBlock include TemplateWrapper - def pre_filter(input) - input.gsub /(.+?<\/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 diff --git a/plugins/pygments_code.rb b/plugins/pygments_code.rb index abb92bc..4ea868d 100644 --- a/plugins/pygments_code.rb +++ b/plugins/pygments_code.rb @@ -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 = "
#{title}#{code}
" + 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) diff --git a/plugins/raw.rb b/plugins/raw.rb index 36aa952..13c053d 100644 --- a/plugins/raw.rb +++ b/plugins/raw.rb @@ -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
+ # Escape content for Textile with def safe_wrap(input) - "
#{input}
" - end - # This must be applied after the - def unwrap(input) - input.gsub /([\s\S]*?)(.+?)([\s\S]*?)/m do - $2 - end + "#{input}" end end diff --git a/plugins/render_partial.rb b/plugins/render_partial.rb index 970a180..916f9da 100644 --- a/plugins/render_partial.rb +++ b/plugins/render_partial.rb @@ -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?