CSS snippet: Sidenote Auto-Adjust Module + four styles available

Github repository:


On how I arrived at this point:

At first I simply want a CSS snippet for sidenotes. After googling I found three ways of implementations:

  • callout block hack
  • code block hack
  • footnote hack

They all are not so “markdown-native” way. The footnote hack only works in the Live Preview mode. The callout hack cannot align the sidenote to its anchor.

Then I found Tufte CSS, which is simply <span class=xxxx></span>, a markdown-native semantic-transparent way, instead of hacks from features designed for other purposes. The downside is that inline markdown won’t render between HTML tags (except in the Reading mode). Works great for pure texts though.

But then, since Tufte designed the sidenote’s width to be 50% of the main document. In obsidian, when ‘Readable Line Length’ option is on, expanding either left- or right-panel would make the 50%-width sidenote incomplete in the visible area.

Instead of hardcoding a certain smaller suitable width value, I wrote this Sidenote Auto-Adjust Module which decides the width upon the dimension of the visible area. If possible, make it 50%. As the window’s width shrinks, at some point switch to 50% x 75%. Later on, 50% x 50%, which is extremely narrow for a sidenote. If the available spaces are smaller than that, switch to the “intrusive” layout.

Besides the Tufte <span> style, I later accepted the callout hack and make it Tufte-like. Then I also embraced the callout skeuomorphic “stickynote”-like fashion and designed syntaxes for them. Then I thought, maybe I should refactor it, so there comes the Module + the styles.

The Module.css and the style.css can be merged into one file, if you don’t mind the keyword conflict between my sidenote styles and the styles written by other people.

At last, I also made it compatible with the Minimal theme (and its ‘wide’, ‘max’ helper-classes), and introduced the ‘leftsided’ / ‘rightsided’ feature, and created templates for quick insert.

5 Likes

I’m a complete novice --even though I have been using Obsidian for 3-4 months now. I love the css, than you so much! It really helps. Is it possible to convert these sidetones into proper footnotes? I like to see my footnotes as sidetones when drafting things but exporting the draft for publication elsewhere almost always requires a regular footnotes at the bottom format, for me.

I’m afraid not… From the markdown “source code” point of view, the inline tag <span class=sidenote>This is a sidenote.</span> is a totally different beast (semantically) compared to the traditional footnote code [^1]: This is a footnote line at the end of the document.

BUT, you may use a text editor (or Obsidian itself) which supports RegExp search & replace. Just replace <span class=sidenote>([^<]*)</span> to ^[\1] , then you’ll get a new markdown document with the proper inline-footnote syntax, e.g. ^[This is a sidenote.] (actually it’s a footnote syntax). Editors like Obsidian will display those footnotes at the bottom of the document (and auto-numbered).

OR, you may choose to adopt other work-arounds that use CSS to display inline-footnote codes (e.g. ^[This is a sidenote.]) as sidenotes. (Those are still footnotes from the “source code” point of view, so that when you turn off those CSS, they’ll be displayed as footnotes by default.)