BaileyJM02 / markdown-to-pdf

A GitHub Action to make PDF and HTML files from Markdown
MIT License
131 stars 32 forks source link

Feature: Add user defined variables for template #48

Open voronizer opened 1 year ago

voronizer commented 1 year ago

Hi! It will be great if there will be ability to define custom variables for the template. On example, I want to create first page of generated pdf as title page where I define title of document, authors, creation/modification date, etc.

It can be done thru adding action inputs parameter where .json file with template variables defined.

And then (just quick mockup):

let jsonData = require(path_to_user_variables.json);

And for: https://github.com/BaileyJM02/markdown-to-pdf/blob/1be26775add5f94fb55d4a2ce36ff7cad23b8dd0/src/markdown-to-pdf.js#L210

Change to:

let view = {
    title: title,
    style: this._style,
    toc: toc,
    content: body,
    vars: jsonData
};

In template:

<div class='title'>
{{{vars.documentTitle}}}
</div>
<div>
{{{vars.author}}}
</div>