diff --git a/browser/components/markdown.styl b/browser/components/markdown.styl index 4921b531d..7a15a744b 100644 --- a/browser/components/markdown.styl +++ b/browser/components/markdown.styl @@ -444,6 +444,44 @@ pre.fence color $ui-text-color background-color $ui-tag-backgroundColor +.markdownIt-TOC-wrapper + list-style none + position fixed + right 0 + top 0 + margin-left 15px + z-index 1000 + transition transform .2s ease-in-out + transform translateX(100%) + + .markdownIt-TOC + display block + max-height 90vh + overflow-y auto + padding 25px + padding-left 38px + + &, + &:before + background-color $ui-dark-backgroundColor + color: $ui-dark-text-color + + &:hover + transform translateX(-15px) + + &:before + content 'TOC' + position absolute + width 60px + height 30px + top 60px + left -29px + display flex + align-items center + justify-content center + transform-origin top left + transform rotate(-90deg) + themeDarkBackground = darken(#21252B, 10%) themeDarkText = #f9f9f9 themeDarkBorder = lighten(themeDarkBackground, 20%) @@ -511,6 +549,14 @@ body[data-theme="dark"] color $ui-dark-text-color background-color $ui-dark-tag-backgroundColor + .markdownIt-TOC-wrapper + &, + &:before + background-color darken(themeDarkBackground, 5%) + color themeDarkText + + +themeSolarizedDarkBackground = $ui-solarized-dark-noteDetail-backgroundColor themeSolarizedDarkTableOdd = $ui-solarized-dark-noteDetail-backgroundColor themeSolarizedDarkTableEven = darken($ui-solarized-dark-noteDetail-backgroundColor, 10%) themeSolarizedDarkTableHead = themeSolarizedDarkTableEven @@ -519,7 +565,7 @@ themeSolarizedDarkTableBorder = themeDarkBorder body[data-theme="solarized-dark"] color $ui-solarized-dark-text-color border-color themeDarkBorder - background-color $ui-solarized-dark-noteDetail-backgroundColor + background-color themeSolarizedDarkBackground table thead tr @@ -554,6 +600,13 @@ body[data-theme="solarized-dark"] color $ui-solarized-dark-button--active-color background-color $ui-solarized-dark-button-backgroundColor + .markdownIt-TOC-wrapper + &, + &:before + background-color darken(themeSolarizedDarkBackground, 15%) + color themeDarkText + +themeMonokaiBackground = $ui-monokai-noteDetail-backgroundColor themeMonokaiTableOdd = $ui-monokai-noteDetail-backgroundColor themeMonokaiTableEven = darken($ui-monokai-noteDetail-backgroundColor, 10%) themeMonokaiTableHead = themeMonokaiTableEven @@ -562,7 +615,7 @@ themeMonokaiTableBorder = themeDarkBorder body[data-theme="monokai"] color $ui-monokai-text-color border-color themeDarkBorder - background-color $ui-monokai-noteDetail-backgroundColor + background-color themeMonokaiBackground table thead tr @@ -600,6 +653,13 @@ body[data-theme="monokai"] color $ui-monokai-button--active-color background-color $ui-monokai-button-backgroundColor + .markdownIt-TOC-wrapper + &, + &:before + background-color darken(themeMonokaiBackground, 15%) + color themeDarkText + +themeDraculaBackground = $ui-dracula-noteDetail-backgroundColor themeDraculaTableOdd = $ui-dracula-noteDetail-backgroundColor themeDraculaTableEven = darken($ui-dracula-noteDetail-backgroundColor, 10%) themeDraculaTableHead = themeDraculaTableEven @@ -608,7 +668,7 @@ themeDraculaTableBorder = themeDarkBorder body[data-theme="dracula"] color $ui-dracula-text-color border-color themeDarkBorder - background-color $ui-dracula-noteDetail-backgroundColor + background-color themeDraculaBackground table thead tr @@ -645,3 +705,9 @@ body[data-theme="dracula"] .prev, .next color $ui-dracula-button--active-color background-color $ui-dracula-button-backgroundColor + + .markdownIt-TOC-wrapper + &, + &:before + background-color darken(themeDraculaBackground, 15%) + color themeDarkText diff --git a/browser/lib/markdown.js b/browser/lib/markdown.js index 57f981db2..d9b98a36b 100644 --- a/browser/lib/markdown.js +++ b/browser/lib/markdown.js @@ -128,12 +128,19 @@ class Markdown { this.md.use(require('markdown-it-abbr')) this.md.use(require('markdown-it-sub')) this.md.use(require('markdown-it-sup')) - this.md.use(markdownItTocAndAnchor, { - toc: true, - tocPattern: /\[TOC\]/i, - anchorLink: false, - appendIdToHeading: false + + this.md.use(md => { + markdownItTocAndAnchor(md, { + toc: true, + tocPattern: /\[TOC\]/i, + anchorLink: false, + appendIdToHeading: false + }) + + md.renderer.rules.toc_open = () => '
' + md.renderer.rules.toc_close = () => '
' }) + this.md.use(require('./markdown-it-deflist')) this.md.use(require('./markdown-it-frontmatter')) diff --git a/tests/lib/snapshots/markdown-test.js.md b/tests/lib/snapshots/markdown-test.js.md index 1ebc0275e..37976ef10 100644 --- a/tests/lib/snapshots/markdown-test.js.md +++ b/tests/lib/snapshots/markdown-test.js.md @@ -87,7 +87,7 @@ Generated by [AVA](https://ava.li). > Snapshot 1 - `