Skip to content

Commit

Permalink
Support :kbd: shortcut
Browse files Browse the repository at this point in the history
Closes github#497.
  • Loading branch information
gjtorikian committed Jun 5, 2015
1 parent 14a8a61 commit 07cf187
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/github/commands/rest2html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ except:

import codecs

from docutils import nodes
from docutils.parsers.rst import roles
from docutils.core import publish_parts
from docutils.writers.html4css1 import Writer, HTMLTranslator

Expand Down Expand Up @@ -127,6 +129,10 @@ class GitHubHTMLTranslator(HTMLTranslator):
self.body.append(self.starttag(node, 'img', **atts))
self.body.append(self.context.pop())

def kbd(name, rawtext, text, lineno, inliner, options=None, content=None):

return [nodes.raw('', '<kbd>%s</kbd>' % text, format='html')], []

def main():
"""
Parses the given ReST file or the redirected string input and returns the
Expand All @@ -145,6 +151,8 @@ def main():
writer = Writer()
writer.translator_class = GitHubHTMLTranslator

roles.register_canonical_role('kbd', kbd)

parts = publish_parts(text, writer=writer, settings_overrides=SETTINGS)
if 'html_body' in parts:
html = parts['html_body']
Expand Down
2 changes: 2 additions & 0 deletions test/markups/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ Field list
:123456789 1234: this should work even with the default :)

[email protected]

Press :kbd:`Ctrl+C` to quit
2 changes: 2 additions & 0 deletions test/markups/README.rst.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,5 @@ <h2><a href="#id2">Field list</a></h2>
</table>

<p><a href="mailto:[email protected]">[email protected]</a></p>

<p>Press <kbd>Ctrl+C</kbd> to quit</p>

0 comments on commit 07cf187

Please sign in to comment.