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

Support different date formats in templates #197

Merged
merged 1 commit into from Sep 8, 2023
Merged

Conversation

poke
Copy link
Contributor

@poke poke commented Jun 2, 2020

This already came up before in #74 and #95 but I am not happy with leaving this to the locale default format. My VS Code is also in a different locale (English) than the format I would have wanted to use (German).

So I came up with a different way that allows transformations to be applied on the header and footer templates before they are passed to puppeteer. That way, one can skip the <span class="date"></span> part and just use placeholders that are replaced directly.

The supported placeholders for now are:

  • %%ISO-DATETIME%% – For an ISO-based date and time format: YYYY-MM-DD hh:mm:ss
  • %%ISO-DATE%% – For an ISO-based date format: YYYY-MM-DD
  • %%ISO-TIME%% – For an ISO-based time format: hh:mm:ss

I originally wanted to allow for completely custom formats but that would require some additional dependencies to format dates properly as one shouldn’t reinvent that.

With these placeholder, I can now simply configure my header template like this:

"markdown-pdf.headerTemplate": "<div style=\"font-size: 9px; margin-left: 1cm;\"> <span class='title'></span></div> <div style=\"font-size: 9px; margin-left: auto; margin-right: 1cm; \">%%ISO-DATE%%</div>"

@yzane yzane added this to the 1.5.0 milestone Jul 4, 2020
@tonoriesco
Copy link

Hi,

I was looking for the date problem in the headers and I found this.
There is any reason to don't merging ?
The US date in the header is really painful!

Thanks.

@koying
Copy link

koying commented Dec 31, 2020

A workaround is to install vscode "English (United Kingdom)" language pack.
You at least get dates in a no-nonsense DD/MM/YYY format

@QbikEdge
Copy link

QbikEdge commented Jun 1, 2021

This already came up before in #74 and #95 but I am not happy with leaving this to the locale default format. My VS Code is also in a different locale (English) than the format I would have wanted to use (German).

So I came up with a different way that allows transformations to be applied on the header and footer templates before they are passed to puppeteer. That way, one can skip the <span class="date"></span> part and just use placeholders that are replaced directly.

The supported placeholders for now are:

  • %%ISO-DATETIME%% – For an ISO-based date and time format: YYYY-MM-DD hh:mm:ss
  • %%ISO-DATE%% – For an ISO-based date format: YYYY-MM-DD
  • %%ISO-TIME%% – For an ISO-based time format: hh:mm:ss

I originally wanted to allow for completely custom formats but that would require some additional dependencies to format dates properly as one shouldn’t reinvent that.

With these placeholder, I can now simply configure my header template like this:

"markdown-pdf.headerTemplate": "<div style=\"font-size: 9px; margin-left: 1cm;\"> <span class='title'></span></div> <div style=\"font-size: 9px; margin-left: auto; margin-right: 1cm; \">%%ISO-DATE%%</div>"

Can you make example how to use the placeholder. I did set the headerTemplate in the settings as given but it rendert no date
it just put the place holder as it is.

@martin-brajer
Copy link

Can you make example how to use the placeholder. I did set the headerTemplate in the settings as given but it rendert no date it just put the place holder as it is.

This update is not merged yet.

@donvipre
Copy link

donvipre commented Sep 7, 2022

Hi,
what prevents a merge in this case?
This feature is really useful.

@deminngi
Copy link

Hi @yzane,
I patched this pull request into the current extensions.js file and works like a charme.
Why is this PR not included in the actual release?
Thank you.

@ikt32
Copy link

ikt32 commented Aug 9, 2023

Also waiting for this - but the author seems to have gone missing from March 2020.

@TheScienceOf
Copy link

I did the same as @giminni and it worked like a charm.

@yzane
Copy link
Owner

yzane commented Aug 17, 2023

Thanks for your PR!

@yzane yzane merged commit 50f8ed9 into yzane:master Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants