Hi all, I’ve been wondering for a while how to write custom CSS to render transclusions without titles, and especially without headers if linking to a section in a note. There used to be a thread on this forum, but it’s been closed, and none of the solutions there were working anymore.
So today, I’ve finally figured out how to do it properly, including making sure that only the first heading or the title are hidden, but other headings are still visible.
As a bonus, this CSS also displays the source file (and section) in small, grey font at the top, so you know where clicking the link will lead you. If you’re not into that, just remove the corresponding sections from the CSS.
/* disable title */
.markdown-embed-title {
display: none;
}
/* Disable the first header in the embed (which is the third div), but only if this
isn't an embed of a complete node (which can be detected through checking whether the
title is empty). */
.markdown-embed-title:empty~.markdown-embed-content .markdown-preview-view .markdown-preview-sizer div:nth-child(3) :is(h1, h2, h3, h4, h5, h6) {
display: none;
}
/* show the source in small, grey font at the top */
.markdown-embed::before {
content: attr(alt);
display: block;
font-size: var(--font-smallest);
color: var(--text-muted);
}
/* change the link background so it's occludes the text when it overlays the source */
.markdown-embed-link {
background: var(--color-base-00);
opacity: 1;
}
.markdown-embed-link:hover {
background: var(--color-base-25);
opacity: 1;
}
And here’s a test, embedding parts of this file
in another file:
That’s it, have fun!
And BTW, if anyone figures out how to reduce the spacing before/after transclusions, let me know!