Fix counter continue in highlighted-fence-replacer.tsx (#943)

Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de>
This commit is contained in:
Tilman Vatteroth 2021-01-13 11:52:06 +01:00 committed by GitHub
parent 7be64bc582
commit 9f6b1a9a46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 197 additions and 117 deletions

View file

@ -26,26 +26,31 @@
display: grid;
grid-template-columns: auto minmax(0, 1fr);
.codeline {
grid-column: 2;
white-space: nowrap;
}
.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 {
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;
display: flex;
align-items: flex-end;
&:before {
content: attr(data-line-number);
}
}
}

View file

@ -41,7 +41,9 @@ export const HighlightedCode: React.FC<HighlightedCodeProps> = ({ code, language
const unreplacedCode = !!language && languageSupported(language) ? hljs.default.highlight(language, code).value : escapeHtml(code)
const replacedDom = replaceCode(unreplacedCode).map((line, index) => (
<Fragment key={index}>
<span className={'linenumber'} data-line-number={(startLineNumber || 1) + index}/>
<span className={'linenumber'}>
{ (startLineNumber || 1) + index }
</span>
<div className={'codeline'}>
{line}
</div>

View file

@ -19,7 +19,7 @@ export class HighlightedCodeReplacer extends ComponentReplacer {
const language = codeNode.attribs['data-highlight-language']
const extraData = codeNode.attribs['data-extra']
const extraInfos = /(=(\d*|\+))?(!?)/.exec(extraData)
const extraInfos = /(=(\d+|\+)?)?(!?)/.exec(extraData)
let showLineNumbers = false
let startLineNumberAttribute = ''