Add post-processing for the sphinx htmlhelp output before build

* Copies our .hhk into the build folder
* Removes TOC entries that just refer to anchors - it's unnecessary and
  just clutters up the TOC.
This commit is contained in:
baldurk
2016-05-16 16:29:08 +02:00
parent afc5c81d4c
commit 29f1d1af62
4 changed files with 47 additions and 1 deletions
+5
View File
@@ -86,6 +86,11 @@ json:
.PHONY: htmlhelp
htmlhelp:
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
# Copy handwritten index file to output, overwriting auto-generated one
@cp renderdoc.hhk $(BUILDDIR)/htmlhelp
# Filter out the auto-generated TOC to remove anchor links and root index.html
@cat $(BUILDDIR)/htmlhelp/renderdoc.hhc | python remove_lines.py ".html#" | python remove_lines.py "\"index.html\"" > $(BUILDDIR)/htmlhelp/tmp
@mv $(BUILDDIR)/htmlhelp/tmp $(BUILDDIR)/htmlhelp/renderdoc.hhc
@echo
@echo "Build finished; now you can run HTML Help Workshop with the" \
".hhp project file in $(BUILDDIR)/htmlhelp."
+6 -1
View File
@@ -5,7 +5,7 @@ REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set BUILDDIR=../Documentation
set BUILDDIR=..\Documentation
set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% .
set I18NSPHINXOPTS=%SPHINXOPTS% .
if NOT "%PAPER%" == "" (
@@ -117,6 +117,11 @@ if "%1" == "json" (
if "%1" == "htmlhelp" (
%SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
if errorlevel 1 exit /b 1
REM Copy handwritten index file to output, overwriting auto-generated one
copy renderdoc.hhk %BUILDDIR%\htmlhelp\
REM Filter out the auto-generated TOC to remove anchor links and root index.html
type %BUILDDIR%\htmlhelp\renderdoc.hhc | python remove_lines.py ".html#" | python remove_lines.py "\"index.html\"" > %BUILDDIR%\htmlhelp\tmp
move %BUILDDIR%\htmlhelp\tmp %BUILDDIR%\htmlhelp\renderdoc.hhc
echo.
echo.Build finished; now you can run HTML Help Workshop with the ^
.hhp project file in %BUILDDIR%/htmlhelp.
+5
View File
@@ -101,6 +101,11 @@ fi
if [ $1 == "htmlhelp" ]; then
$SPHINXBUILD -b htmlhelp $ALLSPHINXOPTS $BUILDDIR/htmlhelp
if [ $? != 0 ]; then exit 1; fi
# Copy handwritten index file to output, overwriting auto-generated one
cp renderdoc.hhk $BUILDDIR/htmlhelp
# Filter out the auto-generated TOC to remove anchor links and root index.html
cat $BUILDDIR/htmlhelp/renderdoc.hhc | python remove_lines.py ".html#" | python remove_lines.py "\"index.html\"" > $BUILDDIR/htmlhelp/tmp
mv $BUILDDIR/htmlhelp/tmp $BUILDDIR/htmlhelp/renderdoc.hhc
echo
echo "Build finished; now you can run HTML Help Workshop with the "
echo ".hhp project file in $BUILDDIR/htmlhelp."
+31
View File
@@ -0,0 +1,31 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Script taken from http://stackoverflow.com/a/17579949/4070143 by inspectorG4dget
# to remove lines above and below certain string match.
# Minor modifications to read and write from stdin/stdout respectively
# and to remove some extra newlines getting added
import sys
def remLines(delim, above, below):
buff = []
line = sys.stdin.readline()
while line:
if delim in line.strip():
buff = []
for _ in range(below):
sys.stdin.readline()
else:
if len(buff) == above:
print(buff[0].replace('\r', '').replace('\n', ''))
buff = buff[1:]
buff.append(line)
line = sys.stdin.readline()
print(''.join(buff).strip())
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Error: no search pattern specified")
else:
remLines(sys.argv[1], 2, 1)