diff options
| author | Pierre-Denis Vanduynslager <[email protected]> | 2016-12-28 19:57:38 -0500 |
|---|---|---|
| committer | Pierre-Denis Vanduynslager <[email protected]> | 2016-12-28 19:57:38 -0500 |
| commit | 425d156df27fa6c18e979aa000bfe5a346ee3450 (patch) | |
| tree | 4157dfcbdf8334e9d9fb2bb239f4ae78706bbc71 /docs/_plugins/highlight_alt.rb | |
| parent | ab2fc63d08b8c53d6f29bcfd73b7f2d5ceaacacd (diff) | |
| parent | e1e621be046a4541a2fd36e445015ee44de3c67e (diff) | |
| download | bootstrap-425d156df27fa6c18e979aa000bfe5a346ee3450.tar.xz bootstrap-425d156df27fa6c18e979aa000bfe5a346ee3450.zip | |
Merge branch 'twbs/v4-dev' into dropdown-keyboard
Diffstat (limited to 'docs/_plugins/highlight_alt.rb')
| -rw-r--r-- | docs/_plugins/highlight_alt.rb | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/docs/_plugins/highlight_alt.rb b/docs/_plugins/highlight_alt.rb index d1ed9ccff..8a86a2202 100644 --- a/docs/_plugins/highlight_alt.rb +++ b/docs/_plugins/highlight_alt.rb @@ -27,14 +27,14 @@ module Jekyll @options[key.to_sym] = value || true end end - @options[:linenos] = "inline" if @options.key?(:linenos) and @options[:linenos] == true + @options[:linenos] = false else raise SyntaxError.new <<-eos -Syntax Error in tag 'highlight' while parsing the following markup: +Syntax Error in tag 'example' while parsing the following markup: #{markup} -Valid syntax: highlight <lang> [linenos] +Valid syntax: example <lang> eos end end @@ -57,16 +57,26 @@ eos def example(output) "<div class=\"bd-example\" data-example-id=\"#{@options[:id]}\">\n#{output}\n</div>" end - + def remove_holderjs(code) code = code.gsub(/data-src="holder.js.+?"/, 'src="..."') end + def remove_example_classes(code) + # Find `bd-` classes and remove them from the highlighted code. Because of how this regex works, it will also + # remove classes that are after the `bd-` class. While this is a bug, I left it because it can be helpful too. + # To fix the bug, replace `(?=")` with `(?=("|\ ))`. + code = code.gsub(/(?!class=".)\ *?bd-.+?(?=")/, "") + # Find empty class attributes after the previous regex and remove those too. + code = code.gsub(/\ class=""/, "") + end + def render_rouge(code) require 'rouge' formatter = Rouge::Formatters::HTML.new(line_numbers: @options[:linenos], wrap: false) lexer = Rouge::Lexer.find_fancy(@lang, code) || Rouge::Lexers::PlainText code = remove_holderjs(code) + code = remove_example_classes(code) code = formatter.format(lexer.lex(code)) "<div class=\"highlight\"><pre>#{code}</pre></div>" end |
