lib/octopress-codefence.rb in octopress-codefence-1.4.5 vs lib/octopress-codefence.rb in octopress-codefence-1.5.0

- old
+ new

@@ -26,10 +26,11 @@ @aliases = aliases end def render @input.encode!("UTF-8") + @input = sub_option_comment(@input) @input.gsub /^`{3}(.+?)`{3}/m do str = $1.to_s str.gsub /([^\n]+)?\n(.+?)\Z/m do markup = $1 || '' code = $2.to_s @@ -38,9 +39,28 @@ rescue => e markup = "```#{markup}" CodeHighlighter.highlight_failed(e, "```[language] [title] [url] [link text] [linenos:false] [start:#] [mark:#,#-#]\ncode\n```", markup, code) end end + end + end + + # Allow html comments to set rendering options + # + # Example: + # <!-- title:"Example 1" --> + # ```ruby + # + # This becomes: + # + # ```ruby title:"Example 1" + # + # This allows Readme files to be rendered by GitHub and other markdown codefences + # But when processed by Octopress Codefence, the code examples are rendered with options + # + def sub_option_comment(input) + input.gsub /<!--(.+?)-->\n`{3}([^\n]+)/ do + "```#{$2} #{$1}" end end def get_options(markup) defaults = { escape: true }