Comments (9)
Yes, the metadata is read from YAML, that is not the problem. It's more about having a generic common template partial which can be the same for different output formats.
I'll try to illustrate the usecase tomorrow to hopefully make it less prone to misunderstandings.
from doctemplates.
Anything that needs to be converted (e.g. your front matter) should be in a source document, not a template. Templates are just for presenting already rendered content. It may be that I don't sufficiently understand your case, though. An example might help.
from doctemplates.
Hi John!
I agree that templates are for rendering metadata and the enclosing form of the user-provided document. That is what we are doing, as all the data in the template is pulled from YAML. The rationale behind this proposal is, that we have to reproduce the same data structure + document faithfully in different formats. And this is where the possibility for a common partial which can be included by templates to different formats would be helpfuls.
Example
I am working in academia and we have many projects wiht space agencies. Customary all documents have to present human readable meta-data in a given format, fixed by contracts, project descriptions, work-breakdown-structure etc.
Here an example of how the first pages of such a document, regardless of the output format, have to be structured:
We see: Basically nothing, that pandoc cannot currently do. Which is great! But currently there are basically two alleys we can walk to get to this result:
- Prepare one template for each format and very carefully keep them all in sync
- Upsides:
- Nothing has to change
- Lean from a user perspective
- Can be codified in a defaults file and thus very easily and safely operated by anybody on the project
- Downsides:
- Maintenance of document template multiplies by formats
- Maintenance requires knowledge of all the formats and the representation of tables, texts, lists etc.
- Upsides:
- Precompile the document with a common template to markdown, then compile the intermediate to the final format
- Upsides:
- Only knowledge of markdown required to maintain template
- Impossible for different formats to drift apart
- Downsides:
- Complicated build-train requiring scripts or a build-system, introducing points of failure
- Not feasable just with pandoc and defaults files
- As pandoc lacks knowledge of the final format, structures (e.g. the TOC, footnotes...) generated in an earlier step might fail or work only partially
- Upsides:
The latter is what we currently do to generate our documentation.
Where does the proposal fit in?
Basically the proposal is to solve most of the downsides of the second workflow by introducing the possibility to translate a partial. This way there still will be templates for each format, but they will only include format-specific information and will call the same partial at the approriate location to generate the front-matter. This way everything could be handled again with defaults files and a simple pandoc invocation.
Why not use a Lua filter for it or something else? Basically this would be a valid solution which I already considered and worked on some time. But my gut feeling is, that this kind of preparation of a document and it's metadata's representation is so close to what I feel pandoc's templates are essentially conceived for, that it seems to be the appropriate place to put this functionality on the long haul.
Alternative ideas
- One could try to do this with a Lua filter
- Still maintenance would probably require more knowledge then upkeep of one common template would do
- More likely to break at some point in the future
- Introduction of basically the complement to pandoc's raw_attribute: An attribute which tells pandoc to read an environment, parse it in a given format, and merge the result instead of the original environment into the AST
- Fancy idea, but seems much more complicated. Maybe only feasable on the long run, who knows.
from doctemplates.
Downsides:
Maintenance of document template multiplies by formats
Maintenance requires knowledge of all the formats and the representation of tables, texts, lists etc.
I still don't get it. Your tables, lists, etc. should be stored in markdown documents or YAML metadata and converted by pandoc and then inserted into a template. You shouldn't need to hard-code them in the template itself: just place a variable where they need to go.
from doctemplates.
Thanks for the patience. It was a busy week. I did a little sketch and hope that it will help clarify what the current situation for our usecase is, how we work around the limitation and what the goal of the proposal is. In case the SVG display in github is wonky or to small to be read comfortably (there's text in the file-symbols, yes 😉 ), I attached a PDf file.
So currently, to avoid maintaining a front-matter template for every format we generate ( 1 in the sketch), we go route 2 and render our source documents with a template containing the front-matter data to markdown to bake this information in and after this we convert the new markdown document to all the formats we need. So we have only one place to maintain the header tables and preamble information.
In our template we make massive use of template variables, for-loops, conditionals etc. to fill the tables and sections with values from YAML metadata or to manipulate rendering of certain parts of the front-matter.
Upside is also, as most people in my insitute only know markdown by now, almost everybody can adjust the front-matter and not only the "specialists" which know all the formats. And it is only one document that hast do be changed, not three or four.
from doctemplates.
You could do this quite easily, e.g., with a Makefile that builds frontmatter.x from frontmatter.markdown as part of the build process. Nobody would ever have to touch anything but frontmatter.markdown; the other files would just be temporary intermediaries, automatically generated. Maybe that's what you're doing? Isn't that a perfectly satisfactory solution? In what way would things be improved for you if pandoc behaved differently?
from doctemplates.
Currently we are using gnumake or meson to automate the frontmatter generation and shell piping to connect results of different pandoc runs into the final documents. This works mostly.
What I noticed is, that - due to the first run being a markdown-markdown transformation (so in the merged document citreproc and pandoc-crossref can run on all parts) - pandoc does not know about the final format. So for example the table of contents, which is part of the frontmatter, is generated in markdown-format. When the final document is then translated to e.g. HTML the table the TOC is only a basic list and not a nav element with a list of elments with special attributes tailored to HTML representation.
We partly compensate these shortcomings by adding raw-blocks for certain formats, but this way still cannot influence generation of elements. So we are missing out on some of pandoc's intelligence when we cannot tell it the final format.
After all I thought, as the generation of a frontmatter is a common problem faced in many parts of science and industry, it would be handy if pandoc could ease this usecase by having a feature to interpret a partial. I know my way around shell-scripts, make and all this stuff, but the big majority of my collegues does not. This complexity makes it not easy to argue the case for finally getting rid of Word and sending-commented-docx-back-forth-by-email. Which is a second point I would dare say we would benefit from a more elegant solution than piped pandoc-runs.
from doctemplates.
All template handling, including partial rendering, is done by a library doctemplates
that is a dependency of pandoc. Even if I wanted to do this (and I'm not sure I do, because simplicity is itself a kind of elegance), I couldn't do it without circular module dependencies. (doctemplates
would have to import pandoc to create such a pipe.)
Of course, nothing stops you from using a shell command, including pandoc, to populate a template variable. For example,
pandoc --variable foo="`pandoc input.md -t html`" -s
Maybe that could help in your case.
from doctemplates.
Of course, nothing stops you from using a shell command, including pandoc, to populate a template variable.
This seems to be a good new idea. I will have look. Thanks!
from doctemplates.
Related Issues (20)
- Naming of Pipes/Filters HOT 2
- Custom Pipes HOT 8
- Feature Request: Option to include files HOT 1
- Add a variable pipe transform that removes whitespace HOT 4
- Cannot access outer loop variables in templates with nested loops HOT 3
- Add option to disable "default true" parameters HOT 1
- Error on missing context variable HOT 3
- doctemplates-0.2.1 does not compile with ghc 8.4.1 HOT 2
- Feature : Add some functions that can be used in the pipe
- Dynamic partials possible?
- Is there a way to check if length > 1? HOT 1
- Error using partials with no extension when output format is beamer
- Custom delimiters (use a character other than '$') HOT 3
- conversion from JSON values - is it possible to force it? HOT 1
- Misleading error message for unmatched template conditionals HOT 8
- add timestamp support in markdown variables HOT 1
- Add ability to iterate over key/value pairs in a map
- Module ‘Data.YAML’ does not export ‘ToYAML(..)’ HOT 1
- Overlapping instances HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from doctemplates.