a lion, a head, and a dash - fosdem.org · a lion, a head, and a dash of yaml extending sphinx to...
TRANSCRIPT
![Page 1: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/1.jpg)
A lion, a head, and a dashof YAMLExtending Sphinx to automate your documentation
FOSDEM 2018
@stephenfin
![Page 2: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/2.jpg)
reStructuredText, Docutils &Sphinx
1
![Page 3: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/3.jpg)
A little reStructuredText=========================
This document demonstrates some basic features of |rst|. You can use **bold** and *italics*, along with ``literals``. It’s quite similar to `Markdown`_ but much more extensible. CommonMark may one day approach this [1]_, but today is not that day. `docutils`__ does all this for us.
.. |rst| replace:: **reStructuredText**
.. _Markdown: https://daringfireball.net/projects/markdown/
.. [1] https://talk.commonmark.org/t/444
.. __ http://docutils.sourceforge.net/
![Page 4: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/4.jpg)
A little reStructuredText=========================
This document demonstrates some basic features of |rst|. You can use **bold** and *italics*, along with ``literals``. It’s quite similar to `Markdown`_ but much more extensible. CommonMark may one day approach this [1]_, but today is not that day. `docutils`__ does all this for us.
.. |rst| replace:: **reStructuredText**
.. _Markdown: https://daringfireball.net/projects/markdown/
.. [1] https://talk.commonmark.org/t/444
.. __ http://docutils.sourceforge.net/
![Page 5: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/5.jpg)
A little reStructuredText
This document demonstrates some basic features of reStructuredText. You can use bold and italics, along with literals. It’s quite similar to Markdown but much more extensible. CommonMark may one day approach this [1], but today is not that day.
docutils does all this for us.
[1] https://talk.commonmark.org/t/444/
![Page 6: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/6.jpg)
A little more reStructuredText==============================The extensibility really comes into play with directives androles. We can do things like link to RFCs (:RFC:`2324`, anyone?)or generate some more advanced formatting (I do love me someH\ :sub:`2`\ O).
.. warning::
The power can be intoxicating.
Of course, all the stuff we showed previously *still works!*. The only limit is your imagination/interest.
![Page 7: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/7.jpg)
A little more reStructuredText==============================The extensibility really comes into play with directives androles. We can do things like link to RFCs (:RFC:`2324`, anyone?)or generate some more advanced formatting (I do love me someH\ :sub:`2`\ O).
.. warning::
The power can be intoxicating.
Of course, all the stuff we showed previously *still works!*. The only limit is your imagination/interest.
![Page 8: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/8.jpg)
A little more reStructuredText
The extensibility really comes into play with directives and roles. We can do things
like link to RFCs (RFC 2324, anyone?) or generate some more advanced formatting(I do love me some H
2O).
WarningThe power can be intoxicating.
Of course, all the stuff we showed previously still works!. The only limit is your imagination/interest.
![Page 9: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/9.jpg)
reStructuredText provides the syntax
Docutils provides the parsing
![Page 10: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/10.jpg)
reStructuredText provides the syntax
Docutils provides the parsing
Sphinx provides the cross-referencing and file generation
![Page 11: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/11.jpg)
Docutils use readers, parsers, transforms, and writers
Docutils works with individual files
![Page 12: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/12.jpg)
Docutils use readers, parsers, transforms, and writers
Docutils works with individual files
Sphinx uses readers, writers, transforms, and builders
Sphinx works with multiple, cross-referenced files
![Page 13: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/13.jpg)
Documentation tool
Multiple output formats
Extensive cross-referencing support
Extensions
![Page 14: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/14.jpg)
Documentation tool
Multiple output formats
Extensive cross-referencing support
Extensions
![Page 15: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/15.jpg)
sphinx-quickstart
sphinx-build
sphinx-apidoc
sphinx-autogen
![Page 16: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/16.jpg)
sphinx-quickstart
sphinx-build
sphinx-apidoc
sphinx-autogen
![Page 17: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/17.jpg)
Let’s Get To Extending...
2
![Page 18: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/18.jpg)
Current version of Sphinx (1.7.0) - APIs may change
Python knowledge is expected
Some possible references to OpenStack projects
See github.com/stephenfin/fosdem-sphinx-demo for more
![Page 19: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/19.jpg)
Extensions are registered via sphinx.application.Application
add_builderadd_config_value
add_domainadd_eventadd_node
add_directiveadd_role
connect, disconnect...
(Builders)(Config Values)(Domains)(Events)(docutils Nodes)(Directives)(Interpreted Text Roles, a.k.a. Roles)(Hooks)...
![Page 20: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/20.jpg)
Extensions are registered via sphinx.application.Application
add_builderadd_config_value
add_domainadd_eventadd_node
add_directiveadd_role
connect, disconnect...
(Builders)(Config Values)(Domains)(Events)(docutils Nodes)(Directives)(Interpreted Text Roles, a.k.a. Roles)(Hooks)...
![Page 21: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/21.jpg)
Interpreted Text Roles
3
(a.k.a. roles)
![Page 22: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/22.jpg)
A little more reStructuredText==============================The extensibility really comes into play with directives androles. We can do things like link to RFCs (:RFC:`2324`, anyone?)or generate some more advanced formatting (I do love me someH\ :sub:`2`\ O).
.. warning::
The power can be intoxicating.
Of course, all the stuff we showed previously *still works!*. The only limit is your imagination/interest.
![Page 23: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/23.jpg)
A little more reStructuredText==============================The extensibility really comes into play with directives androles. We can do things like link to RFCs (:RFC:`2324`, anyone?)or generate some more advanced formatting (I do love me someH\ :sub:`2`\ O).
.. warning::
The power can be intoxicating.
Of course, all the stuff we showed previously *still works!*. Theonly limit is your imagination/interest.
![Page 24: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/24.jpg)
def xyz_role(name, rawtext, text, lineno, inliner, options={}, content=[]): # code...
def setup(app): app.add_role('xyz', xyz_role) return {'version': '1.0', 'parallel_read_safe': True}
![Page 25: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/25.jpg)
Fixes=====
* #2951: Add ``--implicit-namespaces`` PEP-0420 support to apidoc.* Add ``:caption:`` option for sphinx.ext.inheritance_diagram.* #2471: Add config variable for default doctest flags.* Convert linkcheck builder to requests for better encoding handling* #2463, #2516: Add keywords of "meta" directive to search index
source/changes.rst
![Page 26: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/26.jpg)
Fixes=====
* #2951: Add ``--implicit-namespaces`` PEP-0420 support to apidoc.* Add ``:caption:`` option for sphinx.ext.inheritance_diagram.* #2471: Add config variable for default doctest flags.* Convert linkcheck builder to requests for better encoding handling* #2463, #2516: Add keywords of "meta" directive to search index
source/changes.rst
![Page 27: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/27.jpg)
Fixes=====
* #2951: Add ``--implicit-namespaces`` PEP-0420 support to apidoc.* Add ``:caption:`` option for sphinx.ext.inheritance_diagram.* #2471: Add config variable for default doctest flags.* Convert linkcheck builder to requests for better encoding handling* #2463, #2516: Add keywords of "meta" directive to search index
source/changes.rst
![Page 28: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/28.jpg)
Fixes=====
* Add ``--implicit-namespaces`` PEP-0420 support to apidoc (:ghissue:`2951`).* Add ``:caption:`` option for sphinx.ext.inheritance_diagram.* Add config variable for default doctest flags (:ghissue:`2471`).* Convert linkcheck builder to requests for better encoding handling* Add keywords of "meta" directive to search index (:ghissue:`2463`, :ghissue:`2516`)
source/changes.rst
![Page 29: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/29.jpg)
Fixes=====
* Add ``--implicit-namespaces`` PEP-0420 support to apidoc (:ghissue:`2951`).* Add ``:caption:`` option for sphinx.ext.inheritance_diagram.* Add config variable for default doctest flags (:ghissue:`2471`).* Convert linkcheck builder to requests for better encoding handling* Add keywords of "meta" directive to search index (:ghissue:`2463`, :ghissue:`2516`)
source/changes.rst
![Page 30: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/30.jpg)
from docutils import nodes
BASE_URL = 'https://github.com/sphinx-doc/sphinx/issues/{}'
def github_issue(name, rawtext, text, lineno, inliner, options={}, content=[]): refuri = BASE_URL.format(text) node = nodes.reference(rawtext, text, refuri=refuri, **options) return [node], []
def setup(app): app.add_role('ghissue', github_issue) return {'version': '1.0', 'parallel_read_safe': True}
ext/issue_role.py
![Page 31: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/31.jpg)
from docutils import nodes
BASE_URL = 'https://github.com/sphinx-doc/sphinx/issues/{}'
def github_issue(name, rawtext, text, lineno, inliner, options={}, content=[]): refuri = BASE_URL.format(text) node = nodes.reference(rawtext, text, refuri=refuri, **options) return [node], []
def setup(app): app.add_role('ghissue', github_issue) return {'version': '1.0', 'parallel_read_safe': True}
ext/issue_role.py
![Page 32: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/32.jpg)
Fixes=====
* Add ``--implicit-namespaces`` PEP-0420 support to apidoc (:ghissue:`2951`)* Add ``:caption:`` option for sphinx.ext.inheritance_diagram* Add config variable for default doctest flags (:ghissue:`2471`)* Convert linkcheck builder to requests for better encoding handling* Add keywords of "meta" directive to search index (:ghissue:`2463`, :ghissue:`2516`)
source/changes.rst
![Page 33: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/33.jpg)
Fixes
● Add --implicit-namespaces PEP-0420 support to apidoc (2951)● Add :caption: option for sphinx.ext.inheritance_diagram
● Add config variable for default doctest flags (2471)● Convert linkcheck builder to requests for better encoding handling● Add keywords of “meta” directive to search index (2463, 2516)
build/changes.html
![Page 34: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/34.jpg)
Directives
4
![Page 35: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/35.jpg)
A little more reStructuredText==============================The extensibility really comes into play with directives androles. We can do things like link to RFCs (:RFC:`2324`, anyone?)or generate some more advanced formatting (I do love me someH\ :sub:`2`\ O).
.. warning::
The power can be intoxicating.
Of course, all the stuff we showed previously *still works!*. The only limit is your imagination/interest.
![Page 36: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/36.jpg)
A little more reStructuredText==============================The extensibility really comes into play with directives androles. We can do things like link to RFCs (:RFC:`2324`, anyone?)or generate some more advanced formatting (I do love me someH\ :sub:`2`\ O).
.. warning::
The power can be intoxicating.
Of course, all the stuff we showed previously *still works!*. Theonly limit is your imagination/interest.
![Page 37: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/37.jpg)
from docutils import nodesfrom docutils.parsers.rst import Directive
class XYZDirective(Directive): def run(self): section = nodes.section(ids=['test']) section += nodes.title(text='Test') section += nodes.paragraph(text='Hello, world!') return [section]
def setup(app): app.add_directive('xyz-directive', XYZDirective) return {'version': '1.0', 'parallel_read_safe': True}
![Page 38: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/38.jpg)
Issues======
Add keywords of "meta" directive to search index (#2463)--------------------------------------------------------
Opened by TimKam ::
It would be great to have the keywords of `meta` directives included in the search index.
Like this, one can help users who are searching for a synonym of the "correct" term through simply adding synonyms as keywords to a meta directive on the corresponding page.
source/issues.rst
![Page 39: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/39.jpg)
Issues======
Add keywords of "meta" directive to search index (#2463)--------------------------------------------------------
Opened by TimKam ::
It would be great to have the keywords of `meta` directives included in the search index.
Like this, one can help users who are searching for a synonym of the "correct" term through simply adding synonyms as keywords to a meta directive on the corresponding page.
source/issues.rst
![Page 40: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/40.jpg)
Issues======
.. github-issue:: 2463
source/issues.rst
![Page 41: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/41.jpg)
from docutils import nodesfrom docutils.parsers.rst import Directiveimport requests
URL = 'https://api.github.com/repos/sphinx-doc/sphinx/issues/{}'
def get_issue(issue_id): issue = requests.get(URL.format(issue_id)).json() title = '%s (#%s)' % (issue['title'], issue_id) owner = 'Opened by %s' issue['user']['login']
return issue_id, title, issue['body'], owner
...
ext/issue_directive.py
![Page 42: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/42.jpg)
...
class ShowGitHubIssue(Directive): required_arguments = 1
def run(self): issue = get_issue(self.arguments[0])
section = nodes.section(ids=['github-issue-%s' % issue[0]]) section += nodes.title(text=issue[1]) section += nodes.paragraph(text='Opened by %s' % issue[3]) section += nodes.literal_block(text=issue[2])
return [section]
ext/issue_directive.py
![Page 43: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/43.jpg)
...
class ShowGitHubIssue(Directive): required_arguments = 1
def run(self): issue = get_issue(self.arguments[0])
section = nodes.section(ids=['github-issue-%s' % issue[0]]) section += nodes.title(text=issue[1]) section += nodes.paragraph(text='Opened by %s' % issue[3]) section += nodes.literal_block(text=issue[2])
return [section]
ext/issue_directive.py
![Page 44: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/44.jpg)
...
class ShowGitHubIssue(Directive): required_arguments = 1
def run(self): issue = get_issue(self.arguments[0])
section = nodes.section(ids=['github-issue-%s' % issue[0]]) section += nodes.title(text=issue[1]) section += nodes.paragraph(text='Opened by %s' % issue[3]) section += nodes.literal_block(text=issue[2])
return [section]
ext/issue_directive.py
![Page 45: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/45.jpg)
...
def setup(app): app.add_directive('github-issue', ShowGitHubIssue) return {'version': '1.0', 'parallel_read_safe': True}
ext/issue_directive.py
![Page 46: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/46.jpg)
Issues======
.. github-issue:: 2463
source/issues.rst
![Page 47: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/47.jpg)
Issues
Add keywords of “meta” directive to search index (#2463)
Opened by TimKam
build/issues.html
It would be great to have the keywords of `meta` directives included in the search index.
Like this, one can help users who are searching for a synonym of the "correct" term through simply adding synonyms as keywords to a `meta` directive on the corresponding page.
![Page 48: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/48.jpg)
class ShowGitHubIssue(Directive): required_arguments = 1
def run(self): issue = get_issue(self.arguments[0])
section = nodes.section(ids=['github-issue-%s' % issue[0]]) section += nodes.title(text=issue[1]) section += nodes.paragraph(text='Opened by %s' % issue[3]) section += nodes.literal_block(text=issue[2])
return [section]
ext/issue_directive.py
![Page 49: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/49.jpg)
class ShowGitHubIssue(Directive): required_arguments = 1
def run(self): issue = get_issue(self.arguments[0])
section = nodes.section(ids=['github-issue-%s' % issue[0]]) section += nodes.title(text=issue[1]) section += nodes.paragraph(text='Opened by %s' % issue[3]) section += nodes.literal_block(text=issue[2])
return [section]
ext/issue_directive.py
![Page 50: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/50.jpg)
class ShowGitHubIssue(Directive): required_arguments = 1
def run(self): issue = get_issue(self.arguments[0])
result = statemachine.ViewList() for line in format_issue(issue): result.append(line, '<' + __name__ + '>') node = nodes.section(document=self.state.document) nested_parse_with_titles(self.state, result, node)
return node.children
ext/issue_directive.py
![Page 51: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/51.jpg)
class ShowGitHubIssue(Directive): required_arguments = 1
def run(self): issue = get_issue(self.arguments[0])
result = statemachine.ViewList() for line in format_issue(issue): result.append(line, '<' + __name__ + '>') node = nodes.section(document=self.state.document) nested_parse_with_titles(self.state, result, node)
return node.children
ext/issue_directive.py
![Page 52: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/52.jpg)
def format_issue(issue): num, title, body, owner = issue
yield title yield '=' * len(title) yield '' yield '%s ::' % owner yield '' for line in body.splitlines(): yield ' %s' % line if line else ''
ext/issue_directive.py
![Page 53: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/53.jpg)
Issues
Add keywords of “meta” directive to search index (#2463)
Opened by TimKam
It would be great to have the keywords of `meta` directives included in the search index.
Like this, one can help users who are searching for a synonym of the "correct" term through simply adding synonyms as keywords to a `meta` directive on the corresponding page.
build/issues.html
![Page 54: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/54.jpg)
Events
5
![Page 55: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/55.jpg)
builder-inited(app)
config-inited(app, config)
source-read(app, docname, source)
doctree-read(app, doctree)
...
![Page 56: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/56.jpg)
from docutils import nodesfrom docutils.parsers.rst import Directive
def builder_inited_handler(app): # code here...
def setup(app):app.connect('builder-inited', builder_inited_handler)
![Page 57: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/57.jpg)
issues.rst
issue-2951.rst
issue-2463.rst
issue-2516.rst
issue-2471.rst
...
![Page 58: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/58.jpg)
from docutils import nodesfrom docutils.parsers.rst import Directiveimport requests
URL = 'https://api.github.com/repos/sphinx-doc/sphinx/issues/'
def get_issues(): issues = requests.get(URL).json()
for issue in issues: title = '%s (#%s)' % (issue['title'], issue['number']) owner = 'Opened by %s' % issue['user']['login'] yield issue['number'], title, issue['body'], owner
ext/issue_event.py
![Page 59: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/59.jpg)
...
def generate_issue_docs(app): for num, title, body, owner in get_issues(): filename = os.path.join(app.srcdir, 'issues', '%s.rst' % num)
with io.open(filename, 'w') as issue_doc: print(title, file=issue_doc) print('=' * len(title), file=issue_doc) print('', file=issue_doc) print('%s ::' % owner, file=issue_doc) print('', file=issue_doc) for line in body.splitlines(): print(' %s' % line if line else '', file=issue_doc)
ext/issue_event.py
![Page 60: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/60.jpg)
...
def setup(app): app.connect('builder-inited', generate_issue_docs) return {'version': '1.0', 'parallel_read_safe': True}
ext/issue_event.py
![Page 61: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/61.jpg)
Issues======
.. toctree:: :maxdepth: 1 :glob:
issues/*
source/index.rst
![Page 62: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/62.jpg)
Issues
● Drop special support for rst2pdf (#4463)
● Proposal: Integrate source_suffix and source_parsers (#4474)● [RFC] Implement delayed resolution in TOC (#4475)● Not possible to update individual ‘po’ files (#4476)
● Build fails during eclim (aur) build: Babel data files not available (#4481)● Proposal: Allow to switch parsers on parsing document (#4482)● Integrate source suffix and source parsers (#4483)● …
build/index.html
![Page 63: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/63.jpg)
Enabling Your Extensions
5
![Page 64: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/64.jpg)
import osimport sys
sys.path.insert(0, os.path.abspath('../ext'))
extensions = [ 'issue_role', 'issue_directive', 'issue_event',]
source/conf.py
![Page 65: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/65.jpg)
import osimport sys
sys.path.insert(0, os.path.abspath('../ext'))
extensions = [ 'issue_role', 'issue_directive', 'issue_event', 'oslo_config.sphinxext',]
source/conf.py
![Page 66: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/66.jpg)
Wrap Up
6
![Page 67: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/67.jpg)
Extensions are registered via sphinx.application.Application
add_builderadd_config_value
add_domainadd_eventadd_node
add_directiveadd_role
connect, disconnect...
(Builders)(Config Values)(Domains)(Events)(docutils Nodes)(Directives)(Interpreted Text Roles, a.k.a. Roles)(Hooks)...
![Page 68: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/68.jpg)
Extensions are registered via sphinx.application.Application
add_builderadd_config_value
add_domainadd_eventadd_node
add_directiveadd_role
connect, disconnect...
(Builders)(Config Values)(Domains)(Events)(docutils Nodes)(Directives)(Interpreted Text Roles, a.k.a. Roles)(Hooks)...
![Page 69: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/69.jpg)
Extensions are registered via sphinx.application.Application
Builder-specific Extensions (HTML themes, LaTeX templates, …)
(Post) Transforms
Translators
Parsers
Search languages
...
![Page 70: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/70.jpg)
Fin
![Page 71: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/71.jpg)
A lion, a head, and a dashof YAMLExtending Sphinx to automate your documentation
FOSDEM 2018
@stephenfin
![Page 72: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/72.jpg)
References● Quick reStructuredText● Docutils Reference Guide
○ reStructuredText Markup Specification
○ reStructuredText Directives
○ reStructuredText Interpreted Text Roles
● Docutils How-Tos○ Creating reStructuredText Interpreted Text Roles
○ Creating reStructuredText Directives
● Docutils Hacker’s Guide● Sphinx Tutorial: Writing a simple extension
![Page 73: A lion, a head, and a dash - fosdem.org · A lion, a head, and a dash of YAML Extending Sphinx to automate your documentation FOSDEM 2018 @stephenfin](https://reader031.vdocuments.us/reader031/viewer/2022022606/5b8110937f8b9aad638b8c94/html5/thumbnails/73.jpg)
References● Defining Custom Roles in Sphinx -- Doug Hellmann● The Power of Sphinx - Integrating Jinja with RST -- Eric Holscher● Docutils Snippets -- Aurélien Gâteau● OpenStack + Sphinx In A Tree -- Stephen Finucane ( )