aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorStarsam80 <[email protected]>2016-12-27 15:15:22 -0700
committerMark Otto <[email protected]>2016-12-27 14:15:22 -0800
commite8ff150ab760b4a47bcfc3e2056a430e54e09c90 (patch)
tree24eef46eaffd6d3c20b2f50f20375c3332f7812d /docs
parent069a80254f14add187691e82aed606bba7ffbcd4 (diff)
downloadbootstrap-e8ff150ab760b4a47bcfc3e2056a430e54e09c90.tar.xz
bootstrap-e8ff150ab760b4a47bcfc3e2056a430e54e09c90.zip
Don't show `.bd-*` classes to the user (#21443)
* Don't show `bd-*` classes to the user * Add comments and another regex
Diffstat (limited to 'docs')
-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