Skip to content

Commit 3fb76d4

Browse files
committed
diagram-generator: limit line length to 80 chars
1 parent ef87fd1 commit 3fb76d4

File tree

1 file changed

+45
-35
lines changed

1 file changed

+45
-35
lines changed

diagram-generator/diagram-generator.lua

+45-35
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,40 @@
88
for the code to generate a GraphViz image.
99
]]
1010

11-
-- The PlantUML path. If set, uses the environment variable PLANTUML or the value "plantuml.jar" (local PlantUML version).
12-
-- In order to define a PlantUML version per pandoc document, use the meta data to define the key "plantumlPath".
11+
-- The PlantUML path. If set, uses the environment variable PLANTUML or the
12+
-- value "plantuml.jar" (local PlantUML version). In order to define a
13+
-- PlantUML version per pandoc document, use the meta data to define the key
14+
-- "plantumlPath".
1315
local plantumlPath = os.getenv("PLANTUML") or "plantuml.jar"
1416

15-
-- The Inkscape path. In order to define an Inkscape version
16-
-- per pandoc document, use the meta data to define the key "inkscapePath".
17+
-- The Inkscape path. In order to define an Inkscape version per pandoc
18+
-- document, use the meta data to define the key "inkscapePath".
1719
local inkscapePath = os.getenv("INKSCAPE") or "inkscape"
1820

1921
-- The Python path. In order to define a Python version per pandoc document,
2022
-- use the meta data to define the key "pythonPath".
2123
local pythonPath = os.getenv("PYTHON")
2224

23-
-- The Python environment's activate script. Can be set on a per document basis
24-
-- by using the meta data key "activatePythonPath".
25+
-- The Python environment's activate script. Can be set on a per document
26+
-- basis by using the meta data key "activatePythonPath".
2527
local pythonActivatePath = os.getenv("PYTHON_ACTIVATE")
2628

2729
-- The Java path. In order to define a Java version per pandoc document,
2830
-- use the meta data to define the key "javaPath".
2931
local javaPath = os.getenv("JAVA_HOME")
3032
if javaPath then
31-
javaPath = javaPath .. package.config:sub(1,1) .. "bin" .. package.config:sub(1,1) .. "java"
33+
javaPath = javaPath .. package.config:sub(1,1) .. "bin"
34+
.. package.config:sub(1,1) .. "java"
3235
else
3336
javaPath = "java"
3437
end
3538

36-
-- The dot (Graphviz) path. In order to define a dot version per pandoc document,
37-
-- use the meta data to define the key "dotPath".
39+
-- The dot (Graphviz) path. In order to define a dot version per pandoc
40+
-- document, use the meta data to define the key "dotPath".
3841
local dotPath = os.getenv("DOT") or "dot"
3942

40-
-- The pdflatex path. In order to define a pdflatex version per pandoc document,
41-
-- use the meta data to define the key "pdflatexPath".
43+
-- The pdflatex path. In order to define a pdflatex version per pandoc
44+
-- document, use the meta data to define the key "pdflatexPath".
4245
local pdflatexPath = os.getenv("PDFLATEX") or "pdflatex"
4346

4447
-- The default format is SVG i.e. vector graphics:
@@ -100,7 +103,7 @@ local function tikz2image(src, filetype, additionalPackages)
100103
-- Build and write the LaTeX document:
101104
local f = io.open(tmp .. ".tex", 'w')
102105
f:write("\\documentclass{standalone}\n\\usepackage{tikz}\n")
103-
106+
104107
-- Any additional package(s) are desired?
105108
if additionalPackages then
106109
f:write(additionalPackages)
@@ -119,35 +122,37 @@ local function tikz2image(src, filetype, additionalPackages)
119122
local knownFormat = false
120123

121124
if filetype == "png" then
122-
125+
123126
-- Append the subcommands to convert into a PNG file:
124-
baseCommand = baseCommand .. " --export-png=" .. tmp .. ".png --export-dpi=300"
127+
baseCommand = baseCommand .. " --export-png="
128+
.. tmp .. ".png --export-dpi=300"
125129
knownFormat = true
126130

127131
elseif filetype == "svg" then
128-
132+
129133
-- Append the subcommands to convert into a SVG file:
130134
baseCommand = baseCommand .. " --export-plain-svg=" .. tmp .. ".svg"
131135
knownFormat = true
132136

133137
end
134138

135-
-- Unfortunately, continuation is only possible, if we know the actual format:
139+
-- Unfortunately, continuation is only possible, if we know the actual
140+
-- format:
136141
local imgData = nil
137142
if knownFormat then
138143

139144
-- We know the desired format. Thus, execute Inkscape:
140145
os.execute("\"" .. inkscapePath .. "\"" .. baseCommand)
141-
146+
142147
-- Try to open the image:
143148
local r = io.open(tmp .. "." .. filetype, 'rb')
144-
149+
145150
-- Read the image, if available:
146151
if r then
147152
imgData = r:read("*all")
148153
r:close()
149154
end
150-
155+
151156
-- Delete the image tmp file:
152157
os.remove(outfile)
153158
end
@@ -163,7 +168,7 @@ end
163168

164169
-- Run Python to generate an image:
165170
local function py2image(code, filetype)
166-
171+
167172
-- Define the temp files:
168173
local outfile = string.format("./tmp-python/file.%s", filetype)
169174
local tmp = "./tmp-python/file"
@@ -184,7 +189,9 @@ local function py2image(code, filetype)
184189
f:close()
185190

186191
-- Execute Python in the desired environment:
187-
os.execute(pythonActivatePath .. " && " .. pythonPath .. " " .. tmp .. ".py")
192+
os.execute(
193+
pythonActivatePath .. " && " .. pythonPath .. " " .. tmp .. ".py"
194+
)
188195

189196
-- Try to open the written image:
190197
local r = io.open(outfile, 'rb')
@@ -220,13 +227,13 @@ function CodeBlock(block)
220227
-- Call the correct converter which belongs to the used class:
221228
local success, img = pcall(converters[block.classes[1]], block.text,
222229
filetype, block.attributes["additionalPackages"] or nil)
223-
230+
224231
-- Was ok?
225232
if success and img then
226-
233+
227234
-- Hash the figure name and content:
228235
fname = pandoc.sha1(img) .. "." .. filetype
229-
236+
230237
-- Store the data in the media bag:
231238
pandoc.mediabag.insert(fname, mimetype, img)
232239
end
@@ -246,27 +253,30 @@ function CodeBlock(block)
246253
enableCaption = "fig:"
247254
end
248255

249-
-- Create a new image for the document's structure. Attach the user's caption.
250-
-- Also use a hack (fig:) to enforce pandoc to create a figure i.e. attach
251-
-- a caption to the image.
256+
-- Create a new image for the document's structure. Attach the user's
257+
-- caption. Also use a hack (fig:) to enforce pandoc to create a
258+
-- figure i.e. attach a caption to the image.
252259
local imgObj = pandoc.Image(caption, fname, enableCaption)
253260

254-
-- Now, transfer the attribute "name" from the code block to the new image block.
255-
-- It might gets used by the figure numbering lua filter. If the figure numbering
256-
-- gets not used, this additional attribute gets ignored as well.
261+
-- Now, transfer the attribute "name" from the code block to the new
262+
-- image block. It might gets used by the figure numbering lua filter.
263+
-- If the figure numbering gets not used, this additional attribute
264+
-- gets ignored as well.
257265
if block.attributes["name"] then
258266
imgObj.attributes["name"] = block.attributes["name"]
259267
end
260268

261-
-- Finally, put the image inside an empty paragraph. By returning the resulting
262-
-- paragraph object, the source code block gets replaced by the image:
269+
-- Finally, put the image inside an empty paragraph. By returning the
270+
-- resulting paragraph object, the source code block gets replaced by
271+
-- the image:
263272
return pandoc.Para{ imgObj }
264273
end
265274
end
266275

267-
-- Normally, pandoc will run the function in the built-in order Inlines -> Blocks -> Meta -> Pandoc.
268-
-- We instead want Meta -> Blocks. Thus, we must define our custom order:
276+
-- Normally, pandoc will run the function in the built-in order Inlines ->
277+
-- Blocks -> Meta -> Pandoc. We instead want Meta -> Blocks. Thus, we must
278+
-- define our custom order:
269279
return {
270280
{Meta = Meta},
271281
{CodeBlock = CodeBlock},
272-
}
282+
}

0 commit comments

Comments
 (0)