Skip to content

Commit c13934a

Browse files
committed
Expose scale attribute for DITAA images
1 parent 4717ac0 commit c13934a

File tree

6 files changed

+83
-25
lines changed

6 files changed

+83
-25
lines changed

README.markdown

+3-6
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,17 @@ Unique features:
3737

3838
# TODO
3939

40-
1. Expose DITAA's `--scale` via attribute
41-
1. pandoc-ditaa-inline filter could write files to cache dir and read it from there via SHA
42-
- still keep the SVG inline, but do not call ditaa again if unchanged
43-
1. Make pandoc-ditaa-inline only inline SVG if FORMAT is html (html5?)
4440
1. Expose customization of
4541
* highlight-style
4642
* theme
4743
* slideNumber
4844
* history
4945
1. Provide a docker image so that we can run without installing everything
46+
1. Add guard-livereload to the generated project
47+
1. Performance: pandoc-ditaa-inline filter could write files to cache dir and read it from there via SHA
48+
- still keep the SVG inline, but do not call ditaa again if unchanged
5049
1. Consider [mermaid-filter](https://github.com/raghur/mermaid-filter)
5150
1. Allow self-hosted mathjax (copy to target)
5251
1. Charts using [vega-lite](https://vega.github.io/vega-lite/usage/embed.html)
53-
1. Add guard-livereload to the generated project
54-
1. PDF output
5552
1. Make the initial set of files more meaningful (e.g. add the project name, `git config user.name` etc.)
5653
1. Web interface for live editing

lib/revealing/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Revealing
4-
VERSION = '1.5.0'
4+
VERSION = '1.6.0'
55
end

templates/README.markdown

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This is the source of New Presentation. It was generated with [`revealing`](http
66

77
* Images are resized for the web using [`graphicsmagick`](http://www.graphicsmagick.org/)
88
* `#include` and other [`gpp`](https://logological.org/gpp) features allow organizing the sources of complex presentations
9+
* Fenced code blocks marked as `ditaa` will be converted to SVG
910
* Files in the `headers` folder are included verbatim in the HTML `<head>` section
1011
* MathJax is included and configured to render SVG. To use a specific version, set the environment variable `MATH_JAX_VERSION` to one of of the versions provided by [CDNJS](https://cdnjs.com/libraries/mathjax).
1112
* reveal.js is downloaded and unzipped at build time. Set the environment variable `REVEAL_JS_VERSION` to customize which version to use (must be one of the [released versions](https://github.com/hakimel/reveal.js/releases)). If `REVEAL_JS_DIR` is set, the files from this directory are used.

tools/pandoc-ditaa-inline/ditaa-inline.lua

+41-16
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,49 @@ local function dirname(str)
33
if str:match(".-/.-") then
44
return string.gsub(str, "(.*/)(.*)", "%1")
55
else
6-
return ''
6+
return '.'
77
end
88
end
99

10+
local function convertToSVG(text, scale)
11+
return pandoc.pipe(
12+
"java",
13+
{
14+
"-Djava.awt.headless=true",
15+
"-jar", dirname(PANDOC_SCRIPT_FILE) .. '/' .. "lib/ditaa-0.11.0-standalone.jar",
16+
"-",
17+
"-",
18+
"--svg",
19+
"--scale", scale
20+
},
21+
text
22+
)
23+
end
24+
25+
-- These formats accept embedded SVG
26+
local SUPPORTED_FORMATS = {
27+
['html'] = true, ['html5'] = true, ['html4'] = true, ['slideous'] = true,
28+
['slidy'] = true, ['dzslides'] = true, ['revealjs'] = true, ['s5'] = true
29+
}
30+
1031
function CodeBlock(block)
11-
if block.classes[1] == "ditaa" then
12-
local img = pandoc.pipe(
13-
"java",
14-
{
15-
"-Djava.awt.headless=true",
16-
"-jar", dirname(PANDOC_SCRIPT_FILE) .. '/' .. "lib/ditaa-0.11.0-standalone.jar",
17-
"-",
18-
"-",
19-
"--svg",
20-
"--scale", "1.0"
21-
},
22-
block.text
23-
)
24-
return pandoc.Para({pandoc.RawInline("html", img)})
25-
end
32+
if not (block.classes[1] == "ditaa") then
33+
return -- keeps the block's text as literal code block
34+
end
35+
36+
if not SUPPORTED_FORMATS[FORMAT] then
37+
io.stderr:write(string.format("Warning: Cannot convert DITAA block to SVG for format %s. Keeping literal value.\n", FORMAT))
38+
return
39+
end
40+
41+
local scale = block.attributes["scale"] or "1.0"
42+
43+
success, result = pcall(convertToSVG, block.text, scale)
44+
45+
if not success then
46+
io.stderr:write(string.format("Error - DITAA block could not converted:\n%s\n", result.output))
47+
else
48+
-- io.stderr:write("DITAA block converted successfully\n")
49+
return pandoc.Para({pandoc.RawInline("html", result)})
50+
end
2651
end

tools/pandoc-ditaa-inline/examples/example.html

+28-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,34 @@
2525
<text x='153' y='54' font-family='Courier' font-size='15' stroke='none' fill='#000000' ><![CDATA[B ]]></text>
2626
</g>
2727
</svg></p>
28-
<p>As you can see, ditaa renders that quite pretty. It’s turned into an embedded SVG.</p>
28+
<p>The <code>scale</code> attribute can be set so that the generated image is scaled by this factor. This requires the use of <a href="https://pandoc.org/MANUAL.html#extension-fenced_code_attributes">fenced code attributes</a>, where the class is written as <code>.ditaa</code>.</p>
29+
<p>This is the same image as before, but scaled by factor <code>1.5</code>:</p>
30+
<p><?xml version='1.0' encoding='UTF-8' standalone='no'?>
31+
<svg
32+
xmlns='http://www.w3.org/2000/svg'
33+
width='315'
34+
height='147'
35+
shape-rendering='geometricPrecision'
36+
version='1.0'>
37+
<defs>
38+
<filter id='f2' x='0' y='0' width='200%' height='200%'>
39+
<feOffset result='offOut' in='SourceGraphic' dx='5' dy='5' />
40+
<feGaussianBlur result='blurOut' in='offOut' stdDeviation='3' />
41+
<feBlend in='SourceGraphic' in2='blurOut' mode='normal' />
42+
</filter>
43+
</defs>
44+
<g stroke-width='1' stroke-linecap='square' stroke-linejoin='round'>
45+
<rect x='0' y='0' width='315' height='147' style='fill: #ffffff'/>
46+
<path stroke='gray' fill='gray' filter='url(#f2)' d='M37.0 52.0 L37.0 94.0 L127.0 94.0 L127.0 52.0 z' />
47+
<path stroke='gray' fill='gray' filter='url(#f2)' d='M187.0 94.0 L277.0 94.0 L277.0 52.0 L187.0 52.0 z' />
48+
<path stroke='#000000' stroke-width='1,500000' stroke-linecap='round' stroke-linejoin='round' fill='white' d='M37.0 52.0 L37.0 94.0 L127.0 94.0 L127.0 52.0 z' />
49+
<path stroke='#000000' stroke-width='1,500000' stroke-linecap='round' stroke-linejoin='round' fill='white' d='M187.0 94.0 L277.0 94.0 L277.0 52.0 L187.0 52.0 z' />
50+
<path stroke='none' stroke-width='1,500000' stroke-linecap='round' stroke-linejoin='round' fill='#000000' d='M165.0 63.0 L180.0 73.0 L165.0 84.0 z' />
51+
<path stroke='#000000' stroke-width='1,500000' stroke-linecap='round' stroke-linejoin='round' fill='none' d='M172.0 73.0 L142.0 73.0 ' />
52+
<text x='79' y='82' font-family='Courier' font-size='22' stroke='none' fill='#000000' ><![CDATA[A ]]></text>
53+
<text x='230' y='82' font-family='Courier' font-size='22' stroke='none' fill='#000000' ><![CDATA[B ]]></text>
54+
</g>
55+
</svg></p>
2956
<p>Other blocks are left untouched:</p>
3057
<div class="sourceCode" id="cb1"><pre class="sourceCode ruby"><code class="sourceCode ruby"><a class="sourceLine" id="cb1-1" title="1">puts <span class="st">&quot;olleH&quot;</span>.reverse</a></code></pre></div>
3158
<p>That’s it!</p>

tools/pandoc-ditaa-inline/examples/example.markdown

+9-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ The following graph shows two boxes, connected:
66
+-----+ +-----+
77
```
88

9-
As you can see, ditaa renders that quite pretty. It's turned into an embedded SVG.
9+
The `scale` attribute can be set so that the generated image is scaled by this factor. This requires the use of [fenced code attributes](https://pandoc.org/MANUAL.html#extension-fenced_code_attributes), where the class is written as `.ditaa`.
10+
11+
This is the same image as before, but scaled by factor `1.5`:
12+
13+
```{.ditaa scale=1.5}
14+
+-----+ +-----+
15+
| A |-->| B |
16+
+-----+ +-----+
17+
```
1018

1119
Other blocks are left untouched:
1220

0 commit comments

Comments
 (0)