diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2013-05-29 14:52:44 -0700 |
|---|---|---|
| committer | Dan Allen <dan.j.allen@gmail.com> | 2013-05-29 14:52:44 -0700 |
| commit | a6beec228b9757d4ff934ea3573b03b5b346eea1 (patch) | |
| tree | 7433c6f3a749d3efcbeed33089306c52c1db8850 /lib | |
| parent | 1cc746f64ae4e897af003e5e9193fddf7045ded5 (diff) | |
| parent | 83e1389c8b1afc011c5637b0d28d824891717323 (diff) | |
Merge pull request #375 from mojavelinux/kbd-inline-macro
resolves #172 Add kbd inline macro
Diffstat (limited to 'lib')
| -rwxr-xr-x | lib/asciidoctor.rb | 10 | ||||
| -rw-r--r-- | lib/asciidoctor/backends/_stylesheets.rb | 4 | ||||
| -rw-r--r-- | lib/asciidoctor/backends/docbook45.rb | 16 | ||||
| -rw-r--r-- | lib/asciidoctor/backends/html5.rb | 16 | ||||
| -rw-r--r-- | lib/asciidoctor/substituters.rb | 31 |
5 files changed, 77 insertions, 0 deletions
diff --git a/lib/asciidoctor.rb b/lib/asciidoctor.rb index 3bf89b52..8b564c8e 100755 --- a/lib/asciidoctor.rb +++ b/lib/asciidoctor.rb @@ -325,6 +325,10 @@ module Asciidoctor # one two three :space_delim => /([^\\])[[:blank:]]+/, + # Ctrl + Alt+T + # Ctrl,T + :kbd_delim => /(?:\+|,)(?=[[:blank:]]*[^\1])/, + # one\ two\ three :escaped_space => /\\([[:blank:]])/, @@ -356,6 +360,12 @@ module Asciidoctor # footnoteref:[id] :footnote_macro => /\\?(footnote|footnoteref):\[((?:\\\]|[^\]])*?)\]/, + # kbd:[F3] + # kbd:[Ctrl+Shift+T] + # kbd:[Ctrl+\]] + # kbd:[Ctrl,T] + :kbd_macro => /\\?kbd:\[((?:\\\]|[^\]])+?)\]/, + # image::filename.png[Caption] # video::http://youtube.com/12345[Cats vs Dogs] :media_blk_macro => /^(image|video|audio)::(\S+?)\[((?:\\\]|[^\]])*?)\]$/, diff --git a/lib/asciidoctor/backends/_stylesheets.rb b/lib/asciidoctor/backends/_stylesheets.rb index cd6f9582..1bbecd40 100644 --- a/lib/asciidoctor/backends/_stylesheets.rb +++ b/lib/asciidoctor/backends/_stylesheets.rb @@ -143,6 +143,10 @@ table tr.even, table tr.alt, table tr:nth-of-type(even) { background: #f9f9f9; } table thead tr th, table tfoot tr th, table tbody tr td, table tr td, table tfoot tr td { display: table-cell; line-height: 1.6; } pre > code, pre > tt { color: #222222; } tt { font-size: 0.9375em; padding: 1px 3px 0; white-space: nowrap; background-color: #f2f2f2; border: 1px solid #cccccc; -webkit-border-radius: 4px; border-radius: 4px; text-shadow: none; } +kbd.combo { color: #555555; } +kbd:not(.combo) { display: inline-block; color: #222222; font-size: 0.75em; line-height: 1.4; background-color: #F7F7F7; border: 1px solid #ccc; -webkit-border-radius: 3px; border-radius: 3px; -webkit-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 0 0 2px white inset; box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 0 0 2px white inset; margin: -0.15em 0.15em 0 0.15em; padding: 0.2em 0.6em 0.2em 0.5em; vertical-align: middle; white-space: nowrap; } +kbd kbd:first-child { margin-left: 0; } +kbd kbd:last-child { margin-right: 0; } p a > tt { text-decoration: underline; } p a > tt:hover { color: #561309; } #header, #content, #footnotes, #footer { width: 100%; margin-left: auto; margin-right: auto; margin-top: 0; margin-bottom: 0; max-width: 62.5em; *zoom: 1; position: relative; padding-left: 0.9375em; padding-right: 0.9375em; } diff --git a/lib/asciidoctor/backends/docbook45.rb b/lib/asciidoctor/backends/docbook45.rb index 6facd2a7..3f5af92d 100644 --- a/lib/asciidoctor/backends/docbook45.rb +++ b/lib/asciidoctor/backends/docbook45.rb @@ -650,6 +650,22 @@ class InlineQuotedTemplate < BaseTemplate end end +class InlineKbdTemplate < BaseTemplate + def result(node) + keys = node.attr 'keys' + if keys.size == 1 + %(<keycap>#{keys.first}</keycap>) + else + key_combo = keys.map{|key| %(<keycap>#{key}</keycap>) }.join + %(<keycombo>#{key_combo}</keycombo>) + end + end + + def template + :invoke_result + end +end + class InlineAnchorTemplate < BaseTemplate def anchor(target, text, type) case type diff --git a/lib/asciidoctor/backends/html5.rb b/lib/asciidoctor/backends/html5.rb index c063e82f..e80c647d 100644 --- a/lib/asciidoctor/backends/html5.rb +++ b/lib/asciidoctor/backends/html5.rb @@ -858,6 +858,22 @@ class InlineQuotedTemplate < BaseTemplate end end +class InlineKbdTemplate < BaseTemplate + def result(node) + keys = node.attr 'keys' + if keys.size == 1 + %(<kbd>#{keys.first}</kbd>) + else + key_combo = keys.map{|key| %(<kbd>#{key}</kbd>+) }.join.chop + %(<kbd class="combo">#{key_combo}</kbd>) + end + end + + def template + :invoke_result + end +end + class InlineAnchorTemplate < BaseTemplate def anchor(target, text, type, document, node) case type diff --git a/lib/asciidoctor/substituters.rb b/lib/asciidoctor/substituters.rb index 8ce429f1..b2ce3e1b 100644 --- a/lib/asciidoctor/substituters.rb +++ b/lib/asciidoctor/substituters.rb @@ -349,6 +349,37 @@ module Substituters found[:macroish_short_form] = (found[:square_bracket] && found[:colon] && result.include?(':[')) found[:uri] = (found[:colon] && result.include?('://')) use_link_attrs = @document.attributes.has_key?('use-link-attrs') + experimental = @document.attributes.has_key?('experimental') + + if experimental + if found[:macroish_short_form] && result.include?('kbd:') + result.gsub!(REGEXP[:kbd_macro]) { + captured = $~[0] + keys = $~[1] + # honor the escape + if captured.start_with? '\\' + next captured[1..-1] + end + + keys = unescape_bracketed_text keys + if keys == '+' + keys = ['+'] + else + # need to use closure to work around lack of negative lookbehind + keys = keys.split(REGEXP[:kbd_delim]).inject([]) {|c, key| + if key.end_with?('++') + c << key[0..-3].strip + c << '+' + else + c << key.strip + end + c + } + end + Inline.new(self, :kbd, nil, :attributes => {'keys' => keys}).render + } + end + end if found[:macroish] && result.include?('image:') # image:filename.png[Alt Text] |
