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

Change date format in header #210

Open
drrhf opened this issue Sep 23, 2020 · 13 comments
Open

Change date format in header #210

drrhf opened this issue Sep 23, 2020 · 13 comments

Comments

@drrhf
Copy link

drrhf commented Sep 23, 2020

Nice program.
Is there a simple way to change the date format in the pdf header to display the date as YYYY-MM-DD?
Thanks

@Simon-Gregory-LG
Copy link

+1 for this request - or at least use the default locale, or allow to specify ISO 8601 (as @drrhf suggests).

As far as I can see it's fixed to the US format, and that's really only useful in the US! ;)

Thanks

@m-birke
Copy link

m-birke commented Jan 15, 2021

+1 from my side.

ps: I really appreciate your extension :)

@tonyhomfray
Copy link

+1 from me to customise the date in settings or default to local PC settings.

Thanks

@denzfox
Copy link

denzfox commented Jun 12, 2021

Please add either UK or Swedish date format as an option, thanks! :)

@knuth-konrad
Copy link

or allow to specify ISO 8601

If anything, ISO 8601 should be the default format (and every sane MD author should use it when creating any document). Other proprietary regional formats should be considered optional.

jola5 added a commit to jola5/vscode-markdown-pdf that referenced this issue Nov 17, 2021
The lang argument to chromium via puppeteer is broken. A working solution is to provide the same language option as part of the browser environment.
@jola5
Copy link

jola5 commented Nov 17, 2021

Ok, that one really annoyed me. After quite some digging I still can't work around this issue properly. What a pity. But at least I can share what I tried and what actually works.

tl;dr:
Changing your VS Code language setting that gives the desired date format should do the trick. Bit it doesn't work for me. Changing your system locale may work. Only changing the extension source works for me.

Details:
By default this extension uses a bundled chromium installation called puppeteer to do the markdown (via HTML) to PDF conversion. Naturally you can change the locale of puppeteer. You can find different ways on how to do it here https://stackoverflow.com/a/47292022. In the case of this extension puppeteer is configured to use the vscode language setting. You can find it in extension.js around line 400, there's the options for the puppeteer launch.

var options = {
executablePath: vscode.workspace.getConfiguration('markdown-pdf')['executablePath'] || puppeteer.executablePath(),
args: ['--lang='+vscode.env.language, '--no-sandbox', '--disable-setuid-sandbox']
// Setting Up Chrome Linux Sandbox
// https://github.com/puppeteer/puppeteer/blob/master
};

What we are looking for is --lang='+vscode.env.language. So you could simply change the date format for the created PDF by changing this specific VS code language setting. Not very neat but hackable. But on linux (what I'm using) the lang argument seems to be broken since some time https://bugs.chromium.org/p/chromium/issues/detail?id=755338#c14. And maybe it can't be done at all https://bugs.chromium.org/p/chromium/issues/detail?id=234897

Since this extension allows to use an a chromium installation provided somewhere else, another road to success could be to configure markdown-pdf.executablePath to use that chromium on your machine and properly configure it for your desired date/language settings (since the lang argument is ignored anyway). But, alas, this probably will be overwritten by the --lang='+vscode.env.language argument as well. At least I assume this would be the case - I didn't test it.

Although this looked promising, or at least doable it didn't work for me. Neither changing the VS code language setting nor hacking the extension directly by manipulating extension.js to use --lang=de (for German in my case, or de-DE or the likes). Nor any of the other solutions from the above mentioned stackoverflow answer.

The only thing that actually worked was to provide a separate environment variable to the chromium instance launched by puppeteer. What I needed to do was add LANG: 'de' to the environment, which by default is process.env. Since hard coding the language setting this way works I tried using customEnv.LANG = vscode.env.language; to use the VS code language setting and this works as well. That's the best hacky solution I could get to work.

Finally extension.js at around line 400 becomes:

var customEnv = process.env;
customEnv.LANG = vscode.env.language;

var options = {
    executablePath: vscode.workspace.getConfiguration('markdown-pdf')['executablePath'] || puppeteer.executablePath(),
    args: ['--lang=' + vscode.env.language, '--no-sandbox', '--disable-setuid-sandbox'],
    // Setting Up Chrome Linux Sandbox
    // https://github.com/puppeteer/puppeteer/blob/master/docs/troubleshooting.md#setting-up-chrome-linux-sandbox
    env: customEnv
};

In theory it should be way easier but this was the only workaround that solved this for me.

PR is open here #267 - but the extension seems abandoned. Let's see if and how this continues.

Cheers

@jola5 jola5 mentioned this issue Nov 17, 2021
@fuhrmanator
Copy link

I'm in Canada, but there's no en-CA locale (that I can find to set) in my vscode . How will #267 handle that situation?

@jola5
Copy link

jola5 commented Feb 6, 2022

#267 doesn't care it is totally transparent to what locale you want to use. The important question is: Does vscode and/or chromium support the locale? Since the answer for 'en-CA' is no, it seems neither vscode nor chromium supports that, there will be a fallback locale. Presumably that is en(en-US) for you.

tl;dr
I'm neither a vscode nor a chromium expert. But the list of supported languages for chromium extensions may be what you could check: https://developer.chrome.com/docs/webstore/i18n/#choosing-locales-to-support. Chromium doesn't seem to support en-CA though. Vscode doesn't seem to support that specific locale either, see: https://code.visualstudio.com/docs/getstarted/locales. I couldn't even find one in the market place.

@fuhrmanator
Copy link

en-US is precisely the problem with the default date (compared to the rest of the world). It seems to be the reason there was a bug report of #95 and the user proposing a fix was apparently is in Australia, fixing it with en-AU (?).

Anyway, I hard-coded the --lang=en-CA locale in the extension.js file and it fixes the problem for me. I'm on Windows, if that makes a difference.

The point I'm making is that it seems useless to pass the locale from VScode if the problem is English dates (UK, AU, CA, ?), since there's only one locale. A workaround would be a preference in the plug-in where you can pass the lang= setting to puppeteer.

@senspix
Copy link

senspix commented Nov 30, 2022

+1 from me to customise the date in settings.

Thanks

@ultrablue
Copy link

+1 from me to use a customizable date format in the header.

@brigittesullivan
Copy link

+1 from me. I agree this functionality should be included in the extension.

@mtsknn
Copy link

mtsknn commented Nov 13, 2024

Anyway, I hard-coded the --lang=en-CA locale in the extension.js file and it fixes the problem for me. I'm on Windows, if that makes a difference.

Thanks for the tip, @fuhrmanator!

On Mac the file to modify is:

  • ~/.vscode/extensions/yzane.markdown-pdf-1.5.0/extension.js if using VS Code
  • ~/.vscode-oss/extensions/yzane.markdown-pdf-1.5.0-universal/extension.js if using VSCodium

The line to change:

args: ['--lang='+vscode.env.language, '--no-sandbox', '--disable-setuid-sandbox']

Example:

- args: ['--lang='+vscode.env.language, '--no-sandbox', '--disable-setuid-sandbox']
+ args: ['--lang=fi-FI', '--no-sandbox', '--disable-setuid-sandbox']

Then run the "Developer: Reload Window" command via VS Code's Command Palette for the change to take effect. (The "Developer: Restart Extension Host" command might also do the trick.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests