diff options
author | Timotheus Kampik <timotheus.kampik@gmail.com> | 2018-12-24 14:57:14 +0100 |
---|---|---|
committer | Timotheus Kampik <timotheus.kampik@gmail.com> | 2018-12-24 14:57:14 +0100 |
commit | 4e3bc5dbef94948660fdf0ec38f130aecf47b186 (patch) | |
tree | 62a6b6c48bacd3d0b40b267bf149732d317df1aa /sphinx/builders/htmlhelp.py | |
parent | 60ef37ce3318dfe25d7532c64b8fabb22cbc7b78 (diff) | |
parent | b229c1a672e9f1e97adfeaa5b43c9c0a2210073f (diff) | |
download | sphinx-git-4e3bc5dbef94948660fdf0ec38f130aecf47b186.tar.gz |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'sphinx/builders/htmlhelp.py')
-rw-r--r-- | sphinx/builders/htmlhelp.py | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/sphinx/builders/htmlhelp.py b/sphinx/builders/htmlhelp.py index 4a9c7e36b..96db0d98f 100644 --- a/sphinx/builders/htmlhelp.py +++ b/sphinx/builders/htmlhelp.py @@ -11,6 +11,7 @@ import html import os +import re from os import path from docutils import nodes @@ -25,7 +26,7 @@ from sphinx.util.osutil import make_filename_from_project if False: # For type annotation - from typing import Any, Dict, IO, List, Tuple # NOQA + from typing import Any, Dict, IO, List, Match, Tuple # NOQA from sphinx.application import Sphinx # NOQA from sphinx.config import Config # NOQA @@ -169,6 +170,24 @@ chm_locales = { } +def chm_htmlescape(*args, **kwargs): + # type: (*Any, **Any) -> str + """ + chm_htmlescape() is a wrapper of htmlescape(). + .hhc/.hhk files don't recognize hex escaping, we need convert + hex escaping to decimal escaping. for example: `'` -> `'` + htmlescape() may generates a hex escaping `'` for single + quote `'`, this wrapper fixes this. + """ + def convert(matchobj): + # type: (Match[str]) -> str + codepoint = int(matchobj.group(1), 16) + return '&#%d;' % codepoint + return re.sub(r'&#[xX]([0-9a-fA-F]+);', + convert, + html.escape(*args, **kwargs)) + + class HTMLHelpBuilder(StandaloneHTMLBuilder): """ Builder that also outputs Windows HTML help project, contents and @@ -278,7 +297,7 @@ class HTMLHelpBuilder(StandaloneHTMLBuilder): write_toc(subnode, ullevel) elif isinstance(node, nodes.reference): link = node['refuri'] - title = html.escape(node.astext()).replace('"', '"') + title = chm_htmlescape(node.astext()).replace('"', '"') f.write(object_sitemap % (title, link)) elif isinstance(node, nodes.bullet_list): if ullevel != 0: @@ -308,7 +327,7 @@ class HTMLHelpBuilder(StandaloneHTMLBuilder): item = ' <param name="%s" value="%s">\n' % \ (name, value) f.write(item) - title = html.escape(title) + title = chm_htmlescape(title) f.write('<LI> <OBJECT type="text/sitemap">\n') write_param('Keyword', title) if len(refs) == 0: |