]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Add support for example IDs to {% example %} template tag
authorChris Rebert <code@rebertia.com>
Wed, 3 Dec 2014 02:46:42 +0000 (18:46 -0800)
committerChris Rebert <code@rebertia.com>
Wed, 3 Dec 2014 02:46:42 +0000 (18:46 -0800)
e.g. {% example html id=some-example-id-here %}

docs/_plugins/highlight_alt.rb

index de84e759da2e78a0cb03c119fa8a6245d15b6ad6..9d1b414bb732aa878ccca4dc14f295c8bf8d6cd8 100644 (file)
@@ -8,7 +8,7 @@ module Jekyll
       # forms: name, name=value, or name="<quoted list>"
       #
       # <quoted list> is a space-separated list of numbers
-      SYNTAX = /^([a-zA-Z0-9.+#-]+)((\s+\w+(=(\w+|"([0-9]+\s)*[0-9]+"))?)*)$/
+      SYNTAX = /^([a-zA-Z0-9.+#-]+)((\s+\w+(=((\w|[0-9_-])+|"([0-9]+\s)*[0-9]+"))?)*)$/
 
       def initialize(tag_name, markup, tokens)
         super
@@ -17,7 +17,7 @@ module Jekyll
           @options = {}
           if defined?($2) && $2 != ''
             # Split along 3 possible forms -- key="<quoted list>", key=value, or key
-            $2.scan(/(?:\w="[^"]*"|\w=\w|\w)+/) do |opt|
+            $2.scan(/(?:\w+(?:=(?:(?:\w|[0-9_-])+|"[^"]*")?)?)/) do |opt|
               key, value = opt.split('=')
               # If a quoted list, convert to array
               if value && value.include?("\"")
@@ -55,7 +55,7 @@ eos
       end
 
       def example(output)
-        "<div class=\"bs-example\">#{output}</div>"
+        "<div class=\"bs-example\" data-example-id=\"#{@options[:id]}\">\n#{output}\n</div>"
       end
 
       def render_rouge(code)