diff --git a/cypress/integration/autocompletion.spec.ts b/cypress/integration/autocompletion.spec.ts index 9fe5cb55a..285d7153b 100644 --- a/cypress/integration/autocompletion.spec.ts +++ b/cypress/integration/autocompletion.spec.ts @@ -26,9 +26,7 @@ describe('Autocompletion', () => { .should('have.text', '```abnf') cy.get('.CodeMirror-code > div:nth-of-type(3) > .CodeMirror-line > span span') .should('have.text', '```') - cy.getMarkdownBody() - .find('pre > code') - .should('exist') + cy.getMarkdownBody().find('.code-highlighter').should('exist') }) it('via doubleclick', () => { cy.codemirrorFill('```') @@ -41,9 +39,7 @@ describe('Autocompletion', () => { .should('have.text', '```abnf') cy.get('.CodeMirror-code > div:nth-of-type(3) > .CodeMirror-line > span span') .should('have.text', '```') - cy.getMarkdownBody() - .find('pre > code') - .should('exist') + cy.getMarkdownBody().find('.code-highlighter').should('exist') }) }) diff --git a/cypress/integration/highlightedCodeBlock.spec.ts b/cypress/integration/highlightedCodeBlock.spec.ts index ecc3463c2..b3b1b1468 100644 --- a/cypress/integration/highlightedCodeBlock.spec.ts +++ b/cypress/integration/highlightedCodeBlock.spec.ts @@ -5,9 +5,7 @@ */ const findHljsCodeBlock = () => { - return cy.getMarkdownBody() - .find('pre > code.hljs') - .should('be.visible') + return cy.getMarkdownBody().find('.code-highlighter > code.hljs').should('be.visible') } describe('Code', () => { diff --git a/src/components/markdown-renderer/replace-components/highlighted-fence/highlighted-code/highlighted-code.scss b/src/components/markdown-renderer/replace-components/highlighted-fence/highlighted-code/highlighted-code.scss index b1198da16..fda62b852 100644 --- a/src/components/markdown-renderer/replace-components/highlighted-fence/highlighted-code/highlighted-code.scss +++ b/src/components/markdown-renderer/replace-components/highlighted-fence/highlighted-code/highlighted-code.scss @@ -4,62 +4,60 @@ * SPDX-License-Identifier: AGPL-3.0-only */ -.markdown-body { +.code-highlighter { @import '../../../../../../node_modules/highlight.js/styles/github'; body.dark & { @import '../../../../../../node_modules/highlight.js/styles/github-dark'; } - pre, & { - code.hljs { - overflow-x: auto; - background-color: rgba(27, 31, 35, .05); + code.hljs { + overflow-x: auto; + background-color: rgba(27, 31, 35, .05); - body.dark & { - background-color: rgb(27, 31, 35); + body.dark & { + background-color: rgb(27, 31, 35); + } + + body.dark &, & { + padding: 16px; + display: grid; + grid-template-columns: auto minmax(0, 1fr); + + .codeline { + grid-column: 2; + white-space: pre; } - body.dark &, & { - padding: 16px; - display: grid; - grid-template-columns: auto minmax(0, 1fr); - - .codeline { - grid-column: 2; - white-space: pre; - } + .linenumber { + grid-column: 1; + position: relative; + cursor: default; + z-index: 4; + padding: 0 8px 0 0; + min-width: 20px; + box-sizing: content-box; + color: #afafaf; + border-right: 3px solid #6ce26c; + flex-direction: column; + overflow: hidden; + user-select: none; + align-items: flex-end; + display: none; + } + &.showGutter { .linenumber { - grid-column: 1; - position: relative; - cursor: default; - z-index: 4; - padding: 0 8px 0 0; - min-width: 20px; - box-sizing: content-box; - color: #afafaf; - border-right: 3px solid #6ce26c; - flex-direction: column; - overflow: hidden; - user-select: none; - align-items: flex-end; - display: none; + display: flex; } + } - &.showGutter { - .linenumber { - display: flex; - } - } + &.showGutter .codeline { + margin: 0 0 0 16px; + } - &.showGutter .codeline { - margin: 0 0 0 16px; - } - - &.wrapLines .codeline { - white-space: pre-wrap; - } + &.wrapLines .codeline { + white-space: pre-wrap; } } } diff --git a/src/components/markdown-renderer/replace-components/highlighted-fence/highlighted-code/highlighted-code.tsx b/src/components/markdown-renderer/replace-components/highlighted-fence/highlighted-code/highlighted-code.tsx index f3641fd74..a136b15a2 100644 --- a/src/components/markdown-renderer/replace-components/highlighted-fence/highlighted-code/highlighted-code.tsx +++ b/src/components/markdown-renderer/replace-components/highlighted-fence/highlighted-code/highlighted-code.tsx @@ -61,14 +61,14 @@ export const HighlightedCode: React.FC = ({ code, language }, [code, language, startLineNumber]) return ( - +
{dom}
- +
) }