Skip to content

Instantly share code, notes, and snippets.

@claudioluciano
Last active December 1, 2024 18:45
Show Gist options
  • Save claudioluciano/1c108c5fe7804d3ff393f27667d84971 to your computer and use it in GitHub Desktop.
Save claudioluciano/1c108c5fe7804d3ff393f27667d84971 to your computer and use it in GitHub Desktop.
Obsidian - snippet to create spoilers on notes
:root {
--spoiler-bg-color: rgb(23, 23, 26);
--spoiler-border-radius: 2px;
--spoiler-transition-duration: 0.3s;
--spoiler-transition-timing: ease-in-out;
}
/* Document */
/* Hide the checkbox */
[data-task="#"]>label {
display: none;
}
/* Spoiler when the line is not active */
[data-task="#"]:not(.cm-active)>.cm-list-1::before {
content: ' ';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: var(--spoiler-bg-color);
border-radius: var(--spoiler-border-radius);
transition: opacity var(--spoiler-transition-duration) var(--spoiler-transition-timing);
}
/* Reveal when hovering and the line is not active */
[data-task="#"]:hover:not(.cm-active)>.cm-list-1::before {
opacity: 0;
}
/* Popover */
/* Hide the checkbox */
.popover [data-task="#"]>input[type="checkbox"] {
display: none;
}
/* Remove the margin on the left of the spoiler */
.popover [data-task="#"] {
margin-inline-start: initial;
}
/* Spoiler the line */
.popover [data-task="#"]::before {
content: ' ';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: var(--spoiler-bg-color);
border-radius: var(--spoiler-border-radius);
transition: opacity var(--spoiler-transition-duration) var(--spoiler-transition-timing);
}
/* Reveal when hovering */
.popover [data-task="#"]:hover::before {
opacity: 0;
}
@claudioluciano
Copy link
Author

claudioluciano commented Apr 10, 2024

This code is based on this reddit comment

- [#] test

*** For now, it's not work in callout or other blocks

show.mov

@ErisEve
Copy link

ErisEve commented Nov 30, 2024

Works like charm, but has a bug where if the text flows over the end of the line, it shows a little of the text at the end.
image
The blocking box shrinks when I change the size of the window.
image
image

Edit: Now i realize that it tries to block both lines and if the lines are uneven, it blocks till the end of the second line, that's why the first line overflows.

@claudioluciano
Copy link
Author

claudioluciano commented Nov 30, 2024

Works like charm, but has a bug where if the text flows over the end of the line, it shows a little of the text at the end. image The blocking box shrinks when I change the size of the window. image image

Edit: Now i realize that it tries to block both lines and if the lines are uneven, it blocks till the end of the second line, that's why the first line overflows.

Hi there! I’ve made some updates to the snippet to fix this bug and added a smooth transition.

@ErisEve
Copy link

ErisEve commented Dec 1, 2024

Tested it out, it's perfect!
Now the only problem stays is that when I hover a link to a file with a spoiler tag, the tags show up as checked checkbox, and not a spoiler!
image

@claudioluciano
Copy link
Author

Tested it out, it's perfect! Now the only problem stays is that when I hover a link to a file with a spoiler tag, the tags show up as checked checkbox, and not a spoiler! image

Hey, i've update the snippet to cover the popover when you hover a link to another file. (:

@ErisEve
Copy link

ErisEve commented Dec 1, 2024

You're the most dedicated man alive
Thank you sir, would've given it thousands stars if I found out a glitch how lmao
Have a good day !! :))

@claudioluciano
Copy link
Author

You're the most dedicated man alive Thank you sir, would've given it thousands stars if I found out a glitch how lmao Have a good day !! :))

Thanks man, I'm glad you liked it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment