aboutsummaryrefslogtreecommitdiff
path: root/docs/_plugins/highlight_alt.rb
diff options
context:
space:
mode:
authorMark Otto <[email protected]>2016-12-28 15:52:28 -0800
committerMark Otto <[email protected]>2016-12-28 15:52:28 -0800
commit047d4a77da5af8b59fd562935669c550272f57a6 (patch)
tree7a2daf4d737693826c6d264113adc6e987c3ae2a /docs/_plugins/highlight_alt.rb
parent11d52ba9498990483d822a5a42d371393a110080 (diff)
parente1e621be046a4541a2fd36e445015ee44de3c67e (diff)
downloadbootstrap-047d4a77da5af8b59fd562935669c550272f57a6.tar.xz
bootstrap-047d4a77da5af8b59fd562935669c550272f57a6.zip
Merge branch 'v4-dev' into v4-docs-streamlined
Diffstat (limited to 'docs/_plugins/highlight_alt.rb')
-rw-r--r--docs/_plugins/highlight_alt.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/docs/_plugins/highlight_alt.rb b/docs/_plugins/highlight_alt.rb
index bdcada251..8a86a2202 100644
--- a/docs/_plugins/highlight_alt.rb
+++ b/docs/_plugins/highlight_alt.rb
@@ -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