mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
refactor: htmlhelp: Copy .stp file from template
This commit is contained in:
parent
91b6b46a7e
commit
264a4e8380
@ -17,11 +17,14 @@ from os import path
|
|||||||
from docutils import nodes
|
from docutils import nodes
|
||||||
|
|
||||||
from sphinx import addnodes
|
from sphinx import addnodes
|
||||||
|
from sphinx import package_dir
|
||||||
from sphinx.builders.html import StandaloneHTMLBuilder
|
from sphinx.builders.html import StandaloneHTMLBuilder
|
||||||
from sphinx.deprecation import RemovedInSphinx40Warning
|
from sphinx.deprecation import RemovedInSphinx40Warning
|
||||||
from sphinx.environment.adapters.indexentries import IndexEntries
|
from sphinx.environment.adapters.indexentries import IndexEntries
|
||||||
from sphinx.locale import __
|
from sphinx.locale import __
|
||||||
from sphinx.util import logging
|
from sphinx.util import logging
|
||||||
|
from sphinx.util import progress_message
|
||||||
|
from sphinx.util.fileutil import copy_asset_file
|
||||||
from sphinx.util.nodes import NodeMatcher
|
from sphinx.util.nodes import NodeMatcher
|
||||||
from sphinx.util.osutil import make_filename_from_project
|
from sphinx.util.osutil import make_filename_from_project
|
||||||
|
|
||||||
@ -34,6 +37,8 @@ if False:
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
template_dir = path.join(package_dir, 'templates', 'htmlhelp')
|
||||||
|
|
||||||
|
|
||||||
# Project file (*.hhp) template. 'outname' is the file basename (like
|
# Project file (*.hhp) template. 'outname' is the file basename (like
|
||||||
# the pythlp in pythlp.hhp); 'version' is the doc version number (like
|
# the pythlp in pythlp.hhp); 'version' is the doc version number (like
|
||||||
@ -116,24 +121,6 @@ object_sitemap = '''\
|
|||||||
</OBJECT>
|
</OBJECT>
|
||||||
'''
|
'''
|
||||||
|
|
||||||
# List of words the full text search facility shouldn't index. This
|
|
||||||
# becomes file outname.stp. Note that this list must be pretty small!
|
|
||||||
# Different versions of the MS docs claim the file has a maximum size of
|
|
||||||
# 256 or 512 bytes (including \r\n at the end of each line).
|
|
||||||
# Note that "and", "or", "not" and "near" are operators in the search
|
|
||||||
# language, so no point indexing them even if we wanted to.
|
|
||||||
stopwords = """
|
|
||||||
a and are as at
|
|
||||||
be but by
|
|
||||||
for
|
|
||||||
if in into is it
|
|
||||||
near no not
|
|
||||||
of on or
|
|
||||||
such
|
|
||||||
that the their then there these they this to
|
|
||||||
was will with
|
|
||||||
""".split()
|
|
||||||
|
|
||||||
# The following list includes only languages supported by Sphinx. See
|
# The following list includes only languages supported by Sphinx. See
|
||||||
# https://docs.microsoft.com/en-us/previous-versions/windows/embedded/ms930130(v=msdn.10)
|
# https://docs.microsoft.com/en-us/previous-versions/windows/embedded/ms930130(v=msdn.10)
|
||||||
# for more.
|
# for more.
|
||||||
@ -234,6 +221,7 @@ class HTMLHelpBuilder(StandaloneHTMLBuilder):
|
|||||||
|
|
||||||
def handle_finish(self):
|
def handle_finish(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
|
self.copy_stopword_list()
|
||||||
self.build_hhx(self.outdir, self.config.htmlhelp_basename)
|
self.build_hhx(self.outdir, self.config.htmlhelp_basename)
|
||||||
|
|
||||||
def write_doc(self, docname, doctree):
|
def write_doc(self, docname, doctree):
|
||||||
@ -245,14 +233,24 @@ class HTMLHelpBuilder(StandaloneHTMLBuilder):
|
|||||||
|
|
||||||
super().write_doc(docname, doctree)
|
super().write_doc(docname, doctree)
|
||||||
|
|
||||||
|
@progress_message(__('copying stopword list'))
|
||||||
|
def copy_stopword_list(self):
|
||||||
|
# type: () -> None
|
||||||
|
"""Copy a stopword list (.stp) to outdir.
|
||||||
|
|
||||||
|
The stopword list contains a list of words the full text search facility
|
||||||
|
shouldn't index. Note that this list must be pretty small. Different
|
||||||
|
versions of the MS docs claim the file has a maximum size of 256 or 512
|
||||||
|
bytes (including \r\n at the end of each line). Note that "and", "or",
|
||||||
|
"not" and "near" are operators in the search language, so no point
|
||||||
|
indexing them even if we wanted to.
|
||||||
|
"""
|
||||||
|
template = path.join(template_dir, 'project.stp')
|
||||||
|
filename = path.join(self.outdir, self.config.htmlhelp_basename + '.stp')
|
||||||
|
copy_asset_file(template, filename)
|
||||||
|
|
||||||
def build_hhx(self, outdir, outname):
|
def build_hhx(self, outdir, outname):
|
||||||
# type: (str, str) -> None
|
# type: (str, str) -> None
|
||||||
logger.info(__('dumping stopword list...'))
|
|
||||||
filename = path.join(outdir, outname + '.stp')
|
|
||||||
with open(filename, 'w', encoding=self.encoding, errors='xmlcharrefreplace') as f:
|
|
||||||
for word in sorted(stopwords):
|
|
||||||
print(word, file=f)
|
|
||||||
|
|
||||||
logger.info(__('writing project file...'))
|
logger.info(__('writing project file...'))
|
||||||
filename = path.join(outdir, outname + '.hhp')
|
filename = path.join(outdir, outname + '.hhp')
|
||||||
with open(filename, 'w', encoding=self.encoding, errors='xmlcharrefreplace') as f:
|
with open(filename, 'w', encoding=self.encoding, errors='xmlcharrefreplace') as f:
|
||||||
|
33
sphinx/templates/htmlhelp/project.stp
Normal file
33
sphinx/templates/htmlhelp/project.stp
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
a
|
||||||
|
and
|
||||||
|
are
|
||||||
|
as
|
||||||
|
at
|
||||||
|
be
|
||||||
|
but
|
||||||
|
by
|
||||||
|
for
|
||||||
|
if
|
||||||
|
in
|
||||||
|
into
|
||||||
|
is
|
||||||
|
it
|
||||||
|
near
|
||||||
|
no
|
||||||
|
not
|
||||||
|
of
|
||||||
|
on
|
||||||
|
or
|
||||||
|
such
|
||||||
|
that
|
||||||
|
the
|
||||||
|
their
|
||||||
|
then
|
||||||
|
there
|
||||||
|
these
|
||||||
|
they
|
||||||
|
this
|
||||||
|
to
|
||||||
|
was
|
||||||
|
will
|
||||||
|
with
|
Loading…
Reference in New Issue
Block a user