From 17525a4f418f80f17b67f2d31462378d1c7250bb Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Mon, 20 Feb 2023 21:35:00 +1300 Subject: [PATCH 1/7] Add renderer option to HTML blocks in Markdown --- shared/naturalcrit/markdown.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/naturalcrit/markdown.js b/shared/naturalcrit/markdown.js index 8dbb1d7f9..be360dccd 100644 --- a/shared/naturalcrit/markdown.js +++ b/shared/naturalcrit/markdown.js @@ -10,7 +10,7 @@ renderer.html = function (html) { const openTag = html.substring(0, html.indexOf('>')+1); html = html.substring(html.indexOf('>')+1); html = html.substring(0, html.lastIndexOf('')); - return `${openTag} ${Marked.parse(html)} `; + return `${openTag} ${Marked.parse(html, { renderer: renderer })} `; } return html; }; From a65c26e806358228bdf49ac765ede5790701c3df Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Mon, 20 Feb 2023 21:35:12 +1300 Subject: [PATCH 2/7] Increase Jest timeout --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ced80d651..225913478 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "build/*" ], "jest": { - "testTimeout": 15000, + "testTimeout": 30000, "modulePaths": [ "mode_modules", "shared", From 9eb8653dfb5b23b4f8008ddf8fe6ecf8646f02e4 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Mon, 20 Feb 2023 21:35:53 +1300 Subject: [PATCH 3/7] Add info to the change log --- changelog.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/changelog.md b/changelog.md index 10899a485..cb2e3b825 100644 --- a/changelog.md +++ b/changelog.md @@ -61,6 +61,15 @@ pre { ## changelog For a full record of development, visit our [Github Page](https://github.com/naturalcrit/homebrewery). +### Tuesday 21/02/2023 - v3.6.1 +{{taskList +##### G-Ambatte + +* [x] Fix internal links inside `
` blocks not automatically receiving the `target=_self` attribute + +Fixes issues [#2680](https://github.com/naturalcrit/homebrewery/issues/2680) +}} + ### Saturday 18/02/2023 - v3.6.1 {{taskList ##### G-Ambatte From f528b5522642da5fd116bd2aa07254a91d0de492 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Tue, 21 Feb 2023 07:42:38 +1300 Subject: [PATCH 4/7] Move renderer assignment to options --- shared/naturalcrit/markdown.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared/naturalcrit/markdown.js b/shared/naturalcrit/markdown.js index be360dccd..b209bf90d 100644 --- a/shared/naturalcrit/markdown.js +++ b/shared/naturalcrit/markdown.js @@ -10,7 +10,7 @@ renderer.html = function (html) { const openTag = html.substring(0, html.indexOf('>')+1); html = html.substring(html.indexOf('>')+1); html = html.substring(0, html.lastIndexOf('
')); - return `${openTag} ${Marked.parse(html, { renderer: renderer })} `; + return `${openTag} ${Marked.parse(html)} `; } return html; }; @@ -239,7 +239,7 @@ const definitionLists = { Marked.use({ extensions: [mustacheSpans, mustacheDivs, mustacheInjectInline, definitionLists] }); Marked.use(MarkedExtendedTables()); Marked.use(mustacheInjectBlock); -Marked.use({ smartypants: true }); +Marked.use({ renderer: renderer, smartypants: true }); //Fix local links in the Preview iFrame to link inside the frame renderer.link = function (href, title, text) { From 4484035d750ff2c74a09b8cf5fa6c7daf830434b Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Tue, 21 Feb 2023 07:51:18 +1300 Subject: [PATCH 5/7] Add Markdown test --- tests/markdown/basic.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/markdown/basic.test.js b/tests/markdown/basic.test.js index 174e43d7e..459bb22c4 100644 --- a/tests/markdown/basic.test.js +++ b/tests/markdown/basic.test.js @@ -13,3 +13,9 @@ test('Processes the markdown within an HTML block if its just a class wrapper', const rendered = Markdown.render(source); expect(rendered).toBe('

Bold text

\n
'); }); + +test('Check markdown is using the custom renderer; specifically that it adds target=_self attribute to internal links in HTML blocks', function() { + const source = '
[Has _self Attribute?](#p1)
'; + const rendered = Markdown.render(source); + expect(rendered).toBe('

Has _self Attribute?

\n
'); +}); From 81f0670be027b3bc0409cf7e33b074417aefb334 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Tue, 21 Feb 2023 08:15:33 +1300 Subject: [PATCH 6/7] Fix minor version number --- changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index cb2e3b825..9feb6d448 100644 --- a/changelog.md +++ b/changelog.md @@ -61,7 +61,7 @@ pre { ## changelog For a full record of development, visit our [Github Page](https://github.com/naturalcrit/homebrewery). -### Tuesday 21/02/2023 - v3.6.1 +### Tuesday 21/02/2023 - v3.6.2 {{taskList ##### G-Ambatte From c41b06eee1c598596387e526879bd2a37723d33c Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Thu, 23 Mar 2023 12:03:30 -0400 Subject: [PATCH 7/7] Remove duplicate renderer on Marked.parse call --- shared/naturalcrit/markdown.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/shared/naturalcrit/markdown.js b/shared/naturalcrit/markdown.js index b209bf90d..16623b8a5 100644 --- a/shared/naturalcrit/markdown.js +++ b/shared/naturalcrit/markdown.js @@ -347,10 +347,7 @@ module.exports = { render : (rawBrewText)=>{ rawBrewText = rawBrewText.replace(/^\\column$/gm, `\n
\n`) .replace(/^(:+)$/gm, (match)=>`${`
`.repeat(match.length)}\n`); - return Marked.parse( - sanatizeScriptTags(rawBrewText), - { renderer: renderer } - ); + return Marked.parse(sanatizeScriptTags(rawBrewText)); }, validate : (rawBrewText)=>{