Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a template variable containing the name of the source file #3431

Closed
rohieb opened this issue Feb 9, 2017 · 8 comments
Closed

Add a template variable containing the name of the source file #3431

rohieb opened this issue Feb 9, 2017 · 8 comments

Comments

@rohieb
Copy link
Contributor

rohieb commented Feb 9, 2017

I keep several Markdown documents in a Git repository which are rendered to MediaWiki through a custom template. In the MediaWiki template, I want to add a "this file is autogenerated" warning, with a link to the source file in the Git repository. For this reason, it would be nice to have a template variable, e.g. $filename$ or $jobname$ (inspired by LaTeX), so my template could have:

<!-- Warning: this file is auto-generated!
     See instead: https://github.com/stratum0/dokumente/$filename$
  -->
@jgm
Copy link
Owner

jgm commented Feb 9, 2017

A reasonable request. But to mention one complexity: pandoc can take multiple input files on the command line. It can also parse from stdin, in which case there are no input files. Both cases would have to be handled as well.

@rohieb
Copy link
Contributor Author

rohieb commented Feb 9, 2017

Right! I just used \jobname in LaTeX with stdin, which got rendered as input, pandoc could do the same. For multiple files, the variable could be an array, like e.g. $classoption$ already is. The additional $for$ is sensible overhead.

@rohieb
Copy link
Contributor Author

rohieb commented Feb 9, 2017

BTW, I tried to do a pull-request myself, but I couldn't figure out where the template variables are set in the code… Any pointers on that? :)

@mb21
Copy link
Collaborator

mb21 commented Feb 12, 2017

For the template variable to be available in all formats, I think you'll ned to make sure it is set in this doc'. The doc' should be of type Pandoc meta blocks, so specifically it should be in the meta of type Meta. But I'm not sure where the proper place to set it is...

@rohieb
Copy link
Contributor Author

rohieb commented Feb 12, 2017 via email

@jgm
Copy link
Owner

jgm commented Feb 12, 2017

No, the best approach is to set a variable, not metadata. Variables just affect template rendering, which is what you want. Just add it to writerVariables in Text.Pandoc.App.

@mb21
Copy link
Collaborator

mb21 commented Feb 12, 2017

ah right, so somewhere around here then...

@rohieb sorry for the wrong tip...

rohieb added a commit to rohieb/pandoc that referenced this issue Feb 12, 2017
rohieb added a commit to rohieb/pandoc that referenced this issue Feb 12, 2017
@rohieb
Copy link
Contributor Author

rohieb commented Feb 12, 2017

@mb21 you're welcome, I learned a lot today! :D That solution was also what had first had in mind, but somehow I didn't follow it.

It took less time than expected, and I consider #3439 ready now. I still don't quite understand how exactly the withList constructs work, but it compiles and does what I want… :) Nevertheless, feel free to nitpick, especially on code style.

@jgm jgm added the templates label Feb 22, 2017
rohieb added a commit to rohieb/pandoc that referenced this issue Feb 24, 2017
rohieb added a commit to rohieb/pandoc that referenced this issue Feb 24, 2017
@jgm jgm closed this as completed in 699d289 Feb 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants