Skip to content

Commit 07cf187

Browse files
committed
Support :kbd: shortcut
Closes github#497.
1 parent 14a8a61 commit 07cf187

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

lib/github/commands/rest2html

+8
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ except:
4444

4545
import codecs
4646

47+
from docutils import nodes
48+
from docutils.parsers.rst import roles
4749
from docutils.core import publish_parts
4850
from docutils.writers.html4css1 import Writer, HTMLTranslator
4951

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

132+
def kbd(name, rawtext, text, lineno, inliner, options=None, content=None):
133+
134+
return [nodes.raw('', '<kbd>%s</kbd>' % text, format='html')], []
135+
130136
def main():
131137
"""
132138
Parses the given ReST file or the redirected string input and returns the
@@ -145,6 +151,8 @@ def main():
145151
writer = Writer()
146152
writer.translator_class = GitHubHTMLTranslator
147153

154+
roles.register_canonical_role('kbd', kbd)
155+
148156
parts = publish_parts(text, writer=writer, settings_overrides=SETTINGS)
149157
if 'html_body' in parts:
150158
html = parts['html_body']

test/markups/README.rst

+2
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,5 @@ Field list
5757
:123456789 1234: this should work even with the default :)
5858

5959
60+
61+
Press :kbd:`Ctrl+C` to quit

test/markups/README.rst.html

+2
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,5 @@ <h2><a href="#id2">Field list</a></h2>
7575
</table>
7676

7777
<p><a href="mailto:[email protected]">[email protected]</a></p>
78+
79+
<p>Press <kbd>Ctrl+C</kbd> to quit</p>

0 commit comments

Comments
 (0)