From fc87ba9253bd1d6e050e009be2051ba86cca27ce Mon Sep 17 00:00:00 2001 From: fredck Date: Wed, 29 Jan 2020 18:06:04 +0100 Subject: [PATCH] For the purpose of this plugin, autolinking from markdown to html is wrong. --- src/markdown2html/markdown2html.js | 6 ++++ tests/gfmdataprocessor/links.js | 45 ++++++++---------------------- 2 files changed, 17 insertions(+), 34 deletions(-) diff --git a/src/markdown2html/markdown2html.js b/src/markdown2html/markdown2html.js index da96116..a455f57 100644 --- a/src/markdown2html/markdown2html.js +++ b/src/markdown2html/markdown2html.js @@ -14,3 +14,9 @@ export default function markdown2html( markdown ) { headerIds: false } ); } + +// Overrides. + +// Disable the autolink rule in the lexer (point it to a regex that always fail). +marked.InlineLexer.rules.breaks.autolink = /^\b$/; +marked.InlineLexer.rules.breaks.url = /^\b$/; diff --git a/tests/gfmdataprocessor/links.js b/tests/gfmdataprocessor/links.js index 0c5f250..32af660 100644 --- a/tests/gfmdataprocessor/links.js +++ b/tests/gfmdataprocessor/links.js @@ -7,57 +7,34 @@ import { testDataProcessor as test } from '../../tests/_utils/utils'; describe( 'GFMDataProcessor', () => { describe( 'links', () => { - it( 'should autolink', () => { - test( - 'Link: .', - '

Link: http://example.com/.

', - - // When converting back it will be represented as standard markdown link. - 'Link: [http://example.com/](http://example.com/).' - ); - } ); - - it( 'should autolink #2', () => { + it( 'should not autolink', () => { test( 'Link: http://example.com/.', - '

Link: http://example.com/.

', - - // When converting back it will be represented as standard markdown link. - 'Link: [http://example.com/](http://example.com/).' + '

Link: http://example.com/.

' ); } ); - it( 'should autolink with params', () => { + it( 'should not autolink with params', () => { test( - 'Link: .', - '

Link: http://example.com/?foo=1&bar=2.

', - - // When converting back it will be represented as standard markdown link. - 'Link: [http://example.com/?foo=1&bar=2](http://example.com/?foo=1&bar=2).' + 'Link: http://example.com/?foo=1&bar=2.', + '

Link: http://example.com/?foo=1&bar=2.

' ); } ); - it( 'should autolink inside list', () => { + it( 'should not autolink inside list', () => { test( - '* ', - - '', - - // When converting back it will be represented as standard markdown link. - '* [http://example.com/](http://example.com/)' + '* http://example.com/', + '
  • http://example.com/
', ); } ); - it( 'should autolink inside blockquote', () => { + it( 'should not autolink inside blockquote', () => { test( - '> Blockquoted: ', + '> Blockquoted: http://example.com/', '
' + - '

Blockquoted: http://example.com/

' + + '

Blockquoted: http://example.com/

' + '
', - - // When converting back it will be represented as standard markdown link. - '> Blockquoted: [http://example.com/](http://example.com/)' ); } );