"""Escape the `body` part of .chm source file to 7-bit ASCII, to fix visualeffect on some MBCS Windows systems.https://bugs.python.org/issue32174"""import refrom html.entities import codepoint2namefrom sphinx.util.logging import getLogger# escape the characters which codepoint > 0x7Fdef _process(string):def escape(matchobj):codepoint = ord(matchobj.group(0))name = codepoint2name.get(codepoint)if name is None:return '&#%d;' % codepointelse:return '&%s;' % namereturn re.sub(r'[^\x00-\x7F]', escape, string)def escape_for_chm(app, pagename, templatename, context, doctree):# only works for .chm outputif getattr(app.builder, 'name', '') != 'htmlhelp':return# escape the `body` part to 7-bit ASCIIbody = context.get('body')if body is not None:context['body'] = _process(body)def fixup_keywords(app, exception):# only works for .chm outputif getattr(app.builder, 'name', '') != 'htmlhelp' or exception:returngetLogger(__name__).info('fixing HTML escapes in keywords file...')outdir = app.builder.outdiroutname = app.builder.config.htmlhelp_basenamewith app.builder.open_file(outdir, outname + '.hhk', 'r') as f:index = f.read()with app.builder.open_file(outdir, outname + '.hhk', 'w') as f:f.write(index.replace(''', '''))def setup(app):# `html-page-context` event emitted when the HTML builder has# created a context dictionary to render a template with.app.connect('html-page-context', escape_for_chm)# `build-finished` event emitted when all the files have been# output.app.connect('build-finished', fixup_keywords)return {'version': '1.0', 'parallel_read_safe': True}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。