aboutsummaryrefslogtreecommitdiff
path: root/scripts/abc.py
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2013-08-18 15:36:54 -0700
committerJohn MacFarlane <fiddlosopher@gmail.com>2013-08-18 15:37:27 -0700
commit70386a6a54c54189b8456b547a657873481a70b7 (patch)
treeff5d2ce432e0145f65c0728e66caf6cd193d48ac /scripts/abc.py
parent8d441af3da4709fd48a44e860d5a0cd4d35792af (diff)
downloadpandoc-70386a6a54c54189b8456b547a657873481a70b7.tar.gz
Removed scripts directory.
This has been put in its own github repo: https://github.com/jgm/pandoc-filters-python
Diffstat (limited to 'scripts/abc.py')
-rwxr-xr-xscripts/abc.py50
1 files changed, 0 insertions, 50 deletions
diff --git a/scripts/abc.py b/scripts/abc.py
deleted file mode 100755
index daecd1070..000000000
--- a/scripts/abc.py
+++ /dev/null
@@ -1,50 +0,0 @@
-#!/usr/bin/env python
-
-"""
-Pandoc filter to process code blocks with class "abc" containing
-ABC notation into images. Assumes that abcm2ps and ImageMagick's
-convert are in the path. Images are put in the abc-images directory.
-"""
-
-import hashlib
-import os
-import sys
-from pandoc import toJSONFilter
-from subprocess import Popen, PIPE, call
-
-imagedir = "abc-images"
-
-def sha1(x):
- return hashlib.sha1(x).hexdigest()
-
-def abc2eps(abc, filetype, outfile):
- p = Popen(["abcm2ps", "-O", outfile + '.eps', "-"],stdin=PIPE)
- p.stdin.write(abc)
- p.communicate()
- p.stdin.close()
- call(["convert", outfile + '.eps', outfile + '.' + filetype])
-
-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
- abc2eps(code, filetype, outfile)
- sys.stderr.write('Created image ' + src + '\n')
- return {'Para': [{'Image': [[], [src,""]]}]}
-
-if __name__ == "__main__":
- toJSONFilter(abc)