Title: Allow Preview to use a note’s content language (lang
) independently of UI language (proper hyphenation)
Use case or problem
I keep Obsidian’s UI language in English, but I often write notes in German (also de-CH, sometimes FR/ES). In Preview, justified text relies on:
.markdown-preview-section p { text-align: justify; hyphens: auto; }
However, hyphenation is only reliable when the rendered HTML has the correct lang
attribute (e.g., lang="de"
). With the UI set to English, the Preview container typically lacks lang="de"
, so Chromium/Electron picks the wrong dictionary: so hyphenation becomes rare/inconsistent, which hurts readability for long-form notes.
Technical note: browsers choose hyphenation by DOM lang
, not CSS. -webkit-locale
is unreliable, and CSS cannot set lang
.
Proposed solution
Provide a way to set the content language independent of the UI language, and apply it to the Preview content element.
Concretely:
- Frontmatter control (preferred)
- Respect
lang:
in note frontmatter and set it on the Preview content container (e.g.,.markdown-preview-section
). - Example:
---
lang: de # or de-CH, en, fr, …
---
Rendered DOM (illustrative):
<div class="markdown-preview-view">
<div class="markdown-preview-section" lang="de">
…note content…
</div>
</div>
- Vault default (fallback)
- A setting like “Default content language for Preview” with options:
- System/none, Use UI language, or a specific BCP-47 tag (e.g.,
de-CH
).
- System/none, Use UI language, or a specific BCP-47 tag (e.g.,
- Used when a note doesn’t specify
lang
in frontmatter.
- Nice to have
- Apply the same logic to the Editor container (CodeMirror) for consistency.
- Expose a small API so plugins can set/override the content
lang
for a view.
This is standards-aligned (just setting an attribute), low-risk, and improves typography for many non-English users.
Current workaround (optional)
- Manually wrap the note body:
<div lang="de">
…content…
</div>
This immediately fixes Preview hyphenation, but it’s manual, noisy in Markdown, and doesn’t help the Editor.
- A tiny plugin can force
lang="de"
on Preview/Editor containers as a stopgap. (I’m happy to share one if useful.)
Related feature requests (optional)
I didn’t find an exact match yet. Suggested keywords others might have used: hyphenation, hyphens auto, preview lang attribute, per-note language, content language.
Maybe these could also help users with this Problem: https://forum.obsidian.md/t/how-to-set-language-for-individual-note-in-order-to-use-proper-spellchecker/31967
This would not only fix hyphenation in Preview, but could also help users who need a proper spellchecker per note. If Obsidian respected a lang:
value in frontmatter, the editor could switch the spellchecking dictionary accordingly (e.g., en
for English notes, de
for German notes).
Environment (for reference):
- Obsidian version: 1.9.12
- OS: 15.6.1 (24G90)
- UI language: English
- Typical content language: German (
de
/de-CH
) - Rendering target: Preview (Editor affected separately)
Thanks for considering! This would let us keep the UI in English while getting correct hyphenation for content written in other languages—crucial for readable, justified long-form notes.