diff --git a/src/components/editor/markdown-renderer/markdown-it-plugins/linkify-extra.ts b/src/components/editor/markdown-renderer/markdown-it-plugins/linkify-extra.ts new file mode 100644 index 000000000..1dbd1e8d8 --- /dev/null +++ b/src/components/editor/markdown-renderer/markdown-it-plugins/linkify-extra.ts @@ -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 + } + }) +} diff --git a/src/components/editor/markdown-renderer/markdown-renderer.tsx b/src/components/editor/markdown-renderer/markdown-renderer.tsx index f55e236d0..1a2b6d3a3 100644 --- a/src/components/editor/markdown-renderer/markdown-renderer.tsx +++ b/src/components/editor/markdown-renderer/markdown-renderer.tsx @@ -20,6 +20,7 @@ import ReactHtmlParser, { convertNodeToElement, Transform } from 'react-html-par import MathJaxReact from 'react-mathjax' import { createRenderContainer, validAlertLevels } from './container-plugins/alert' 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 './markdown-renderer.scss' import { replaceGistLink } from './regex-plugins/replace-gist-link' @@ -97,6 +98,7 @@ const createMarkdownIt = ():MarkdownIt => { md.use(markdownItRegex, replaceQuoteExtraAuthor) md.use(markdownItRegex, replaceQuoteExtraColor) md.use(markdownItRegex, replaceQuoteExtraTime) + md.use(linkifyExtra) md.use(MarkdownItParserDebugger) validAlertLevels.forEach(level => { diff --git a/src/external-types/markdown-it-linkify/index.d.ts b/src/external-types/markdown-it-linkify/index.d.ts new file mode 100644 index 000000000..41e0478b6 --- /dev/null +++ b/src/external-types/markdown-it-linkify/index.d.ts @@ -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 +}