Skip to content

Instantly share code, notes, and snippets.

@m0rtyn
Last active January 24, 2024 18:28
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m0rtyn/96f4b9b657ae1103bca69f3572490d5e to your computer and use it in GitHub Desktop.
Save m0rtyn/96f4b9b657ae1103bca69f3572490d5e to your computer and use it in GitHub Desktop.
obsidian-fix-for-nested-code-blocks.css

Fix for codeblocks nested in list items in Obsidian app

Result: image

.HyperMD-codeblock {
  --code-background: #0003;
}

.HyperMD-list-line-nobullet ~ .HyperMD-codeblock:has(.cm-indent) {
  margin-left: 3em !important;
  background-color: var(--code-background) !important;
}

.HyperMD-list-line-nobullet ~ .HyperMD-codeblock .cm-indent:first-child {
  display: none !important;
}

.HyperMD-codeblock.HyperMD-codeblock-begin.HyperMD-codeblock-begin.HyperMD-codeblock-begin,
.HyperMD-codeblock.HyperMD-codeblock-end.HyperMD-codeblock-end.HyperMD-codeblock-end {
  padding-top: 0 !important;
  padding-bottom: 0.3em !important;
  line-height: 0.8em !important;
  background-color: transparent !important;
}

.HyperMD-codeblock.HyperMD-codeblock-begin.HyperMD-codeblock-begin.HyperMD-codeblock-begin .cm-formatting,
.HyperMD-codeblock.HyperMD-codeblock-end.HyperMD-codeblock-end.HyperMD-codeblock-end .cm-formatting {
  font-size: 0.65em !important;
}

.HyperMD-codeblock-begin + .HyperMD-codeblock {
  border-radius: 1rem 1rem 0 0 !important;
}

.HyperMD-codeblock:has(+ .HyperMD-codeblock-end) {
  border-radius: 0 0 1rem 1rem !important;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment