Language setting in Markdown notes

I’m writing notes in Markdown, mostly in German but also some in English. I’ve set my editor pane to a quite narrow column, so I’ve activated hyphenation in the style sheet for my Markdown notes. I use DEVONthink with the English user interface.

And there lies the rub: DEVONthink sets the language in the rendered Markdown to the language of the user interface. This means that the hyphenation in my German notes is kaputt.

As far as I know, there’s no way to set the language in CSS. I know there’s the :language pseudo-class, but it can only be used to style text in a certain language (like a special non-Latin font for the non-Latin parts of a text that otherwise is written in a language with Latin letters). The language is set in the HTML code, in the <body> tag, as the default, and in <span> or <div> for exceptions.

MultiMarkdown—again: to my knowledge—can contain a metadata called Language:, but it wouldn’t affect how it’s rendered in HTML. Is there any way of setting the language for Markdown notes, other than adding unelegantly and un-markdownily HTML code? Could DEVONthink get a setting to at least set the default Markdown language independently of the user interface language?

Correct. And “of course” :wink: CSS is about style, not content.

Unfortunately, it does exactly zilch. Nothing. Why would be a question for @cgrunenberg or @BLUEFROG.

The HTML generated by the MMD processor in DT is quite rudimentary in that it doesn’t contain any lang setting at all in the html element. It should do, in my opinion

Even that won’t help you. The lang attribute must be set on an element, preferably the html element. But you can’t include a html element in your MD file. Nor any other element that would set the lang correctly for the whole document.

Perhaps the power that be (@cgrunenberg?) could do something about it?

Edit Here’s what you could do (and I admit upfront that it’s at best a nasty workaround, not a solution).
Create a JavaScript file (say “lang.js”), save that somewhere, and add it to the JavaScript part of DT’s markdown setting.

  document.addEventListener('DOMContentLoaded', () => {
     const htmlEl = document.querySelector('html');
     html.lang = 'de';
  })

You can also add this code inside a script element at the top of a MD file to see if/how it works.
This will set the lang attribute to “de” in the html element. It does so, however, after the document has finished loading. So, I can’t promise that this will cause the hyphenation to be modified. Give it a try.

Is there a common Markdown syntax for this?

The metadata section of the MultiMarkdown 6 syntax guide only contains of this:

 Title:	This is a title
 Author:	Fletcher T. Penney
 HTML Header: 

Maybe the HTML Header part could be of any use?

There is a metadata item in the MMD6 specification. I can’t test if that does what it says it would do, though. But what I expect is this:

  • set language: de_DE in the MD header
  • have <html lang="de_DE"... in the rendered HTML

That would at least allow a language setting per Markdown file. A better approach might be to set the language in the html element from the user’s locale:

  • If there’s no language: in the MD header, use the user’s locale setting
  • If there is a language: in the MD header, use that instead.

Even more sophisticated would be separate locale setting for MD files in the DT preferences :wink: That way, users could override the system wide settings in DT and the DT settings in individual MD files.

Just dreaming …

There are already way too many options and we try to avoid adding even more unless there’s a common need for it (as more options make support more difficult and do not simplify the learning curve for new users).

2 Likes

Understandable, but I’d say it’s not just me but there actually is a common need for proper hyphenation (and quotes) in Markdown notes.

Interestingly, Fletcher Penney’s (the inventor of MultiMarkdown) own MultiMarkdown Composer does ignore the hyphen: auto setting, so I can’t test the language: de_DE setting.

It doesn’t do anything in DEVONthink. Marked on the other hand hyphenates correctly without any language setting. (It might take the user interface language of macOS as a default though; I won’t check that by switching the whole OS language, at least for the time being.)

The next release will support this.

5 Likes

Great (as always)!

Of course, like I said, I would prefer if the default language would be independent from the UI setting. But I can work with this solution. Sounds like a job for a script to add the language metadata to existing Markdown notes.