[Python-modules-commits] [python-pandocfilters] 01/03: New upstream version 1.4.1
Sebastian Humenda
moomoc-guest at moszumanska.debian.org
Thu Jun 1 07:44:46 UTC 2017
This is an automated email from the git hooks/post-receive script.
moomoc-guest pushed a commit to branch master
in repository python-pandocfilters.
commit 1428fc54ec04a6cdbd792068cdf17cfac550557f
Author: Sebastian Humenda <shumenda at gmx.de>
Date: Wed May 31 12:23:18 2017 +0200
New upstream version 1.4.1
---
PKG-INFO | 112 ++++++++++++++++++-------
README | 110 ++++++++++++++++++-------
README.rst | 110 ++++++++++++++++++-------
examples/Makefile | 22 +++++
examples/abc-sample.md | 71 ++++++++++++++++
examples/abc.py | 40 ++++-----
examples/caps-sample.md | 2 +
examples/comments-sample.md | 10 +++
examples/deemph-sample.md | 3 +
examples/deflists-sample.md | 20 +++++
examples/gabc-sample.md | 32 ++++++++
examples/gabc.py | 83 +++++++++++++------
examples/graphviz-sample.md | 24 ++++++
examples/graphviz.py | 48 ++++-------
examples/latexdivs-sample.md | 21 +++++
examples/latexdivs.py | 33 ++++++++
examples/lilypond-sample.md | 31 +++++++
examples/metavars-sample.md | 7 ++
examples/myemph-sample.md | 4 +
examples/plantuml-sample.md | 37 +++++++++
examples/plantuml.py | 43 ++++++++++
examples/theorem-sample.md | 13 +++
examples/tikz-sample.md | 37 +++++++++
examples/tikz.py | 36 +++-----
pandocfilters.py | 191 +++++++++++++++++++++++++++++++++++--------
setup.py | 2 +-
26 files changed, 912 insertions(+), 230 deletions(-)
diff --git a/PKG-INFO b/PKG-INFO
index 3ed0443..8bd5c54 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: pandocfilters
-Version: 1.3.0
+Version: 1.4.1
Summary: Utilities for writing pandoc filters in python
Home-page: http://github.com/jgm/pandocfilters
Author: John MacFarlane
@@ -38,6 +38,10 @@ Description: pandocfilters
- pandocfilters version <= 1.2.4 for pandoc versions 1.12--1.15, and
- pandocfilters version >= 1.3.0 for pandoc versions >= 1.16.
+ Pandoc 1.17.3 (pandoc-types 1.17.*) introduced a new JSON format.
+ pandocfilters 1.4.0 should work with both the old and the new
+ format.
+
Installing
--------------
Run this inside the present directory::
@@ -50,36 +54,80 @@ Description: pandocfilters
Available functions
----------------------
- The ``pandocfilters`` module exports the following functions:
-
- ``walk(x, action, format, meta)``
- Walk a tree, applying an action to every object.
- Returns a modified tree.
-
- ``toJSONFilter(action)``
- Converts an action into a filter that reads a JSON-formatted
- pandoc document from stdin, transforms it by walking the tree
- with the action, and returns a new JSON-formatted pandoc document
- to stdout. The argument is a function ``action(key, value, format, meta)``,
- where key is the type of the pandoc object (e.g. ``'Str'``, ``'Para'``),
- value is the contents of the object (e.g. a string for ``'Str'``,
- a list of inline elements for ``'Para'``), format is the target
- output format (which will be taken for the first command line
- argument if present), and meta is the document's metadata.
- If the function returns None, the object to which it applies
- will remain unchanged. If it returns an object, the object will
- be replaced. If it returns a list, the list will be spliced in to
- the list to which the target object belongs. (So, returning an
- empty list deletes the object.)
-
- ``stringify(x)``
- Walks the tree ``x`` and returns concatenated string content,
- leaving out all formatting.
-
- ``attributes(attrs)``
- Returns an attribute list, constructed from the
- dictionary ``attrs``.
+ The main functions ``pandocfilters`` exports are
+
+ - ``walk(x, action, format, meta)``
+
+ Walk a tree, applying an action to every object. Returns a modified
+ tree. An action is a function of the form
+ ``action(key, value, format, meta)``, where:
+
+ - ``key`` is the type of the pandoc object (e.g. 'Str', 'Para')
+ ``value`` is
+ - the contents of the object (e.g. a string for 'Str', a list of
+ inline elements for 'Para')
+ - ``format`` is the target output format (as supplied by the
+ ``format`` argument of ``walk``)
+ - ``meta`` is the document's metadata
+
+ The return of an action is either:
+
+ - ``None``: this means that the object should remain unchanged
+ - a pandoc object: this will replace the original object
+ - a list of pandoc objects: these will replace the original object;
+ the list is merged with the neighbors of the orignal objects
+ (spliced into the list the original object belongs to); returning
+ an empty list deletes the object
+
+ - ``toJSONFilter(action)``
+
+ Like ``toJSONFilters``, but takes a single action as argument.
+
+ - ``toJSONFilters(actions)``
+
+ Generate a JSON-to-JSON filter from stdin to stdout
+
+ The filter:
+
+ - reads a JSON-formatted pandoc document from stdin
+ - transforms it by walking the tree and performing the actions
+ - returns a new JSON-formatted pandoc document to stdout
+
+ The argument ``actions`` is a list of functions of the form
+ ``action(key, value, format, meta)``, as described in more detail
+ under ``walk``.
+ This function calls ``applyJSONFilters``, with the ``format``
+ argument provided by the first command-line argument, if present.
+ (Pandoc sets this by default when calling filters.)
+
+ - ``applyJSONFilters(actions, source, format="")``
+
+ Walk through JSON structure and apply filters
+
+ This:
+
+ - reads a JSON-formatted pandoc document from a source string
+ - transforms it by walking the tree and performing the actions
+ - returns a new JSON-formatted pandoc document as a string
+
+ The ``actions`` argument is a list of functions (see ``walk`` for a
+ full description).
+
+ The argument ``source`` is a string encoded JSON object.
+
+ The argument ``format`` is a string describing the output format.
+
+ Returns a the new JSON-formatted pandoc document.
+
+ - ``stringify(x)``
+
+ Walks the tree x and returns concatenated string content, leaving out
+ all formatting.
+
+ - ``attributes(attrs)``
+
+ Returns an attribute list, constructed from the dictionary attrs.
How to use
--------------
Most users will only need ``toJSONFilter``. Here is a simple example
@@ -154,6 +202,10 @@ Description: pandocfilters
macro ``\myemph{...}`` rather than ``\emph{...}`` in latex. Other output
formats are unaffected.
+ ``plantuml.py``
+ Pandoc filter to process code blocks with class ``plantuml`` to images.
+ Needs `plantuml.jar` from http://plantuml.com/.
+
``theorem.py``
Pandoc filter to convert divs with ``class="theorem"`` to LaTeX theorem
environments in LaTeX output, and to numbered theorems in HTML
diff --git a/README b/README
index 31997cd..ba8c9c2 100644
--- a/README
+++ b/README
@@ -30,6 +30,10 @@ that breaks backwards compatibility. Consequently, you should use:
- pandocfilters version <= 1.2.4 for pandoc versions 1.12--1.15, and
- pandocfilters version >= 1.3.0 for pandoc versions >= 1.16.
+Pandoc 1.17.3 (pandoc-types 1.17.*) introduced a new JSON format.
+pandocfilters 1.4.0 should work with both the old and the new
+format.
+
Installing
--------------
Run this inside the present directory::
@@ -42,36 +46,80 @@ Or install from PyPI::
Available functions
----------------------
-The ``pandocfilters`` module exports the following functions:
-
-``walk(x, action, format, meta)``
- Walk a tree, applying an action to every object.
- Returns a modified tree.
-
-``toJSONFilter(action)``
- Converts an action into a filter that reads a JSON-formatted
- pandoc document from stdin, transforms it by walking the tree
- with the action, and returns a new JSON-formatted pandoc document
- to stdout. The argument is a function ``action(key, value, format, meta)``,
- where key is the type of the pandoc object (e.g. ``'Str'``, ``'Para'``),
- value is the contents of the object (e.g. a string for ``'Str'``,
- a list of inline elements for ``'Para'``), format is the target
- output format (which will be taken for the first command line
- argument if present), and meta is the document's metadata.
- If the function returns None, the object to which it applies
- will remain unchanged. If it returns an object, the object will
- be replaced. If it returns a list, the list will be spliced in to
- the list to which the target object belongs. (So, returning an
- empty list deletes the object.)
-
-``stringify(x)``
- Walks the tree ``x`` and returns concatenated string content,
- leaving out all formatting.
-
-``attributes(attrs)``
- Returns an attribute list, constructed from the
- dictionary ``attrs``.
+The main functions ``pandocfilters`` exports are
+
+- ``walk(x, action, format, meta)``
+
+ Walk a tree, applying an action to every object. Returns a modified
+ tree. An action is a function of the form
+ ``action(key, value, format, meta)``, where:
+
+ - ``key`` is the type of the pandoc object (e.g. 'Str', 'Para')
+ ``value`` is
+ - the contents of the object (e.g. a string for 'Str', a list of
+ inline elements for 'Para')
+ - ``format`` is the target output format (as supplied by the
+ ``format`` argument of ``walk``)
+ - ``meta`` is the document's metadata
+
+ The return of an action is either:
+
+ - ``None``: this means that the object should remain unchanged
+ - a pandoc object: this will replace the original object
+ - a list of pandoc objects: these will replace the original object;
+ the list is merged with the neighbors of the orignal objects
+ (spliced into the list the original object belongs to); returning
+ an empty list deletes the object
+
+- ``toJSONFilter(action)``
+
+ Like ``toJSONFilters``, but takes a single action as argument.
+
+- ``toJSONFilters(actions)``
+
+ Generate a JSON-to-JSON filter from stdin to stdout
+
+ The filter:
+
+ - reads a JSON-formatted pandoc document from stdin
+ - transforms it by walking the tree and performing the actions
+ - returns a new JSON-formatted pandoc document to stdout
+
+ The argument ``actions`` is a list of functions of the form
+ ``action(key, value, format, meta)``, as described in more detail
+ under ``walk``.
+ This function calls ``applyJSONFilters``, with the ``format``
+ argument provided by the first command-line argument, if present.
+ (Pandoc sets this by default when calling filters.)
+
+- ``applyJSONFilters(actions, source, format="")``
+
+ Walk through JSON structure and apply filters
+
+ This:
+
+ - reads a JSON-formatted pandoc document from a source string
+ - transforms it by walking the tree and performing the actions
+ - returns a new JSON-formatted pandoc document as a string
+
+ The ``actions`` argument is a list of functions (see ``walk`` for a
+ full description).
+
+ The argument ``source`` is a string encoded JSON object.
+
+ The argument ``format`` is a string describing the output format.
+
+ Returns a the new JSON-formatted pandoc document.
+
+- ``stringify(x)``
+
+ Walks the tree x and returns concatenated string content, leaving out
+ all formatting.
+
+- ``attributes(attrs)``
+
+ Returns an attribute list, constructed from the dictionary attrs.
How to use
--------------
Most users will only need ``toJSONFilter``. Here is a simple example
@@ -146,6 +194,10 @@ for developing your own pandocfilters.
macro ``\myemph{...}`` rather than ``\emph{...}`` in latex. Other output
formats are unaffected.
+``plantuml.py``
+ Pandoc filter to process code blocks with class ``plantuml`` to images.
+ Needs `plantuml.jar` from http://plantuml.com/.
+
``theorem.py``
Pandoc filter to convert divs with ``class="theorem"`` to LaTeX theorem
environments in LaTeX output, and to numbered theorems in HTML
diff --git a/README.rst b/README.rst
index 31997cd..ba8c9c2 100644
--- a/README.rst
+++ b/README.rst
@@ -30,6 +30,10 @@ that breaks backwards compatibility. Consequently, you should use:
- pandocfilters version <= 1.2.4 for pandoc versions 1.12--1.15, and
- pandocfilters version >= 1.3.0 for pandoc versions >= 1.16.
+Pandoc 1.17.3 (pandoc-types 1.17.*) introduced a new JSON format.
+pandocfilters 1.4.0 should work with both the old and the new
+format.
+
Installing
--------------
Run this inside the present directory::
@@ -42,36 +46,80 @@ Or install from PyPI::
Available functions
----------------------
-The ``pandocfilters`` module exports the following functions:
-
-``walk(x, action, format, meta)``
- Walk a tree, applying an action to every object.
- Returns a modified tree.
-
-``toJSONFilter(action)``
- Converts an action into a filter that reads a JSON-formatted
- pandoc document from stdin, transforms it by walking the tree
- with the action, and returns a new JSON-formatted pandoc document
- to stdout. The argument is a function ``action(key, value, format, meta)``,
- where key is the type of the pandoc object (e.g. ``'Str'``, ``'Para'``),
- value is the contents of the object (e.g. a string for ``'Str'``,
- a list of inline elements for ``'Para'``), format is the target
- output format (which will be taken for the first command line
- argument if present), and meta is the document's metadata.
- If the function returns None, the object to which it applies
- will remain unchanged. If it returns an object, the object will
- be replaced. If it returns a list, the list will be spliced in to
- the list to which the target object belongs. (So, returning an
- empty list deletes the object.)
-
-``stringify(x)``
- Walks the tree ``x`` and returns concatenated string content,
- leaving out all formatting.
-
-``attributes(attrs)``
- Returns an attribute list, constructed from the
- dictionary ``attrs``.
+The main functions ``pandocfilters`` exports are
+
+- ``walk(x, action, format, meta)``
+
+ Walk a tree, applying an action to every object. Returns a modified
+ tree. An action is a function of the form
+ ``action(key, value, format, meta)``, where:
+
+ - ``key`` is the type of the pandoc object (e.g. 'Str', 'Para')
+ ``value`` is
+ - the contents of the object (e.g. a string for 'Str', a list of
+ inline elements for 'Para')
+ - ``format`` is the target output format (as supplied by the
+ ``format`` argument of ``walk``)
+ - ``meta`` is the document's metadata
+
+ The return of an action is either:
+
+ - ``None``: this means that the object should remain unchanged
+ - a pandoc object: this will replace the original object
+ - a list of pandoc objects: these will replace the original object;
+ the list is merged with the neighbors of the orignal objects
+ (spliced into the list the original object belongs to); returning
+ an empty list deletes the object
+
+- ``toJSONFilter(action)``
+
+ Like ``toJSONFilters``, but takes a single action as argument.
+
+- ``toJSONFilters(actions)``
+
+ Generate a JSON-to-JSON filter from stdin to stdout
+
+ The filter:
+
+ - reads a JSON-formatted pandoc document from stdin
+ - transforms it by walking the tree and performing the actions
+ - returns a new JSON-formatted pandoc document to stdout
+
+ The argument ``actions`` is a list of functions of the form
+ ``action(key, value, format, meta)``, as described in more detail
+ under ``walk``.
+ This function calls ``applyJSONFilters``, with the ``format``
+ argument provided by the first command-line argument, if present.
+ (Pandoc sets this by default when calling filters.)
+
+- ``applyJSONFilters(actions, source, format="")``
+
+ Walk through JSON structure and apply filters
+
+ This:
+
+ - reads a JSON-formatted pandoc document from a source string
+ - transforms it by walking the tree and performing the actions
+ - returns a new JSON-formatted pandoc document as a string
+
+ The ``actions`` argument is a list of functions (see ``walk`` for a
+ full description).
+
+ The argument ``source`` is a string encoded JSON object.
+
+ The argument ``format`` is a string describing the output format.
+
+ Returns a the new JSON-formatted pandoc document.
+
+- ``stringify(x)``
+
+ Walks the tree x and returns concatenated string content, leaving out
+ all formatting.
+
+- ``attributes(attrs)``
+
+ Returns an attribute list, constructed from the dictionary attrs.
How to use
--------------
Most users will only need ``toJSONFilter``. Here is a simple example
@@ -146,6 +194,10 @@ for developing your own pandocfilters.
macro ``\myemph{...}`` rather than ``\emph{...}`` in latex. Other output
formats are unaffected.
+``plantuml.py``
+ Pandoc filter to process code blocks with class ``plantuml`` to images.
+ Needs `plantuml.jar` from http://plantuml.com/.
+
``theorem.py``
Pandoc filter to convert divs with ``class="theorem"`` to LaTeX theorem
environments in LaTeX output, and to numbered theorems in HTML
diff --git a/examples/Makefile b/examples/Makefile
new file mode 100644
index 0000000..bcbd16d
--- /dev/null
+++ b/examples/Makefile
@@ -0,0 +1,22 @@
+
+ALLSAMPLES = $(basename $(wildcard *-sample.md))
+ALLPDF = $(addsuffix .pdf,$(ALLSAMPLES))
+
+PYTHON=/usr/bin/python2
+
+all: ${ALLPDF}
+
+
+lilypond-sample.pdf: lilypond-sample.md
+ pandoc --latex-engine lualatex --filter ./$(subst -sample.md,.py,$<) $< -o $@ || touch $@
+
+gabc-sample.pdf: gabc-sample.md
+ pandoc --latex-engine lualatex --filter ./$(subst -sample.md,.py,$<) $< -o $@ || touch $@
+
+%.pdf: %.md
+ echo $(subst -sample.md,.py,$<)
+ pandoc --filter ./$(subst -sample.md,.py,$<) $< -o $@ || touch $@
+
+clean:
+ $(RM) -f ${ALLPDF} *.pyc
+ $(RM) -rf *-images tmp_ly
diff --git a/examples/abc-sample.md b/examples/abc-sample.md
new file mode 100644
index 0000000..67d3bfe
--- /dev/null
+++ b/examples/abc-sample.md
@@ -0,0 +1,71 @@
+
+Use this
+
+
+```
+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,-|
+```
+
+to get
+
+```abc
+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,-|
+```
+
+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 @@ 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 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)
diff --git a/examples/caps-sample.md b/examples/caps-sample.md
new file mode 100644
index 0000000..49e8792
--- /dev/null
+++ b/examples/caps-sample.md
@@ -0,0 +1,2 @@
+
+This is the caps sample with Äüö.
\ No newline at end of file
diff --git a/examples/comments-sample.md b/examples/comments-sample.md
new file mode 100644
index 0000000..866c51c
--- /dev/null
+++ b/examples/comments-sample.md
@@ -0,0 +1,10 @@
+
+Regular text with Äüö.
+
+<!-- BEGIN COMMENT -->
+
+This is a comment with Äüö
+
+<!-- END COMMENT -->
+
+This is regular text again.
\ No newline at end of file
diff --git a/examples/deemph-sample.md b/examples/deemph-sample.md
new file mode 100644
index 0000000..f0b0e4d
--- /dev/null
+++ b/examples/deemph-sample.md
@@ -0,0 +1,3 @@
+This is the deemph sample.
+
+This is *emphasis with Äüö* text which will be shown in caps.
diff --git a/examples/deflists-sample.md b/examples/deflists-sample.md
new file mode 100644
index 0000000..68e72b1
--- /dev/null
+++ b/examples/deflists-sample.md
@@ -0,0 +1,20 @@
+Some Definitions
+
+Term 1
+
+: Definition 1
+
+Term 2 with *inline markup*
+
+: Definition 2
+
+ { some code, part of Definition 2 }
+
+ Third paragraph of definition 2.
+
+Term with Äüö
+
+: Definition with Äüö
+
+
+Regular Text.
\ No newline at end of file
diff --git a/examples/gabc-sample.md b/examples/gabc-sample.md
new file mode 100644
index 0000000..671cb4c
--- /dev/null
+++ b/examples/gabc-sample.md
@@ -0,0 +1,32 @@
+---
+header-includes:
+
+ - \usepackage{libertine}
+ - \usepackage[autocompile]{gregoriotex}
+
+---
+
+
+Use this
+
+~~~~~~
+```gabc
+(c4) A(f)ve(c) Ma(d)rí(dh'!iv)a.(h.) (::)
+```
+~~~~~~
+
+to get
+
+```gabc
+(c4) A(f)ve(c) Ma(d)rí(dh'!iv)a.(h.) (::)
+```
+
+and this
+
+~~~~~~
+`gabc-score`{.gabc staffsize=12 annotation=Off. mode=2.}
+~~~~~~
+
+to get the score in `gabc-score.gabc` :
+
+`gabc-score`{.gabc staffsize=12 annotation=Off. mode=2.}
diff --git a/examples/gabc.py b/examples/gabc.py
index 670fd76..5778a40 100755
--- a/examples/gabc.py
+++ b/examples/gabc.py
@@ -13,10 +13,15 @@ from hashlib import sha1
from pandocfilters import toJSONFilter, RawBlock, RawInline, Para, Image
+STDERR = DEVNULL
IMAGEDIR = "tmp_gabc"
LATEX_DOC = """\\documentclass{article}
\\usepackage{libertine}
-\\usepackage[autocompile]{gregoriotex}
+\\usepackage[autocompile,allowdeprecated=false]{gregoriotex}
+\\catcode`\\℣=\\active \\def ℣#1{{\\Vbar\\hspace{-.25ex}#1}}
+\\catcode`\\℟=\\active \\def ℟#1{{\\Rbar\\hspace{-.25ex}#1}}
+\\catcode`\\†=\\active \\def †{{\\GreDagger}}
+\\catcode`\\✠=\\active \\def ✠{{\\grecross}}
\\pagestyle{empty}
\\begin{document}
%s
@@ -44,11 +49,14 @@ def htmlblock(code):
return RawBlock('html', code)
-def latexsnippet(code, kvs):
+def latexsnippet(code, kvs, staffsize=17, initiallines=1):
"""Take in account key/values"""
snippet = ''
- staffsize = int(kvs['staffsize']) if 'staffsize' in kvs else 17
- annotationsize = .56 * staffsize
+ staffsize = int(kvs['staffsize']) if 'staffsize' in kvs \
+ else staffsize
+ initiallines = int(kvs['initiallines']) if 'initiallines' in kvs \
+ else initiallines
+ annotationsize = .5 * staffsize
if 'mode' in kvs:
snippet = (
"\\greannotation{{\\fontsize{%s}{%s}\\selectfont{}%s}}\n" %
@@ -56,14 +64,15 @@ def latexsnippet(code, kvs):
) + snippet
if 'annotation' in kvs:
snippet = (
- "\\grechangedim{annotationseparation}{%s mm}{0}\n"
+ "\\grechangedim{annotationseparation}{%s mm}{fixed}\n"
"\\greannotation{{\\fontsize{%s}{%s}\\selectfont{}%s}}\n" %
- (staffsize / 34, annotationsize, annotationsize, kvs['annotation'])
+ (staffsize / 60, annotationsize, annotationsize, kvs['annotation'])
) + snippet
snippet = (
+ "\\gresetinitiallines{%s}\n" % initiallines +
"\\grechangestaffsize{%s}\n" % staffsize +
- "\\def\\greinitialformat#1{{\\fontsize{%s}{%s}\\selectfont{}#1}}" %
- (2.75 * staffsize, 2.75 * staffsize)
+ "\\grechangestyle{initial}{\\fontsize{%s}{%s}\\selectfont{}}" %
+ (2.5 * staffsize, 2.5 * staffsize)
) + snippet
snippet = "\\setlength{\\parskip}{0pt}\n" + snippet + code
return snippet
@@ -72,33 +81,31 @@ def latexsnippet(code, kvs):
def latex2png(snippet, outfile):
"""Compiles a LaTeX snippet to png"""
pngimage = os.path.join(IMAGEDIR, outfile + '.png')
+ texdocument = os.path.join(IMAGEDIR, 'tmp.tex')
+ with open(texdocument, 'w') as doc:
+ doc.write(LATEX_DOC % (snippet))
environment = os.environ
- environment['openout_any'] = 'a'
environment['shell_escape_commands'] = \
- "bibtex,bibtex8,kpsewhich,makeindex,mpost,repstopdf,gregorio"
+ "bibtex,bibtex8,kpsewhich,makeindex,mpost,repstopdf,\
+ gregorio,gregorio-4_2_0"
proc = Popen(
- ["lualatex", '-output-directory=' + IMAGEDIR],
+ ["lualatex", '-output-directory=' + IMAGEDIR, texdocument],
stdin=PIPE,
- stdout=DEVNULL,
+ stdout=STDERR,
env=environment
)
- proc.stdin.write(
- (
- LATEX_DOC % (snippet)
- ).encode("utf-8")
- )
proc.communicate()
proc.stdin.close()
- call(["pdfcrop", os.path.join(IMAGEDIR, "texput.pdf")], stdout=DEVNULL)
+ call(["pdfcrop", os.path.join(IMAGEDIR, "tmp.pdf")], stdout=STDERR)
call(
[
"gs",
"-sDEVICE=pngalpha",
"-r144",
"-sOutputFile=" + pngimage,
- os.path.join(IMAGEDIR, "texput-crop.pdf"),
+ os.path.join(IMAGEDIR, "tmp-crop.pdf"),
],
- stdout=DEVNULL,
+ stdout=STDERR,
)
@@ -117,12 +124,29 @@ def png(contents, latex_command):
return src
+def properties(meta):
+ try:
+ staffsize = int(
+ meta['music']['c']['gregorio']['c']['staffsize']['c']
+ )
+ except (KeyError, TypeError):
+ staffsize = 17
+ try:
+ initiallines = int(
+ meta['music']['c']['gregorio']['c']['initiallines']['c']
+ )
+ except (KeyError, TypeError):
+ initiallines = 1
+ return staffsize, initiallines
+
+
def gabc(key, value, fmt, meta): # pylint:disable=I0011,W0613
"""Handle gabc file inclusion and gabc code block."""
if key == 'Code':
[[ident, classes, kvs], contents] = value # pylint:disable=I0011,W0612
kvs = {key: value for key, value in kvs}
if "gabc" in classes:
+ staffsize, initiallines = properties(meta)
if fmt == "latex":
if ident == "":
label = ""
@@ -130,7 +154,10 @@ def gabc(key, value, fmt, meta): # pylint:disable=I0011,W0613
label = '\\label{' + ident + '}'
return latex(
"\n\\smallskip\n{%\n" +
- latexsnippet('\\gregorioscore{' + contents + '}', kvs) +
+ latexsnippet(
+ '\\gregorioscore{' + contents + '}',
+ kvs, staffsize, initiallines
+ ) +
"%\n}" +
label
)
@@ -143,7 +170,9 @@ def gabc(key, value, fmt, meta): # pylint:disable=I0011,W0613
return [Image(['', [], []], [], [
png(
contents,
- latexsnippet('\\gregorioscore', kvs)
+ latexsnippet(
+ '\\gregorioscore', kvs, staffsize, initiallines
+ )
),
""
])]
@@ -151,6 +180,7 @@ def gabc(key, value, fmt, meta): # pylint:disable=I0011,W0613
[[ident, classes, kvs], contents] = value
kvs = {key: value for key, value in kvs}
if "gabc" in classes:
+ staffsize, initiallines = properties(meta)
if fmt == "latex":
if ident == "":
label = ""
@@ -158,7 +188,10 @@ def gabc(key, value, fmt, meta): # pylint:disable=I0011,W0613
label = '\\label{' + ident + '}'
return [latexblock(
"\n\\smallskip\n{%\n" +
- latexsnippet('\\gabcsnippet{' + contents + '}', kvs) +
+ latexsnippet(
+ '\\gabcsnippet{' + contents + '}',
+ kvs, staffsize, initiallines
+ ) +
"%\n}" +
label
)]
@@ -166,7 +199,9 @@ def gabc(key, value, fmt, meta): # pylint:disable=I0011,W0613
return Para([Image(['', [], []], [], [
png(
contents,
- latexsnippet('\\gabcsnippet', kvs)
+ latexsnippet(
+ '\\gabcsnippet', kvs, staffsize, initiallines
+ )
),
""
])])
diff --git a/examples/graphviz-sample.md b/examples/graphviz-sample.md
new file mode 100644
index 0000000..1e1f0c8
--- /dev/null
+++ b/examples/graphviz-sample.md
@@ -0,0 +1,24 @@
+Use this
+
+
+```
+digraph G {Hello->World}
+```
+
+to get
+
+```graphviz
+digraph G {Hello->World}
+```
+
+with with Äüö
+
+```graphviz
+digraph G {Hello->World with Äüö}
+```
+
+See [(this is a link to whatever)](#whatever) for an example with options `{.graphviz #whatever caption="this is the caption" width=35%}`:
+
+```{.graphviz #whatever caption="this is the caption" width=35%}
+digraph G {Hello->World}
+```
diff --git a/examples/graphviz.py b/examples/graphviz.py
index 6d9cbc1..10db996 100755
--- a/examples/graphviz.py
+++ b/examples/graphviz.py
@@ -3,47 +3,33 @@
"""
Pandoc filter to process code blocks with class "graphviz" into
graphviz-generated images.
+
+Needs pygraphviz
"""
-import pygraphviz
-import hashlib
import os
import sys
-from pandocfilters import toJSONFilter, Str, Para, Image
-
-def sha1(x):
- return hashlib.sha1(x.encode(sys.getfilesystemencoding())).hexdigest()
-
-imagedir = "graphviz-images"
+import pygraphviz
+from pandocfilters import toJSONFilter, Para, Image, get_filename4code, get_caption, get_extension, get_value
-def graphviz(key, value, format, meta):
+def graphviz(key, value, format, _):
if key == 'CodeBlock':
[[ident, classes, keyvals], code] = value
- caption = "caption"
if "graphviz" in classes:
- G = pygraphviz.AGraph(string=code)
- G.layout()
- filename = sha1(code)
- if format == "html":
- filetype = "png"
- elif format == "latex":
- filetype = "pdf"
- else:
- filetype = "png"
- alt = Str(caption)
- src = imagedir + '/' + filename + '.' + filetype
- if not os.path.isfile(src):
- try:
- os.mkdir(imagedir)
- sys.stderr.write('Created directory ' + imagedir + '\n')
- except OSError:
- pass
- G.draw(src)
- sys.stderr.write('Created image ' + src + '\n')
- tit = ""
- return Para([Image(['', [], []], [alt], [src, tit])])
+ caption, typef, keyvals = get_caption(keyvals)
+ prog, keyvals = get_value(keyvals, u"prog", u"dot")
+ filetype = get_extension(format, "png", html="png", latex="pdf")
+ dest = get_filename4code("graphviz", code, filetype)
+
+ if not os.path.isfile(dest):
+ g = pygraphviz.AGraph(string=code)
... 625 lines suppressed ...
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-pandocfilters.git
More information about the Python-modules-commits
mailing list