marp-team / marp-cli

A CLI interface for Marp and Marpit based converters
MIT License
1.91k stars 107 forks source link

Add support for `lang` directive #542

Closed ludelafo closed 1 year ago

ludelafo commented 1 year ago

In order to use the hyphens CSS property as mentioned in https://github.com/marp-team/marp-vscode/issues/430, a new lang global directive must be implemented.

A starting point would be https://github.com/marp-team/marp-cli/blob/d0cee502f2785e1a2f998f3afc831849e3f6efc9/src/marp-cli.ts and https://github.com/marp-team/marp-cli/blob/d0cee502f2785e1a2f998f3afc831849e3f6efc9/src/engine/meta-plugin.ts by adding a lang directive.

I see at https://github.com/marp-team/marp-cli/blob/d0cee502f2785e1a2f998f3afc831849e3f6efc9/src/templates/layout.pug#L2 that the HTML lang is set here. If I understand it correctly, this value is passed by the --lang argument of the CLI where a new global directive should also set this value if set.

Please correct me if I'm wrong. I would be glad to implement this feature if you are interested.

yhatt commented 1 year ago

Currently Marp CLI uses the locale of running OS as the value for the lang attribute of the <html> element. https://github.com/marp-team/marp-cli/blob/d0cee502f2785e1a2f998f3afc831849e3f6efc9/src/config.ts#L293

Unlike similar options for metadata, the CLI argument --lang is not supported in the current Marp CLI, and changes are only supported in the lang field of the configuration file. Therefore, it may be a little hard to contribute for that.

This decision was made to prevent unnecessary confusion for not specialized users. Providing an easily changeable CLI option / global directive might lead unintended rendering output and a bit of confusion, especially in East Asian languages. https://heistak.github.io/your-code-displays-japanese-wrong/

However, considering the appropriate purpose of "document-level language setting", adding --lang option and the lang global directive support would be justified.

yhatt commented 1 year ago

This issue may be best drilling down to Marp Core, and even Marpit, the framework to build a core.

The lang attribute can be used on any tag, not just <html>. Given that the snippets of slides generated by Marp are also used by third-party implementations outside of the official Marp tools, so it is better to have the lang attribute on each slide tags, rather than the <html> tag. (Note that it's not meaning to remove lang attribute from <html> provided by Marp CLI templates)

If there were lang attribute in each slide, the display reproducibility of the slide in cases where multiple languages are mixed in a single HTML. e.g. a web page/app with Marp slides as a part of HTML.

ludelafo commented 1 year ago

Thank you very much @yhatt!