diff --git a/examples/abc-sample.md b/examples/abc-sample.md index 11ac36f..67d3bfe 100644 --- a/examples/abc-sample.md +++ b/examples/abc-sample.md @@ -9,9 +9,9 @@ C:André Raison M:3/4 L:1/4 Q:1/4=92 -%%staves {(Pos1 Pos2) Trompette} +%%staves {(Pos1 Pos2) Trompette} K:F -% +% V:Pos1 %%MIDI program 78 "Positif"x3 |x3 |c'>ba|Pga/g/f|:g2a |ba2 |g2c- |c2P=B |c>de |fga | @@ -32,9 +32,9 @@ C:André Raison M:3/4 L:1/4 Q:1/4=92 -%%staves {(Pos1 Pos2) Trompette} +%%staves {(Pos1 Pos2) Trompette} K:F -% +% V:Pos1 %%MIDI program 78 "Positif"x3 |x3 |c'>ba|Pga/g/f|:g2a |ba2 |g2c- |c2P=B |c>de |fga | @@ -46,3 +46,26 @@ V:Trompette "Trompette"z3|z3 |z3 |z3 |:Mc>BA|PGA/G/F|PE>EF|PEF/E/D|C>CPB,|A,G,F,-| ``` +See [(this is a link to whatever)](#whatever) for an example with options +`{.abc #whatever caption="this is the caption" width=50%}`. + +```{.abc #whatever caption="this is the caption" width=50%} +X:7 +T:Qui Tolis (Trio) +C:André Raison +M:3/4 +L:1/4 +Q:1/4=92 +%%staves {(Pos1 Pos2) Trompette} +K:F +% +V:Pos1 +%%MIDI program 78 +"Positif"x3 |x3 |c'>ba|Pga/g/f|:g2a |ba2 |g2c- |c2P=B |c>de |fga | +V:Pos2 +%%MIDI program 78 + Mf>ed|cd/c/B|PA2d |ef/e/d |:e2f |ef2 |c>BA |GA/G/F |E>FG |ABc- | +V:Trompette +%%MIDI program 56 +"Trompette"z3|z3 |z3 |z3 |:Mc>BA|PGA/G/F|PE>EF|PEF/E/D|C>CPB,|A,G,F,-| +``` diff --git a/examples/abc.py b/examples/abc.py index e6bdfd7..b65d255 100755 --- a/examples/abc.py +++ b/examples/abc.py @@ -6,48 +6,36 @@ convert are in the path. Images are put in the abc-images directory. """ -import hashlib import os import sys -from pandocfilters import toJSONFilter, Para, Image from subprocess import Popen, PIPE, call -imagedir = "abc-images" +from pandocfilters import toJSONFilter, Para, Image, get_caption, get_filename4code, get_extension -def sha1(x): - return hashlib.sha1(x.encode(sys.getfilesystemencoding())).hexdigest() - - -def abc2eps(abc, filetype, outfile): +def abc2eps(abc_src, filetype, outfile): p = Popen(["abcm2ps", "-O", outfile + '.eps', "-"], stdin=PIPE) - p.stdin.write(abc) + p.stdin.write(abc_src) p.communicate() p.stdin.close() call(["convert", outfile + '.eps', outfile + '.' + filetype]) -def abc(key, value, format, meta): +def abc(key, value, format, _): if key == 'CodeBlock': [[ident, classes, keyvals], code] = value if "abc" in classes: - outfile = imagedir + '/' + sha1(code) - if format == "html": - filetype = "png" - elif format == "latex": - filetype = "pdf" - else: - filetype = "png" - src = outfile + '.' + filetype - if not os.path.isfile(src): - try: - os.mkdir(imagedir) - sys.stderr.write('Created directory ' + imagedir + '\n') - except OSError: - pass + caption, typef, keyvals = get_caption(keyvals) + outfile = get_filename4code("abc", code) + filetype = get_extension(format, "png", html="png", latex="pdf") + dest = outfile + '.' + filetype + + if not os.path.isfile(dest): abc2eps(code.encode("utf-8"), filetype, outfile) - sys.stderr.write('Created image ' + src + '\n') - return Para([Image(['', [], []], [], [src, ""])]) + sys.stderr.write('Created image ' + dest + '\n') + + return Para([Image([ident, [], keyvals], caption, [dest, typef])]) + if __name__ == "__main__": toJSONFilter(abc)