summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Lechner <david@lechnology.com>2017-10-30 10:22:11 -0500
committerDavid Lechner <david@lechnology.com>2017-10-30 10:23:55 -0500
commit831f89a687d754e3f471075009b9f59b35ec6cab (patch)
tree709d81a28d230fb446042ac0fb55915564a29e76
parent215be8e5bd897bba9d576e2bb957cb038bd356fb (diff)
downloadsphinx-git-831f89a687d754e3f471075009b9f59b35ec6cab.tar.gz
Closes #3160: Use <kbd> tag for :kbd: role in html writers
-rw-r--r--CHANGES1
-rw-r--r--sphinx/writers/html.py17
-rw-r--r--sphinx/writers/html5.py17
-rw-r--r--tests/test_build_html.py2
-rw-r--r--tests/test_build_html5.py2
5 files changed, 27 insertions, 12 deletions
diff --git a/CHANGES b/CHANGES
index 8fa96e052..649d88989 100644
--- a/CHANGES
+++ b/CHANGES
@@ -73,6 +73,7 @@ Features removed
Bugs fixed
----------
+* #3160: Why doesn't Sphinx translate :kbd: roles to HTML's <kbd> tags?
* #3882: Update the order of files for HTMLHelp and QTHelp
* #3962: sphinx-apidoc does not recognize implicit namespace packages correctly
diff --git a/sphinx/writers/html.py b/sphinx/writers/html.py
index 8d02793e3..b3419b70a 100644
--- a/sphinx/writers/html.py
+++ b/sphinx/writers/html.py
@@ -491,14 +491,21 @@ class HTMLTranslator(BaseTranslator):
# overwritten
def visit_literal(self, node):
# type: (nodes.Node) -> None
- self.body.append(self.starttag(node, 'code', '',
- CLASS='docutils literal'))
- self.protect_literal_text += 1
+ if 'kbd' in node['classes']:
+ self.body.append(self.starttag(node, 'kbd', '',
+ CLASS='docutils literal'))
+ else:
+ self.body.append(self.starttag(node, 'code', '',
+ CLASS='docutils literal'))
+ self.protect_literal_text += 1
def depart_literal(self, node):
# type: (nodes.Node) -> None
- self.protect_literal_text -= 1
- self.body.append('</code>')
+ if 'kbd' in node['classes']:
+ self.body.append('</kbd>')
+ else:
+ self.protect_literal_text -= 1
+ self.body.append('</code>')
def visit_productionlist(self, node):
# type: (nodes.Node) -> None
diff --git a/sphinx/writers/html5.py b/sphinx/writers/html5.py
index 51c4e8ecb..1efd060f2 100644
--- a/sphinx/writers/html5.py
+++ b/sphinx/writers/html5.py
@@ -437,14 +437,21 @@ class HTML5Translator(BaseTranslator):
# overwritten
def visit_literal(self, node):
# type: (nodes.Node) -> None
- self.body.append(self.starttag(node, 'code', '',
- CLASS='docutils literal'))
- self.protect_literal_text += 1
+ if 'kbd' in node['classes']:
+ self.body.append(self.starttag(node, 'kbd', '',
+ CLASS='docutils literal'))
+ else:
+ self.body.append(self.starttag(node, 'code', '',
+ CLASS='docutils literal'))
+ self.protect_literal_text += 1
def depart_literal(self, node):
# type: (nodes.Node) -> None
- self.protect_literal_text -= 1
- self.body.append('</code>')
+ if 'kbd' in node['classes']:
+ self.body.append('</kbd>')
+ else:
+ self.protect_literal_text -= 1
+ self.body.append('</code>')
def visit_productionlist(self, node):
# type: (nodes.Node) -> None
diff --git a/tests/test_build_html.py b/tests/test_build_html.py
index 5eaccb2bb..dc06491e8 100644
--- a/tests/test_build_html.py
+++ b/tests/test_build_html.py
@@ -238,7 +238,7 @@ def test_static_output(app):
(".//li/strong", r'^command\\n$'),
(".//li/strong", r'^program\\n$'),
(".//li/em", r'^dfn\\n$'),
- (".//li/code/span[@class='pre']", r'^kbd\\n$'),
+ (".//li/kbd", r'^kbd\\n$'),
(".//li/span", u'File \N{TRIANGULAR BULLET} Close'),
(".//li/code/span[@class='pre']", '^a/$'),
(".//li/code/em/span[@class='pre']", '^varpart$'),
diff --git a/tests/test_build_html5.py b/tests/test_build_html5.py
index 12386705e..771994ca6 100644
--- a/tests/test_build_html5.py
+++ b/tests/test_build_html5.py
@@ -119,7 +119,7 @@ def cached_etree_parse():
(".//li/p/strong", r'^command\\n$'),
(".//li/p/strong", r'^program\\n$'),
(".//li/p/em", r'^dfn\\n$'),
- (".//li/p/code/span[@class='pre']", r'^kbd\\n$'),
+ (".//li/p/kbd", r'^kbd\\n$'),
(".//li/p/span", u'File \N{TRIANGULAR BULLET} Close'),
(".//li/p/code/span[@class='pre']", '^a/$'),
(".//li/p/code/em/span[@class='pre']", '^varpart$'),