diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2018-12-26 00:37:55 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2018-12-26 00:37:55 +0900 |
commit | b5c0edc9494627f8dd4c246a9d581096338e6af0 (patch) | |
tree | 738ce97ac1a3c73e2c1d5335bad33b7dab6cdf86 /sphinx/builders/htmlhelp.py | |
parent | ed411fdbeb162b2aeff850416700e78739cc95a3 (diff) | |
parent | 920aafaee60413f4e536f3168f3122779df01683 (diff) | |
download | sphinx-git-b5c0edc9494627f8dd4c246a9d581096338e6af0.tar.gz |
Merge branch '1.8'
Diffstat (limited to 'sphinx/builders/htmlhelp.py')
-rw-r--r-- | sphinx/builders/htmlhelp.py | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/sphinx/builders/htmlhelp.py b/sphinx/builders/htmlhelp.py index 96db0d98f..641761b69 100644 --- a/sphinx/builders/htmlhelp.py +++ b/sphinx/builders/htmlhelp.py @@ -11,7 +11,6 @@ import html import os -import re from os import path from docutils import nodes @@ -170,22 +169,18 @@ chm_locales = { } -def chm_htmlescape(*args, **kwargs): - # type: (*Any, **Any) -> str +def chm_htmlescape(s, quote=True): + # type: (str, bool) -> str """ - chm_htmlescape() is a wrapper of htmlescape(). + chm_htmlescape() is a wrapper of html.escape(). .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. + hex escaping to decimal escaping. for example: ``'`` -> ``'`` + html.escape() 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)) + s = html.escape(s, quote) + s = s.replace(''', ''') # re-escape as decimal + return s class HTMLHelpBuilder(StandaloneHTMLBuilder): @@ -297,7 +292,7 @@ class HTMLHelpBuilder(StandaloneHTMLBuilder): write_toc(subnode, ullevel) elif isinstance(node, nodes.reference): link = node['refuri'] - title = chm_htmlescape(node.astext()).replace('"', '"') + title = chm_htmlescape(node.astext(), True) f.write(object_sitemap % (title, link)) elif isinstance(node, nodes.bullet_list): if ullevel != 0: @@ -324,10 +319,9 @@ class HTMLHelpBuilder(StandaloneHTMLBuilder): # type: (str, List[Tuple[str, str]], List[Tuple[str, List[Tuple[str, str]]]]) -> None # NOQA def write_param(name, value): # type: (str, str) -> None - item = ' <param name="%s" value="%s">\n' % \ - (name, value) + item = ' <param name="%s" value="%s">\n' % (name, value) f.write(item) - title = chm_htmlescape(title) + title = chm_htmlescape(title, True) f.write('<LI> <OBJECT type="text/sitemap">\n') write_param('Keyword', title) if len(refs) == 0: |