From 07cf1870d508fd94ae15da31136d4b0ecff52cab Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Fri, 5 Jun 2015 14:42:24 -0700 Subject: [PATCH] Support `:kbd:` shortcut Closes https://github.com/github/markup/issues/497. --- lib/github/commands/rest2html | 8 ++++++++ test/markups/README.rst | 2 ++ test/markups/README.rst.html | 2 ++ 3 files changed, 12 insertions(+) diff --git a/lib/github/commands/rest2html b/lib/github/commands/rest2html index 413437f9..b9dc5c29 100755 --- a/lib/github/commands/rest2html +++ b/lib/github/commands/rest2html @@ -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 @@ -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('', '%s' % text, format='html')], [] + def main(): """ Parses the given ReST file or the redirected string input and returns the @@ -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'] diff --git a/test/markups/README.rst b/test/markups/README.rst index 53f1e62d..ccabe9e7 100644 --- a/test/markups/README.rst +++ b/test/markups/README.rst @@ -57,3 +57,5 @@ Field list :123456789 1234: this should work even with the default :) someone@somewhere.org + +Press :kbd:`Ctrl+C` to quit diff --git a/test/markups/README.rst.html b/test/markups/README.rst.html index 3719a66c..af777045 100644 --- a/test/markups/README.rst.html +++ b/test/markups/README.rst.html @@ -75,3 +75,5 @@

Field list

someone@somewhere.org

+ +

Press Ctrl+C to quit