Recently, I am writing a document with Sphinx.
So I solved it once, but when using PlantUML, it became stressful that I could not preview on VS Code.
When making html
```plantuml
Enclose
.. uml::
I want to automatically convert to.
#policy
Official documentationThere is an event implementation method inside.
#Extension plugin implementation
I wrote it like this.
uml_change.py
def uml_change(app, docname, source):
umlFlg = False
lines = []
for line in source[0].split("\n"):
if umlFlg:
if line.strip() == "```":
#Delete when the end of the box comes
line = ""
umlFlg = False
else:
#Indent inside the box
line = " " + line
###Convert markdown notation to reST notation
if line.strip() == "```plantuml":
line = ".. uml::"
umlFlg = True
lines.append(line)
source[0] = "\n".join(lines)
def setup(app):
app.connect("source-read", uml_change)
conf.Add the following description to py.
conf.py
import sys
import os
sys.path.append (os.path.abspath ("./ bin")) # Folder name is an example
Store the above script in the specified folder (under bin in the above example).
Add the created plugin name to extensions.
conf.py
extensions = ['uml_change']
Try make html and if the uml image is displayed, it succeeds.
#Supplement
You should be able to write various preprocessing by applying this method. Convert markdown link format to restructuredText format, etc.
Recommended Posts