Commit afe17a7b authored by Steve Dower's avatar Steve Dower Committed by GitHub

bpo-35482: Fixes HTML escaping in CHM index and build location of NEWS file (GH-11224)

parent b2f642cc
...@@ -16,7 +16,7 @@ if not defined SPHINXBUILD ( ...@@ -16,7 +16,7 @@ if not defined SPHINXBUILD (
%PYTHON% -m pip install sphinx %PYTHON% -m pip install sphinx
if errorlevel 1 exit /B if errorlevel 1 exit /B
) )
set SPHINXBUILD=%PYTHON% -c "import sphinx, sys; sys.argv[0] = 'sphinx-build'; sys.exit(sphinx.main())" set SPHINXBUILD=%PYTHON% -c "import sphinx.cmd.build, sys; sys.exit(sphinx.cmd.build.main())"
) )
%PYTHON% -c "import python_docs_theme" > nul 2> nul %PYTHON% -c "import python_docs_theme" > nul 2> nul
...@@ -115,17 +115,16 @@ goto end ...@@ -115,17 +115,16 @@ goto end
:build :build
if not exist "%BUILDDIR%" mkdir "%BUILDDIR%" if not exist "%BUILDDIR%" mkdir "%BUILDDIR%"
rem We ought to move NEWS to %BUILDDIR%\NEWS and point rem PY_MISC_NEWS_DIR is also used by our Sphinx extension in tools/extensions/pyspecific.py
rem Sphinx at the right location. if not defined PY_MISC_NEWS_DIR set PY_MISC_NEWS_DIR=%BUILDDIR%\%1
if exist ..\Misc\NEWS ( if exist ..\Misc\NEWS (
echo.Copying Misc\NEWS to build\NEWS echo.Copying Misc\NEWS to %PY_MISC_NEWS_DIR%\NEWS
if not exist build mkdir build copy ..\Misc\NEWS "%PY_MISC_NEWS_DIR%\NEWS" > nul
copy ..\Misc\NEWS build\NEWS > nul
) else if exist ..\Misc\NEWS.D ( ) else if exist ..\Misc\NEWS.D (
if defined BLURB ( if defined BLURB (
echo.Merging Misc/NEWS with %BLURB% echo.Merging Misc/NEWS with %BLURB%
if not exist build mkdir build if not exist build mkdir build
%BLURB% merge -f build\NEWS %BLURB% merge -f "%PY_MISC_NEWS_DIR%\NEWS"
) else ( ) else (
echo.No Misc/NEWS file and Blurb is not available. echo.No Misc/NEWS file and Blurb is not available.
exit /B 1 exit /B 1
......
...@@ -8,6 +8,8 @@ https://bugs.python.org/issue32174 ...@@ -8,6 +8,8 @@ https://bugs.python.org/issue32174
import re import re
from html.entities import codepoint2name from html.entities import codepoint2name
from sphinx.util.logging import getLogger
# escape the characters which codepoint > 0x7F # escape the characters which codepoint > 0x7F
def _process(string): def _process(string):
def escape(matchobj): def escape(matchobj):
...@@ -23,7 +25,7 @@ def _process(string): ...@@ -23,7 +25,7 @@ def _process(string):
def escape_for_chm(app, pagename, templatename, context, doctree): def escape_for_chm(app, pagename, templatename, context, doctree):
# only works for .chm output # only works for .chm output
if not hasattr(app.builder, 'name') or app.builder.name != 'htmlhelp': if getattr(app.builder, 'name', '') != 'htmlhelp':
return return
# escape the `body` part to 7-bit ASCII # escape the `body` part to 7-bit ASCII
...@@ -31,9 +33,25 @@ def escape_for_chm(app, pagename, templatename, context, doctree): ...@@ -31,9 +33,25 @@ def escape_for_chm(app, pagename, templatename, context, doctree):
if body is not None: if body is not None:
context['body'] = _process(body) context['body'] = _process(body)
def fixup_keywords(app, exception):
# only works for .chm output
if getattr(app.builder, 'name', '') != 'htmlhelp' or exception:
return
getLogger(__name__).info('fixing HTML escapes in keywords file...')
outdir = app.builder.outdir
outname = app.builder.config.htmlhelp_basename
with 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): def setup(app):
# `html-page-context` event emitted when the HTML builder has # `html-page-context` event emitted when the HTML builder has
# created a context dictionary to render a template with. # created a context dictionary to render a template with.
app.connect('html-page-context', escape_for_chm) 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} return {'version': '1.0', 'parallel_read_safe': True}
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
import re import re
import io import io
from os import path from os import getenv, path
from time import asctime from time import asctime
from pprint import pformat from pprint import pformat
from docutils.io import StringOutput from docutils.io import StringOutput
...@@ -292,7 +292,9 @@ class MiscNews(Directive): ...@@ -292,7 +292,9 @@ class MiscNews(Directive):
fname = self.arguments[0] fname = self.arguments[0]
source = self.state_machine.input_lines.source( source = self.state_machine.input_lines.source(
self.lineno - self.state_machine.input_offset - 1) self.lineno - self.state_machine.input_offset - 1)
source_dir = path.dirname(path.abspath(source)) source_dir = getenv('PY_MISC_NEWS_DIR')
if not source_dir:
source_dir = path.dirname(path.abspath(source))
fpath = path.join(source_dir, fname) fpath = path.join(source_dir, fname)
self.state.document.settings.record_dependencies.add(fpath) self.state.document.settings.record_dependencies.add(fpath)
try: try:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment