1 of 36

Why we need to learn

“Inside Sphinx”

Takeshi KOMIYA (@tk0miya)

2019.11.25 @ SphinxCon JP 2019

↓ URL of this slide

2 of 36

Who am I ?

  • Takeshi KOMIYA
  • @tk0miya
  • CTO of TIME INTERMEDIA, Inc.
    • We’re hiring!
  • OSS Developer
    • Sphinx
    • Sphinx extensions
    • blockdiag
  • Winner of Open Source

Bonus Program (Oct, 2017)

3 of 36

Who am I ?

  • blockdiag: Generate graph image from text

{

"Top page" -> "Sign in" -> "My Page";

"Top page" -> "List page" -> "Detail page";

}

4 of 36

Who am I ? (Books, Articles)

  • Books and magazines
    • Getting Started Sphinx (2nd edition)
    • Software Design (2015/4~2017/3, with friends)
    • teckbookfest (技術書典7, き42D)

5 of 36

Who am I ?

  • As a maintainer of Sphinx
    • 2000+ contributions in last 12months
    • Most active committer in the world
      • I’ve producted 50-60% of commits.

6 of 36

Agenda

  • Extensions I’ve ever made
  • Why extension needed
  • To make own Sphinx extension
  • Conclusion

7 of 36

Agenda

  • Extensions I’ve ever made
  • Why extension needed
  • To make own Sphinx extension
  • Conclusion

8 of 36

Extensions I’ve ever made

  • Ever I’ve made tons of Sphinx exts
    • 26 packages on PyPI
    • 28 micro posts to Gist
      • quick hacks
      • seeds of new extensions

9 of 36

Extensions I’ve ever made

  • sphinxcontrib-cacoo
    • Fetch and embed a remote image
    • similars: astah, googledrive

source

Image

on

Cacoo

Fetch image

from Cacoo

10 of 36

Extensions I’ve ever made

  • sphinxcontrib-astah
    • Convert embed an astah*’s image
    • similars: visio

source

Convert image

astah*’s

image

11 of 36

Extensions I’ve ever made

  • sphinxcontrib-apiblueprint
    • Convert and embed a local file
    • similars: jsonschema

source

API

Blueprint

Definition

Convert API def.

to document

12 of 36

Extensions I’ve ever made

  • sphinxcontrib-commonmark
    • Allow to use another format as a source
      • will support GFM in future (if requested)
    • similars: toc

13 of 36

Extensions I’ve ever made

  • sphinxcontrib-getstart-sphinx
    • Gather footnotes to bottom of each section
    • similars: bibliography

source

Modifies

doc structure

14 of 36

Extensions I’ve ever made

  • sphinxcontrib-details-directive
    • Generate <details> tag in HTML output
    • similars: emoji

source

<details>

15 of 36

Extensions I’ve ever made

  • sphinxcontrib-googlemaps
    • Embed a content on internet to document
    • similars:
      • slide, googlechart, nicovideo
      • remoteinclude

source

Google

Maps

16 of 36

Extensions I’ve ever made

  • schema2rst
    • Generate .rst file from live database
    • autodoc for database

source

DB

17 of 36

Agenda

  • Extensions I’ve ever made
  • Why extension needed
  • To make own Sphinx extension
  • Conclusion

18 of 36

Why extensions needed?

  • Automation
  • Representation for specific output format
  • Collaborate with external tools & services
  • Arrange document structure
  • Add a new feature

19 of 36

Why extensions needed?

  • Automation
    • Let computer working instead of you
  • Case of cacoo ext.
    • Before:
      • Edit image → Export → Build docs → Edit …
    • After:
      • Edit image → Build docs

20 of 36

Why extensions needed?

  • Representation for specific output format
    • Sphinx-core only provides commonly used document-structure as a parts
    • Video, Slides, Maps are not provided
      • Hard to represent except in HTML
  • Case of details-directive
    • Allows to use <details> tag on HTML build
    • Contents are expanded in other output

21 of 36

Why extensions needed?

  • Collaborate with external tools & services
    • There are many useful services for docs
      • ex. drawing tools
    • Everything it can be converted to docs
      • Infrastructure as Code
      • Open API Specification
  • Case of sphinxcontrib-cacoo
    • Embed a diagram drawn in Cacoo
    • Only build to use, no additional operations!

22 of 36

Why extensions needed?

  • Arrange document structure
    • Rewrite and modify document structure
      • Relocate elements
      • Change styles
  • Case of sphinx-getstart-sphinx
    • Relocate footnotes to end of each section
    • It is useful for EPUB output
    • Before
      • footnotes are shown at written location
    • After
      • footnotes are shown at end of section

23 of 36

Why extensions needed?

  • Add a new feature
  • sphinxcontrib-commonmark
    • brandnew custom commonmark parser
    • follows commonmark spec perfectly
    • Allow to enhance syntax via code
      • I’ll support GitHub Flavored Markdown in future

24 of 36

Why extensions needed?

  • Making own ext. is not special
  • It’s like a macro for documentation
  • It makes your documentation better

25 of 36

Agenda

  • Extensions I’ve ever made
  • Why extension needed
  • To make own Sphinx extension
  • Conclusion

26 of 36

To make own Sphinx extension

  • How to make own Sphinx extension?
  • Recipes:
    • Python code
    • docutils
    • Sphinx Framework & API
    • Case of Sphinx extensions

27 of 36

To make own Sphinx extension

  • How to get knowledges for development
  • Sources
    • sphinx documentation
    • source code
      • sphinx-core
      • other extensions
    • community
      • sphinx-users group (EN)
      • sphinx-users.jp (JA)

28 of 36

To make own Sphinx extension

  • How to get knowledges for development
  • Sources
    • books
      • mastering docutils (JA)
      • Inside Sphinx (JA)

29 of 36

To make own Sphinx extension

  • Inside Sphinx
    • Learn how to develop ext. via 4 examples
    • How to enhance reST markup
      • sphinxcontrib-textstyle
    • How to add own configurations
      • sphinx.ext.graphviz
    • How to hook Sphinx events
      • sphinx.ext.githubpages
    • How to modify document structures
      • sphinxcontrib-getstart-sphinx

  • I’ll contiue to ship next book if requested :-)

30 of 36

Agenda

  • Extensions I’ve ever made
  • Why extension needed
  • To make own Sphinx extension
  • Conclusion

31 of 36

Conclusion

  • Sphinx extension is your friends
    • It’s like a macro, not a special tool
    • Pick up for your writing environment
    • Let’s make new one if not found
  • Learning what ext. can do
    • Knowledge of ext will help your development
    • There are many sources

32 of 36

AD: personal sponsorship

  • I started personal sponsorship program to support my OSS development
  • It’s very helpful to me if you become my sponsor!
  • Thank you for my sponsors!

For Japanese readers

For English readers

33 of 36

34 of 36

35 of 36

emoji extension

36 of 36

upLaTeX support

  • Add upLaTeX support to core
  • Stay tuned

  • Issues and questions are important. They are seeds of my development. Don’t be shy!