jgm / pandoc

Universal markup converter
https://pandoc.org
Other
34.6k stars 3.38k forks source link

Extension to pandoc's markdown similar to Gitbook, using a "Web template system" #2676

Closed xoox closed 7 years ago

xoox commented 8 years ago

Hi, Gitbook Templating would be a powerful extension to pandoc's markdown (not for pandoc's templates). That could also be a substitution to macros.

Besides, many static site generators are powered by similar templating feature. With it, pandoc will get the capability sharing the same markdown source with others, which could utilize pandoc as their renderer if configurable.

There're so many template systems. To find the one acceptable to pandoc community, a survey might be needed.

jgm commented 8 years ago

You know pandoc already has a templating system, don't you? See the manual under Templates. It is different from the one you link to, but at least as powerful.

xoox commented 8 years ago

Oops, I think I used wrong words.

Basically It is an extension to pandoc's markdown instead of pandoc's templates. That extension would enable variables and tags in markdown.

{% include "./test.md" %} Importing an other file's content.

{% for author in authors %}
  - {{ author.name }}
{% endfor %}

will generate a list of authors.

The extension may be a pre-processing function in Markdown.hs reader.

There are several Haskell packages supporting similar syntax and features to Jinja2. With them, the extension should need not too much work.

For information of other template system, see Web template system

jgm commented 8 years ago

So the real issue is that you'd like some kind of preprocessor, run before Markdown parsing, that interpolates variables from metadata and can include external files.

This wouldn't be easy, since pandoc allows YAML metadata blocks anywhere in the document. So you really have to parse Markdown in order to know what the metadata is.

I would suggest, if you want a preprocessor, that you just write one yourself and pipe your input through it before sending it to pandoc. Or use an existing one as suggested here.

EDIT: Just looked at the gitbook templating link. I guess all their variables are set in an external json file.

xoox commented 8 years ago

Thanks for your clarification. YAML anywhere in the document is an obstacle to this possible extension. I'm trying with nunjucks. And YAML data have to be converted to JSON. To sharing the same metadata, they should be kept in a separate YAML file.