Markdown Template / style like "read the docs" for documents

Hi :slight_smile:

I’ve been using DEVONthink for some years now and it has become my “go-to-place” for external and internal documents and documentation. Great piece of software! :smiling_face_with_three_hearts:

What I’m struggling a little bit with is own documentation using markdown files. Not on a technical basis, it’s more a readability issue for me or maybe just aesthetics… :wink:

Is there any way to apply the theme of “read the docs” to markdown files? An example layout would be

Especially the “Note” and “Important” environments.

I know that you can use CSS as a rendering template but unfortunately re-creating this template in CSS is beyond my capabilities.

One a sidenote - to manage expectations here - I’m not asking anyone to create this for me, but maybe someone knows if anything similar already exists?

Thanks in advance,
have a nice weekend!

You can achieve this with the following css style code

.note, .important {
    border-left: 4px solid;
    padding: 0;
    margin: 20px 0;
    font-family: Arial, sans-serif;
}

.note .title-bar, .important .title-bar {
    font-weight: bold;
    color: #fff;
    padding: 10px 20px;
    display: flex;
    align-items: center;
}

.note {
    border-color: #2196F3;
    background-color: #e7f3fe;
}

.note .title-bar {
    background-color: #2196F3;
}

.important {
    border-color: #ffb100;
    background-color: #fff9e6;
}

.important .title-bar {
    background-color: #ffb100;
}

.note .title-bar:before, .important .title-bar:before {
    font-size: 20px;
    margin-right: 10px;
}

.note .title-bar:before {
    content: "ℹ️";
}

.important .title-bar:before {
    content: "⚠️";
}

.box-content {
    padding: 10px 20px;
}

and the following html code in the markdown document:

<div class="note">
    <div class="title-bar"><span>Note</span></div>
    <div class="box-content">
        <p>Attempting to run powertop --auto-tune on boot may overwrite TLP's settings (depending on whether Powertop or TLP is invoked first in the boot order).</p>
        <p>Furthermore, TLP will overwrite Powertop’s initial settings every time the power source changes.</p>
        <p>Refer to How it works for details.</p>
    </div>
</div>

<div class="important">
    <div class="title-bar"><span>Important</span></div>
    <div class="box-content">
        <p>TLP applies maximum power savings on battery power only, so unplug AC power before checking with Powertop.</p>
        <p>Powertop’s recommendations are quite schematic, they do not take into account frequently occurring problems with certain types of devices. For that reason TLP’s settings deviate from Powertop’s recommendations for a few but important exceptions:</p>
    </div>
</div>

It then looks like this:

Maybe @chrillek and @BLUEFROG as CSS and markdown specialists can improve my code.

1 Like

Hi vinschger,

thank you very much for your reply! This is already closer that I ever thought I would get (on my own) :+1:

And I agree if we could somehow “hide” the HTML part from the markdown it would improve the readability of the “source code”.

I will give it a try later today!

Thanks again, Cheers
Thorsten

While adding divs to a MD document works (of course), it goes a bit against the whole idea of MD, namely to facilitate the production of HTML. If you’re writing HTML in MD, what’s the point of using MD in the first place?

That makes no sense. If you write MD, HTML is a normal citizen. That’s by design. Hiding it would make the MD completely unintelligble (what would you in effect want to see instead of the HTML?).

What we’d need would be block-level attributes like Hugo’s Goldmark renderer provides. Those are not generally available with DT’s MultiMarkdown 6. Therefore, @vinschger’s solution is one of the few possibilities you have. I’d probably go with less markup, though. Something like

<div class="important">

### Important

TLP applies maximum power savings **on** battery power only, so unplug AC power **before** checking with Powertop. 

Powertop's recommendations are quite schematic, they to **not** take into account …

</div>

since there’s no point in adding a span inside a div as the only element. Here’s a (very simplistic) CSS for that:

.important {
  border-color: #ffb100; 
  background-color: #fff9e6;
}
.important h3 {
  background-color: #ffb100;
}
.important h3:before {
    content: "⚠️";
}
.important p {
  padding-left: 2em;
  padding-right: 2em;
}
.important p:first-of-type {
  padding-top: 1em;
}
.important p:last-of-type {
  padding-bottom: 1em;
}

I’ve no time right how to explain that, but if you’ve questions, I’ll try to answer them as soon as possible.

1 Like

Ok, maybe my statement was a little confusing…

What I meant with “hiding the HTML” was that you do not need to type this into the “unrendered” .md file. In my head I was thinking along the lines of “Prism.js” where you could just write

```language-bash
 # some code written in bash

and have it rendered automatically.

So the “lazy way” in this case would be like

```box-important
TLP applies maximum power savings on ...

and have it rendered like in vinschger’s solution.

Does this make more sense?

But I understood form your answer that this will not be possible.

I’m sorry, but that makes no sense either. You’re talking about code fences now, and those are limited to a set of pre-defined languages (like HTML, CSS, JavaScript). And that’s not part of MD per se, but of prism.js (in the case of DT) or another highlighter.

You can’t re-purpose code fences for something like
```box-important
`whatever
```

since box-important is not a pre-defined language. Nor can you define it (without a serious amount of work, that is). And even if you could, it would go against semantic HTML, as code blocks are for code, not for arbitrary information. The best (I think) approach would probably be an aside element (instead of a div), since that is meant to stand out from the normal text flow.

I posted a simpler solution already that avoids all but one HTML element. Just make sure to keep all the empty lines in that example, they are crucial.

1 Like

Well, thanks for bearing with me.

I understand that I just have not enough knowledge in this regard, that’s why I was asking for help. And vinschger’s approach and your improvement is already way more than I would have dreamed of getting as a reply on a weekend (or Monday morning - depending on your TZ ;-))

Thanks a lot for your feedback. I have only slightly adjusted the CSS code to my preferences (other padding, color of left margin). Wondering if @ThorstenG is happy with this :slight_smile:

.important {
  border-color: #ffb100; 
  background-color: #fff9e6;
  border-left: 5px solid #ffb100;
}
.important h3 {
  background-color: #ffb100;
  padding-top: 0.5em;
  padding-bottom: 0.5em;
  padding-left: 1em;
}
.important h3:before {
    content: "⚠️ ";
}
.important p {
  padding-left: 1em;
  padding-right: 1em;
}
.important p:first-of-type {
  padding-top: 0.5em;
}
.important p:last-of-type {
  padding-bottom: 0.5em;
}

Now it looks like this:

One recommendation to @ThorstenG You can use the text replacement feature of macos to enter this in your markdown code, e.g. by typing importantx so that this text block is inserted…

<div class="important">

### Important

text
</div>```

Yeah, that’s visually more appealing. Also better to use relative units for padding than pixels!

I forgot to mention that the choice of h3 (or ### in the markdown) is arbitrary. And from a semantic standpoint, using an aside element might be preferable over a div. That doesn’t change anything with the CSS as long as the class important is set for the aside element.

thank you! it’s really a joy to improve CSS coding with your help and feedback!

I am not sure what you mean with this statement, could you elaborate this with a short example?

Well, as I feel only “competent” to “evaluate” the aesthetic part of this: it’s perfect!.

And with the text replacement it’s even a no-brainer to use! :smiling_face_with_three_hearts:

Thank you guys so much!

Instead of

<div class="important">

### Important

First paragraph

Second paragraph

</div>

use

<aside>

# Important

first paragraph

second paragraph
…
</aside>

<div> has no semantics, so the blocks (“Important”, “Notification”, whatever) are considered to be semantically part of the normal text flow. Which they are not (why else would one want them to stand out this much?). Everything you need to know (as usual in this context) is at MDN:

This is relevant for several reasons:

  • A h3 element without a preceding h2 is not considered semantically correct
  • A screen reader might (I don’t know, though) just read out the “Important” div like any other text, which could be irritating

Also, I was wrong in assuming that one could use any heading in an aside element: The W3C examples use an h1 here, so I have modified the MD accordingly. CSS should also be modified to address h1 instead of h3 in this case.

https://www.w3.org/TR/2011/WD-html5-author-20110809/the-aside-element.html

Dear @chrillek

Maybe I have not understood you correctly,

if I use

<aside>

# Important

first paragraph

second paragraph
…
</aside>

instead of

<div class="important">

### Important

First paragraph

Second paragraph

</div>

It looks like this

Do I need to change the CSS for using aside instead of a div class?

Well…

I forgot to write <aside class="important">. My bad. The context though … never mind.

As far as I understand (and it works here…) you still need to reference the CSS style class.

So it would look like this:

<aside class="important">

### Important
</aside> 

image

1 Like

@chrillek Great, now I have understood, and it works perfectly. May I ask how you achieved this nice rounded colored margin around the whole box?

For completeness, an earlier discussion (summer '23) of admonitions in markdown.

Perhaps:

thanks…

now it looks great with this improved CSS code

.important {
  border-color: #ffb100; 
  background-color: #fff9e6;
  border-left: 5px solid #ffb100;
  border-right: 5px solid #ffb100;
  border-radius: 5px;
}
.important h3 {
  background-color: #ffb100;
  padding-top: 0.5em;
  padding-bottom: 0.5em;
  padding-left: 1em;
  color: white;
}
.important h3:before {
    content: "⚠️ ";
}
.important p {
  padding-left: 1em;
  padding-right: 1em;
}
.important p:first-of-type {
  padding-top: 0.5em;
}
.important p:last-of-type {
  padding-bottom: 0.5em;
  border-bottom: 5px solid #ffb100;
}

it looks like this

Indeed, even slightly “nicer” border margins than in @ThorstenG’s example

I’m absolutely amazed about what this thread turned into!