From 43f4539db118273d9baff7dfe23b4238d3eda82e Mon Sep 17 00:00:00 2001 From: zzzzBov Date: Mon, 1 Apr 2024 00:02:28 -0400 Subject: [PATCH] fix: split metadata key-value pairs on first colon instead of last --- src/subParsers/makehtml/metadata.js | 2 +- test/unit/showdown.Converter.makeHtml.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/subParsers/makehtml/metadata.js b/src/subParsers/makehtml/metadata.js index 8b151762..f1ed3f8f 100644 --- a/src/subParsers/makehtml/metadata.js +++ b/src/subParsers/makehtml/metadata.js @@ -66,7 +66,7 @@ showdown.subParser('makehtml.metadata', function (text, options, globals) { // replace multiple spaces .replace(/\n {4}/g, ' '); - content.replace(/^([\S ]+): +([\s\S]+?)$/gm, function (wm, key, value) { + content.replace(/^([\S ]+?): +([\s\S]+?)$/gm, function (wm, key, value) { globals.metadata.parsed[key] = value; return ''; }); diff --git a/test/unit/showdown.Converter.makeHtml.js b/test/unit/showdown.Converter.makeHtml.js index 4715ac46..306c4faf 100644 --- a/test/unit/showdown.Converter.makeHtml.js +++ b/test/unit/showdown.Converter.makeHtml.js @@ -64,6 +64,7 @@ describe('showdown.Converter', function () { '---SIMPLE\n' + 'foo: bar\n' + 'baz: bazinga\n' + + 'lorem: ipsum: dolor\n' + '---\n', text2 = '---TIVIE\n' + @@ -75,8 +76,8 @@ describe('showdown.Converter', function () { converter.setOption('metadata', true); let expectedHtml = '', - expectedObj = {foo: 'bar', baz: 'bazinga'}, - expectedRaw = 'foo: bar\nbaz: bazinga', + expectedObj = {foo: 'bar', baz: 'bazinga', lorem: 'ipsum: dolor'}, + expectedRaw = 'foo: bar\nbaz: bazinga\nlorem: ipsum: dolor', expectedFormat = 'SIMPLE'; converter.makeHtml(text1).should.equal(expectedHtml); converter.getMetadata().should.eql(expectedObj);