diff --git a/build/build.sh b/build/build.sh index e40ff643..950956f7 100644 --- a/build/build.sh +++ b/build/build.sh @@ -52,6 +52,8 @@ then --to=docx \ --filter pandoc-fignos \ --filter pandoc-tablenos \ + --filter pandoc-img-glob \ + --filter build/pandoc-svg.py \ --bibliography=$BIBLIOGRAPHY_PATH \ --metadata link-citations=true \ --csl=$CSL_PATH \ diff --git a/build/environment.yml b/build/environment.yml index 354fa1b1..bf4553d9 100644 --- a/build/environment.yml +++ b/build/environment.yml @@ -17,6 +17,9 @@ dependencies: - git+https://github.com/greenelab/manubot@b0da17625e1f12091159f15a329391b85c205565 - pandoc-eqnos==0.16 - pandoc-fignos==0.20 + - pandoc-img-glob==0.1.3 + - pandocfilters==1.4.1 + - panflute==1.10.5 - pandoc-tablenos==0.16 - pybase62==0.3.2 - pysha3==1.0.2 diff --git a/build/pandoc-svg.py b/build/pandoc-svg.py new file mode 100644 index 00000000..7b4594fd --- /dev/null +++ b/build/pandoc-svg.py @@ -0,0 +1,65 @@ +#! /usr/bin/env python +""" +Pandoc filter to convert svg files to pdf as suggested at: +https://github.com/jgm/pandoc/issues/265#issuecomment-27317316 +""" + +__author__ = "Jerome Robert" + +import mimetypes +import subprocess +import os +import sys +import re +import urllib +from pandocfilters import toJSONFilter, Para, Image + +fmt_to_option = { + "docx": ("--export-pdf", "pdf") +} + + +build_dir = os.getcwd() +img_dir = "content/images/" + + +def svg_to_any(key, value, fmt, meta): + if key == 'Image': + if len(value) == 2: + # before pandoc 1.16 + alt, [src, title] = value + attrs = None + else: + attrs, alt, [src, title] = value + mimet, _ = mimetypes.guess_type(src) + option = fmt_to_option.get(fmt) + if mimet == 'image/svg+xml' and option: + web_image = re.compile('^http[s]?://') + if web_image.match(src): + base_name = os.path.basename(src) + base_name, _ = os.path.splitext(base_name) + eps_name = os.path.join(build_dir, img_dir, base_name + "." + option[1]) + file_name = src + else: + base_name, _ = os.path.splitext(src) + eps_name = os.path.join(build_dir, base_name + "." + option[1]) + file_name = os.path.join(build_dir, src) + try: + mtime = os.path.getmtime(eps_name) + except OSError: + mtime = -1 + try: + src_mtime = os.path.getmtime(src) + except FileNotFoundError: + src_mtime = -1 + if mtime < src_mtime or web_image.match(src): + cmd_line = ['inkscape', option[0], eps_name, file_name] + sys.stderr.write("Running %s\n" % " ".join(cmd_line)) + subprocess.call(cmd_line, stdout=sys.stderr.fileno()) + if attrs: + return Image(attrs, alt, [eps_name, title]) + else: + return Image(alt, [eps_name, title]) + +if __name__ == "__main__": + toJSONFilter(svg_to_any) diff --git a/content/00.front-matter.md b/content/00.front-matter.md index be8a2b8b..428c5138 100644 --- a/content/00.front-matter.md +++ b/content/00.front-matter.md @@ -11,15 +11,15 @@ on {{date}}. {% for author in authors %} + **{{author.name}}**
{%- if author.orcid is defined %} - ![ORCID icon](images/orcid.svg){height="13px"} + ![ORCID icon](images/orcid.svg){height="13px" width="13px"} [{{author.orcid}}](https://orcid.org/{{author.orcid}}) {%- endif %} {%- if author.github is defined %} - · ![GitHub icon](images/github.svg){height="13px"} + · ![GitHub icon](images/github.svg){height="13px" width="13px"} [{{author.github}}](https://github.com/{{author.github}}) {%- endif %} {%- if author.twitter is defined %} - · ![Twitter icon](images/twitter.svg){height="13px"} + · ![Twitter icon](images/twitter.svg){height="13px" width="13px"} [{{author.twitter}}](https://twitter.com/{{author.twitter}}) {%- endif %}
diff --git a/references/pandoc-reference.docx b/references/pandoc-reference.docx index a2a657a9..1c4f68cc 100644 Binary files a/references/pandoc-reference.docx and b/references/pandoc-reference.docx differ