mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-23 03:27:05 -04:00
Feature/highlightjs (#242)
* Add highlighting for code blocks Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de>
This commit is contained in:
parent
b3899cd1a5
commit
e03da3bd76
10 changed files with 170 additions and 2 deletions
|
@ -0,0 +1,3 @@
|
|||
.markdown-body {
|
||||
@import '../../../../../../node_modules/highlight.js/styles/github-gist';
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
import { DomElement } from 'domhandler'
|
||||
import React, { ReactElement } from 'react'
|
||||
import { HighlightedCode } from '../../../../common/highlighted-code/highlighted-code'
|
||||
import './highlighted-code.scss'
|
||||
|
||||
const getElementReplacement = (codeNode: DomElement, index: number, counterMap: Map<string, number>): (ReactElement | undefined) => {
|
||||
if (codeNode.name !== 'code' || !codeNode.attribs || !codeNode.attribs['data-highlight-language'] || !codeNode.children || !codeNode.children[0]) {
|
||||
return
|
||||
}
|
||||
|
||||
const language = codeNode.attribs['data-highlight-language']
|
||||
const showGutter = codeNode.attribs['data-show-gutter'] !== undefined
|
||||
return <HighlightedCode key={index} language={language} showGutter={showGutter} code={codeNode.children[0].data as string}/>
|
||||
}
|
||||
|
||||
export { getElementReplacement as getHighlightedCodeBlock }
|
Loading…
Add table
Add a link
Reference in a new issue