Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

support ```regexp for pygment

  • Loading branch information...
commit 0e2966da04e1833a87c4ad074a847c13bc7f68f1 1 parent 1bad17e
@mvj3 authored
Showing with 10 additions and 8 deletions.
  1. +10 −8 lib/markdownizer.rb
View
18 lib/markdownizer.rb
@@ -120,20 +120,21 @@ def coderay text, options = {}
end
- private
def highlight text, options
- text.gsub(%r/\{% code (\w+?) %\}(.+?)\{% endcode %\}|```(\w+?) +(.+?)```/m) do
+ text.gsub(%r/\{% code (\w+?) %\}((.|\n)+?)\{% endcode %\}|```\w+\s+?[\r\n\t]+.+[\r\n\t]+```/m) do |m|
options.delete(:highlight_lines)
options.delete(:caption)
-
enclosing_class = options[:enclosing_class] || 'markdownizer_code'
- code, language = $2.strip, $1.strip
- language = if lexer = Pygments::Lexer.find_by_extname(language)
- lexer.aliases[0]
+ if Markdownizer.highlight_engine == :pygments
+ language = if lexer = Pygments::Lexer.find_by_extname(language)
+ lexer.aliases[0]
+ else
+ 'text'
+ end
else
- 'text'
- end if Markdownizer.highlight_engine == :pygments
+ code, language = $2.strip, $1.strip
+ end
# Mark comments to avoid conflicts with Header parsing
code.gsub!(/(#+)/) do
@@ -157,6 +158,7 @@ def pygments text, language
Pygments.highlight(text.to_s, :lexer => language, :options => opts).to_s.force_encoding("UTF-8")
end
+ private
def extract_caption_from(code, options)
caption = nil
code.gsub!(%r[\{% caption '([^']+)' %\}]) do
Please sign in to comment.
Something went wrong with that request. Please try again.