Add a wrapper for linkify (#268)

Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de>
This commit is contained in:
mrdrogdrog 2020-06-24 23:52:45 +02:00 committed by GitHub
parent b74bb8e71d
commit cdadc7b41a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 0 deletions

View file

@ -0,0 +1,13 @@
import MarkdownIt from 'markdown-it/lib'
import linkify from 'markdown-it/lib/rules_core/linkify'
export const linkifyExtra: MarkdownIt.PluginSimple = (md) => {
md.core.ruler.push('linkify', state => {
try {
state.md.options.linkify = true
return linkify(state)
} finally {
state.md.options.linkify = false
}
})
}

View file

@ -20,6 +20,7 @@ import ReactHtmlParser, { convertNodeToElement, Transform } from 'react-html-par
import MathJaxReact from 'react-mathjax' import MathJaxReact from 'react-mathjax'
import { createRenderContainer, validAlertLevels } from './container-plugins/alert' import { createRenderContainer, validAlertLevels } from './container-plugins/alert'
import { highlightedCode } from './markdown-it-plugins/highlighted-code' import { highlightedCode } from './markdown-it-plugins/highlighted-code'
import { linkifyExtra } from './markdown-it-plugins/linkify-extra'
import { MarkdownItParserDebugger } from './markdown-it-plugins/parser-debugger' import { MarkdownItParserDebugger } from './markdown-it-plugins/parser-debugger'
import './markdown-renderer.scss' import './markdown-renderer.scss'
import { replaceGistLink } from './regex-plugins/replace-gist-link' import { replaceGistLink } from './regex-plugins/replace-gist-link'
@ -97,6 +98,7 @@ const createMarkdownIt = ():MarkdownIt => {
md.use(markdownItRegex, replaceQuoteExtraAuthor) md.use(markdownItRegex, replaceQuoteExtraAuthor)
md.use(markdownItRegex, replaceQuoteExtraColor) md.use(markdownItRegex, replaceQuoteExtraColor)
md.use(markdownItRegex, replaceQuoteExtraTime) md.use(markdownItRegex, replaceQuoteExtraTime)
md.use(linkifyExtra)
md.use(MarkdownItParserDebugger) md.use(MarkdownItParserDebugger)
validAlertLevels.forEach(level => { validAlertLevels.forEach(level => {

View file

@ -0,0 +1,6 @@
declare module 'markdown-it/lib/rules_core/linkify' {
import { RuleCore } from 'markdown-it/lib/parser_core'
const markdownItLinkify: RuleCore
export = markdownItLinkify
}