From ecd20837450395a305928b8831f1eed98b358445 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 15 Dec 2022 19:28:48 +0000 Subject: [PATCH] Handle blockquotes & empty paragraphs (#16019) refs: https://github.com/TryGhost/Ghost/commit/5f90baf6fe3bd9b9acdcc418a0e21389084030ee - Blockquotes without any wrapping tag get converted to Mobiledoc weirdly. Wrapping them in `

` tags helps solve that - Also removes empty paragraph tags which cause unwanted large blank spaces in content - Remove internal #revue from Revue content --- ghost/importer-revue/lib/importer-revue.js | 8 +++---- ghost/importer-revue/lib/json-to-html.js | 14 ++++++++++- .../test/importer-revue.test.js | 23 +++++++++++++------ 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/ghost/importer-revue/lib/importer-revue.js b/ghost/importer-revue/lib/importer-revue.js index bf1f3fb549..fa98c2ca48 100644 --- a/ghost/importer-revue/lib/importer-revue.js +++ b/ghost/importer-revue/lib/importer-revue.js @@ -33,14 +33,14 @@ const fetchPostsFromData = (revueData) => { } const revuePostID = postMeta.id; - let postHTML = postMeta.description; + let postHTML = JSONToHTML.cleanCsvHTML(postMeta.description); const postItems = _.filter(itemData, {issue_id: revuePostID}); const sortedPostItems = _.sortBy(postItems, o => o.order); if (postItems) { const convertedItems = JSONToHTML.itemsToHtml(sortedPostItems); - postHTML = `${postMeta.description}${convertedItems}`; + postHTML = `${postHTML}${convertedItems}`; } const postDate = JSONToHTML.getPostDate(postMeta); @@ -54,9 +54,7 @@ const fetchPostsFromData = (revueData) => { created_at: postDate, published_at: postDate, updated_at: postDate, - html: postHTML, - tags: ['#revue'] - + html: postHTML }); }); diff --git a/ghost/importer-revue/lib/json-to-html.js b/ghost/importer-revue/lib/json-to-html.js index 2c5b8fbac3..cc126323ac 100644 --- a/ghost/importer-revue/lib/json-to-html.js +++ b/ghost/importer-revue/lib/json-to-html.js @@ -88,8 +88,20 @@ const getPostStatus = (data) => { return (isPublished) ? 'published' : 'draft'; }; +const cleanCsvHTML = (data) => { + // Blockquotes need to have some sort of wrapping elements around all contents + // Wrap all content in

tags. The HTML to Mobiledoc parse can handle duplicate

tags. + data = data.replace(/(.*?)<\/blockquote>/gm, '

$1

'); + + // These exports have a lot of


that we don't want + data = data.replace(/


<\/p>/gm, ''); + + return data; +}; + module.exports = { itemsToHtml, getPostDate, - getPostStatus + getPostStatus, + cleanCsvHTML }; diff --git a/ghost/importer-revue/test/importer-revue.test.js b/ghost/importer-revue/test/importer-revue.test.js index b37363b689..169d868bd0 100644 --- a/ghost/importer-revue/test/importer-revue.test.js +++ b/ghost/importer-revue/test/importer-revue.test.js @@ -68,8 +68,7 @@ describe('Revue Importer', function () { created_at: '2022-12-01T01:01:30.000Z', published_at: '2022-12-01T01:01:30.000Z', updated_at: '2022-12-01T01:01:30.000Z', - html: '

Hello World!

', - tags: ['#revue'] + html: '

Hello World!

' } ]); }); @@ -88,9 +87,6 @@ describe('Revue Importer', function () { html: '

Hello World!

Goodbye World!

', published_at: '2022-12-01T01:01:30.000Z', status: 'published', - tags: [ - '#revue' - ], title: 'Hello World - Issue #8', slug: 'hello-world-issue-8', updated_at: '2022-12-01T01:01:30.000Z', @@ -113,8 +109,7 @@ describe('Revue Importer', function () { created_at: '2022-12-01T01:02:03.123Z', published_at: '2022-12-01T01:02:03.123Z', updated_at: '2022-12-01T01:02:03.123Z', - html: '

Hello World!

Goodbye World!

', - tags: ['#revue'] + html: '

Hello World!

Goodbye World!

' } ]); }); @@ -223,5 +218,19 @@ describe('Revue Importer', function () { assert.deepEqual(result, '
Hello world
'); }); }); + + describe('cleanCsvHTML', function () { + it('can wrap blockquote content in p tags', function () { + const result = JSONToHTML.cleanCsvHTML('

Hello World!

Try This!
'); + + assert.deepEqual(result, '

Hello World!

Try This!

'); + }); + + it('can remove unwanted blank paragraphs', function () { + const result = JSONToHTML.cleanCsvHTML('

Hello World!


Goodbye World!

'); + + assert.deepEqual(result, '

Hello World!

Goodbye World!

'); + }); + }); }); });