mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Use template for generating .qhp file
This commit is contained in:
parent
dc3faa57b4
commit
c271cc4542
@ -40,37 +40,6 @@ logger = logging.getLogger(__name__)
|
|||||||
_idpattern = re.compile(
|
_idpattern = re.compile(
|
||||||
r'(?P<title>.+) (\((class in )?(?P<id>[\w\.]+)( (?P<descr>\w+))?\))$')
|
r'(?P<title>.+) (\((class in )?(?P<id>[\w\.]+)( (?P<descr>\w+))?\))$')
|
||||||
|
|
||||||
# Qt Help Project (.qhp)
|
|
||||||
# This is the input file for the help generator.
|
|
||||||
# It contains the table of contents, indices and references to the
|
|
||||||
# actual documentation files (*.html).
|
|
||||||
# In addition it defines a unique namespace for the documentation.
|
|
||||||
project_template = u'''\
|
|
||||||
<?xml version="1.0" encoding="utf-8" ?>
|
|
||||||
<QtHelpProject version="1.0">
|
|
||||||
<namespace>%(namespace)s</namespace>
|
|
||||||
<virtualFolder>doc</virtualFolder>
|
|
||||||
<customFilter name="%(project)s %(version)s">
|
|
||||||
<filterAttribute>%(outname)s</filterAttribute>
|
|
||||||
<filterAttribute>%(version)s</filterAttribute>
|
|
||||||
</customFilter>
|
|
||||||
<filterSection>
|
|
||||||
<filterAttribute>%(outname)s</filterAttribute>
|
|
||||||
<filterAttribute>%(version)s</filterAttribute>
|
|
||||||
<toc>
|
|
||||||
<section title="%(title)s" ref="%(masterdoc)s.html">
|
|
||||||
%(sections)s
|
|
||||||
</section>
|
|
||||||
</toc>
|
|
||||||
<keywords>
|
|
||||||
%(keywords)s
|
|
||||||
</keywords>
|
|
||||||
<files>
|
|
||||||
%(files)s
|
|
||||||
</files>
|
|
||||||
</filterSection>
|
|
||||||
</QtHelpProject>
|
|
||||||
'''
|
|
||||||
|
|
||||||
section_template = '<section title="%(title)s" ref="%(ref)s"/>'
|
section_template = '<section title="%(title)s" ref="%(ref)s"/>'
|
||||||
file_template = ' ' * 12 + '<file>%(filename)s</file>'
|
file_template = ' ' * 12 + '<file>%(filename)s</file>'
|
||||||
@ -195,16 +164,12 @@ class QtHelpBuilder(StandaloneHTMLBuilder):
|
|||||||
|
|
||||||
# write the project file
|
# write the project file
|
||||||
with codecs.open(path.join(outdir, outname + '.qhp'), 'w', 'utf-8') as f: # type: ignore # NOQA
|
with codecs.open(path.join(outdir, outname + '.qhp'), 'w', 'utf-8') as f: # type: ignore # NOQA
|
||||||
f.write(project_template % {
|
content = render_file('project.qhp', outname=outname,
|
||||||
'outname': htmlescape(outname),
|
title=self.config.html_title, version=self.config.version,
|
||||||
'title': htmlescape(self.config.html_title),
|
project=self.config.project, namespace=nspace,
|
||||||
'version': htmlescape(self.config.version),
|
master_doc=self.config.master_doc,
|
||||||
'project': htmlescape(self.config.project),
|
sections=sections, keywords=keywords, files=projectfiles)
|
||||||
'namespace': htmlescape(nspace),
|
f.write(content)
|
||||||
'masterdoc': htmlescape(self.config.master_doc),
|
|
||||||
'sections': sections,
|
|
||||||
'keywords': keywords,
|
|
||||||
'files': projectfiles})
|
|
||||||
|
|
||||||
homepage = 'qthelp://' + posixpath.join(
|
homepage = 'qthelp://' + posixpath.join(
|
||||||
nspace, 'doc', self.get_target_uri(self.config.master_doc))
|
nspace, 'doc', self.get_target_uri(self.config.master_doc))
|
||||||
@ -279,9 +244,9 @@ class QtHelpBuilder(StandaloneHTMLBuilder):
|
|||||||
|
|
||||||
if id:
|
if id:
|
||||||
item = ' ' * 12 + '<keyword name="%s" id="%s" ref="%s"/>' % (
|
item = ' ' * 12 + '<keyword name="%s" id="%s" ref="%s"/>' % (
|
||||||
name, id, ref[1])
|
name, id, htmlescape(ref[1]))
|
||||||
else:
|
else:
|
||||||
item = ' ' * 12 + '<keyword name="%s" ref="%s"/>' % (name, ref[1])
|
item = ' ' * 12 + '<keyword name="%s" ref="%s"/>' % (name, htmlescape(ref[1]))
|
||||||
item.encode('ascii', 'xmlcharrefreplace')
|
item.encode('ascii', 'xmlcharrefreplace')
|
||||||
return item
|
return item
|
||||||
|
|
||||||
@ -289,7 +254,7 @@ class QtHelpBuilder(StandaloneHTMLBuilder):
|
|||||||
# type: (unicode, List[Any], Any) -> List[unicode]
|
# type: (unicode, List[Any], Any) -> List[unicode]
|
||||||
keywords = [] # type: List[unicode]
|
keywords = [] # type: List[unicode]
|
||||||
|
|
||||||
title = htmlescape(title)
|
title = htmlescape(title, quote=True)
|
||||||
# if len(refs) == 0: # XXX
|
# if len(refs) == 0: # XXX
|
||||||
# write_param('See Also', title)
|
# write_param('See Also', title)
|
||||||
if len(refs) == 1:
|
if len(refs) == 1:
|
||||||
|
24
sphinx/templates/qthelp/project.qhp
Normal file
24
sphinx/templates/qthelp/project.qhp
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<QtHelpProject version="1.0">
|
||||||
|
<namespace>{{ namespace|e }}</namespace>
|
||||||
|
<virtualFolder>doc</virtualFolder>
|
||||||
|
<customFilter name="{{ project|e }} {{ version|e }}">
|
||||||
|
<filterAttribute>{{ outname|e }}</filterAttribute>
|
||||||
|
<filterAttribute>{{ version|e }}</filterAttribute>
|
||||||
|
</customFilter>
|
||||||
|
<filterSection>
|
||||||
|
<filterAttribute>{{ outname|e }}</filterAttribute>
|
||||||
|
<filterAttribute>{{ version|e }}</filterAttribute>
|
||||||
|
<toc>
|
||||||
|
<section title="{{ title|e }}" ref="{{ master_doc|e }}.html">
|
||||||
|
{{ sections }}
|
||||||
|
</section>
|
||||||
|
</toc>
|
||||||
|
<keywords>
|
||||||
|
{{ keywords }}
|
||||||
|
</keywords>
|
||||||
|
<files>
|
||||||
|
{{ files }}
|
||||||
|
</files>
|
||||||
|
</filterSection>
|
||||||
|
</QtHelpProject>
|
2
tests/roots/test-need-escaped/bar.rst
Normal file
2
tests/roots/test-need-escaped/bar.rst
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
bar
|
||||||
|
===
|
2
tests/roots/test-need-escaped/baz.rst
Normal file
2
tests/roots/test-need-escaped/baz.rst
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
baz
|
||||||
|
===
|
5
tests/roots/test-need-escaped/conf.py
Normal file
5
tests/roots/test-need-escaped/conf.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
master_doc = 'index'
|
||||||
|
project = 'need <b>"escaped"</b> project'
|
||||||
|
smartquotes = False
|
15
tests/roots/test-need-escaped/foo.rst
Normal file
15
tests/roots/test-need-escaped/foo.rst
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<foo>
|
||||||
|
=====
|
||||||
|
|
||||||
|
.. toctree::
|
||||||
|
|
||||||
|
quux
|
||||||
|
|
||||||
|
foo "1"
|
||||||
|
-------
|
||||||
|
|
||||||
|
foo.1-1
|
||||||
|
^^^^^^^
|
||||||
|
|
||||||
|
foo.2
|
||||||
|
-----
|
30
tests/roots/test-need-escaped/index.rst
Normal file
30
tests/roots/test-need-escaped/index.rst
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
.. Sphinx Tests documentation master file, created by sphinx-quickstart on Wed Jun 4 23:49:58 2008.
|
||||||
|
You can adapt this file completely to your liking, but it should at least
|
||||||
|
contain the root `toctree` directive.
|
||||||
|
|
||||||
|
Welcome to Sphinx Tests's documentation!
|
||||||
|
========================================
|
||||||
|
|
||||||
|
Contents:
|
||||||
|
|
||||||
|
.. toctree::
|
||||||
|
:maxdepth: 2
|
||||||
|
:numbered:
|
||||||
|
:caption: Table of Contents
|
||||||
|
:name: mastertoc
|
||||||
|
|
||||||
|
foo
|
||||||
|
bar
|
||||||
|
http://sphinx-doc.org/
|
||||||
|
baz
|
||||||
|
qux
|
||||||
|
|
||||||
|
.. index::
|
||||||
|
pair: "subsection"; <subsection>
|
||||||
|
|
||||||
|
----------
|
||||||
|
subsection
|
||||||
|
----------
|
||||||
|
|
||||||
|
subsubsection
|
||||||
|
-------------
|
2
tests/roots/test-need-escaped/quux.rst
Normal file
2
tests/roots/test-need-escaped/quux.rst
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
quux
|
||||||
|
====
|
1
tests/roots/test-need-escaped/qux.rst
Normal file
1
tests/roots/test-need-escaped/qux.rst
Normal file
@ -0,0 +1 @@
|
|||||||
|
qux.rst has no section title
|
@ -39,26 +39,37 @@ def test_qthelp_basic(app, status, warning):
|
|||||||
assert '<file>Python.qch</file>' in qhcp
|
assert '<file>Python.qch</file>' in qhcp
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx('qthelp', testroot='toctree')
|
@pytest.mark.sphinx('qthelp', testroot='need-escaped')
|
||||||
def test_qthelp_toctree(app, status, warning):
|
def test_qthelp_escaped(app, status, warning):
|
||||||
app.builder.build_all()
|
app.builder.build_all()
|
||||||
|
|
||||||
et = etree_parse(app.outdir / 'Python.qhp')
|
et = etree_parse(app.outdir / 'needbescapedbproject.qhp')
|
||||||
|
customFilter = et.find('.//customFilter')
|
||||||
|
assert len(customFilter) == 2
|
||||||
|
assert customFilter.attrib == {'name': 'need <b>"escaped"</b> project '}
|
||||||
|
assert customFilter[0].text == 'needbescapedbproject'
|
||||||
|
assert customFilter[1].text is None
|
||||||
|
|
||||||
toc = et.find('.//toc')
|
toc = et.find('.//toc')
|
||||||
assert len(toc) == 1
|
assert len(toc) == 1
|
||||||
assert toc[0].attrib == {'title': 'Python documentation',
|
assert toc[0].attrib == {'title': 'need <b>"escaped"</b> project documentation',
|
||||||
'ref': 'index.html'}
|
'ref': 'index.html'}
|
||||||
assert len(toc[0]) == 4
|
assert len(toc[0]) == 4
|
||||||
assert toc[0][0].attrib == {'title': 'foo', 'ref': 'foo.html'}
|
assert toc[0][0].attrib == {'title': '<foo>', 'ref': 'foo.html'}
|
||||||
assert toc[0][1].attrib == {'title': 'bar', 'ref': 'bar.html'}
|
|
||||||
assert toc[0][0][0].attrib == {'title': 'quux', 'ref': 'quux.html'}
|
assert toc[0][0][0].attrib == {'title': 'quux', 'ref': 'quux.html'}
|
||||||
assert toc[0][0][1].attrib == {'title': 'foo.1', 'ref': 'foo.html#foo-1'}
|
assert toc[0][0][1].attrib == {'title': 'foo "1"', 'ref': 'foo.html#foo-1'}
|
||||||
assert toc[0][0][1][0].attrib == {'title': 'foo.1-1', 'ref': 'foo.html#foo-1-1'}
|
assert toc[0][0][1][0].attrib == {'title': 'foo.1-1', 'ref': 'foo.html#foo-1-1'}
|
||||||
assert toc[0][0][2].attrib == {'title': 'foo.2', 'ref': 'foo.html#foo-2'}
|
assert toc[0][0][2].attrib == {'title': 'foo.2', 'ref': 'foo.html#foo-2'}
|
||||||
|
assert toc[0][1].attrib == {'title': 'bar', 'ref': 'bar.html'}
|
||||||
assert toc[0][2].attrib == {'title': 'http://sphinx-doc.org/',
|
assert toc[0][2].attrib == {'title': 'http://sphinx-doc.org/',
|
||||||
'ref': 'http://sphinx-doc.org/'}
|
'ref': 'http://sphinx-doc.org/'}
|
||||||
assert toc[0][3].attrib == {'title': 'baz', 'ref': 'baz.html'}
|
assert toc[0][3].attrib == {'title': 'baz', 'ref': 'baz.html'}
|
||||||
|
|
||||||
|
keywords = et.find('.//keywords')
|
||||||
|
assert len(keywords) == 2
|
||||||
|
assert keywords[0].attrib == {'name': '<subsection>', 'ref': 'index.html#index-0'}
|
||||||
|
assert keywords[1].attrib == {'name': '"subsection"', 'ref': 'index.html#index-0'}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx('qthelp', testroot='basic')
|
@pytest.mark.sphinx('qthelp', testroot='basic')
|
||||||
def test_qthelp_namespace(app, status, warning):
|
def test_qthelp_namespace(app, status, warning):
|
||||||
@ -101,7 +112,8 @@ def test_qthelp_title(app, status, warning):
|
|||||||
app.builder.build_all()
|
app.builder.build_all()
|
||||||
|
|
||||||
qhp = (app.outdir / 'Python.qhp').text()
|
qhp = (app.outdir / 'Python.qhp').text()
|
||||||
assert '<section title="Sphinx <b>"full"</b> title" ref="index.html">' in qhp
|
assert ('<section title="Sphinx <b>"full"</b> title" ref="index.html">'
|
||||||
|
in qhp)
|
||||||
|
|
||||||
qhcp = (app.outdir / 'Python.qhcp').text()
|
qhcp = (app.outdir / 'Python.qhcp').text()
|
||||||
assert '<title>Sphinx <b>"short"</b> title</title>' in qhcp
|
assert '<title>Sphinx <b>"short"</b> title</title>' in qhcp
|
||||||
|
Loading…
Reference in New Issue
Block a user