diff --git a/changelog.md b/changelog.md index afe3034dc..aed9390c7 100644 --- a/changelog.md +++ b/changelog.md @@ -80,6 +80,15 @@ pre { ## changelog For a full record of development, visit our [Github Page](https://github.com/naturalcrit/homebrewery). +### XXXXday DD/MM/2023 - v3.8.0 +{{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) +}} + ### Monday 13/03/2023 - v3.7.2 {{taskList diff --git a/shared/naturalcrit/markdown.js b/shared/naturalcrit/markdown.js index 8dbb1d7f9..16623b8a5 100644 --- a/shared/naturalcrit/markdown.js +++ b/shared/naturalcrit/markdown.js @@ -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) { @@ -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)=>{ 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
'); +});