mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Handle blockquotes & empty paragraphs (#16019)
refs: 5f90baf6fe
- Blockquotes without any wrapping tag get converted to Mobiledoc weirdly. Wrapping them in `<p>` tags helps solve that
- Also removes empty paragraph tags which cause unwanted large blank spaces in content
- Remove internal #revue from Revue content
This commit is contained in:
parent
5f90baf6fe
commit
ecd2083745
3 changed files with 32 additions and 13 deletions
|
@ -33,14 +33,14 @@ const fetchPostsFromData = (revueData) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const revuePostID = postMeta.id;
|
const revuePostID = postMeta.id;
|
||||||
let postHTML = postMeta.description;
|
let postHTML = JSONToHTML.cleanCsvHTML(postMeta.description);
|
||||||
|
|
||||||
const postItems = _.filter(itemData, {issue_id: revuePostID});
|
const postItems = _.filter(itemData, {issue_id: revuePostID});
|
||||||
const sortedPostItems = _.sortBy(postItems, o => o.order);
|
const sortedPostItems = _.sortBy(postItems, o => o.order);
|
||||||
|
|
||||||
if (postItems) {
|
if (postItems) {
|
||||||
const convertedItems = JSONToHTML.itemsToHtml(sortedPostItems);
|
const convertedItems = JSONToHTML.itemsToHtml(sortedPostItems);
|
||||||
postHTML = `${postMeta.description}${convertedItems}`;
|
postHTML = `${postHTML}${convertedItems}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const postDate = JSONToHTML.getPostDate(postMeta);
|
const postDate = JSONToHTML.getPostDate(postMeta);
|
||||||
|
@ -54,9 +54,7 @@ const fetchPostsFromData = (revueData) => {
|
||||||
created_at: postDate,
|
created_at: postDate,
|
||||||
published_at: postDate,
|
published_at: postDate,
|
||||||
updated_at: postDate,
|
updated_at: postDate,
|
||||||
html: postHTML,
|
html: postHTML
|
||||||
tags: ['#revue']
|
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -88,8 +88,20 @@ const getPostStatus = (data) => {
|
||||||
return (isPublished) ? 'published' : 'draft';
|
return (isPublished) ? 'published' : 'draft';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const cleanCsvHTML = (data) => {
|
||||||
|
// Blockquotes need to have some sort of wrapping elements around all contents
|
||||||
|
// Wrap all content in <p> tags. The HTML to Mobiledoc parse can handle duplicate <p> tags.
|
||||||
|
data = data.replace(/<blockquote.*?>(.*?)<\/blockquote>/gm, '<blockquote><p>$1</p></blockquote>');
|
||||||
|
|
||||||
|
// These exports have a lot of <p><br></p> that we don't want
|
||||||
|
data = data.replace(/<p><br><\/p>/gm, '');
|
||||||
|
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
itemsToHtml,
|
itemsToHtml,
|
||||||
getPostDate,
|
getPostDate,
|
||||||
getPostStatus
|
getPostStatus,
|
||||||
|
cleanCsvHTML
|
||||||
};
|
};
|
||||||
|
|
|
@ -68,8 +68,7 @@ describe('Revue Importer', function () {
|
||||||
created_at: '2022-12-01T01:01:30.000Z',
|
created_at: '2022-12-01T01:01:30.000Z',
|
||||||
published_at: '2022-12-01T01:01:30.000Z',
|
published_at: '2022-12-01T01:01:30.000Z',
|
||||||
updated_at: '2022-12-01T01:01:30.000Z',
|
updated_at: '2022-12-01T01:01:30.000Z',
|
||||||
html: '<p>Hello World!</p>',
|
html: '<p>Hello World!</p>'
|
||||||
tags: ['#revue']
|
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
@ -88,9 +87,6 @@ describe('Revue Importer', function () {
|
||||||
html: '<p>Hello World!</p><p>Goodbye World!</p>',
|
html: '<p>Hello World!</p><p>Goodbye World!</p>',
|
||||||
published_at: '2022-12-01T01:01:30.000Z',
|
published_at: '2022-12-01T01:01:30.000Z',
|
||||||
status: 'published',
|
status: 'published',
|
||||||
tags: [
|
|
||||||
'#revue'
|
|
||||||
],
|
|
||||||
title: 'Hello World - Issue #8',
|
title: 'Hello World - Issue #8',
|
||||||
slug: 'hello-world-issue-8',
|
slug: 'hello-world-issue-8',
|
||||||
updated_at: '2022-12-01T01:01:30.000Z',
|
updated_at: '2022-12-01T01:01:30.000Z',
|
||||||
|
@ -113,8 +109,7 @@ describe('Revue Importer', function () {
|
||||||
created_at: '2022-12-01T01:02:03.123Z',
|
created_at: '2022-12-01T01:02:03.123Z',
|
||||||
published_at: '2022-12-01T01:02:03.123Z',
|
published_at: '2022-12-01T01:02:03.123Z',
|
||||||
updated_at: '2022-12-01T01:02:03.123Z',
|
updated_at: '2022-12-01T01:02:03.123Z',
|
||||||
html: '<p>Hello World!</p><p>Goodbye World!</p>',
|
html: '<p>Hello World!</p><p>Goodbye World!</p>'
|
||||||
tags: ['#revue']
|
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
@ -223,5 +218,19 @@ describe('Revue Importer', function () {
|
||||||
assert.deepEqual(result, '<figure class="kg-card kg-embed-card kg-card-hascaption"><iframe src="https://player.vimeo.com/video/789123" width="200" height="113" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe><figcaption>Hello world</figcaption></figure>');
|
assert.deepEqual(result, '<figure class="kg-card kg-embed-card kg-card-hascaption"><iframe src="https://player.vimeo.com/video/789123" width="200" height="113" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe><figcaption>Hello world</figcaption></figure>');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('cleanCsvHTML', function () {
|
||||||
|
it('can wrap blockquote content in p tags', function () {
|
||||||
|
const result = JSONToHTML.cleanCsvHTML('<p>Hello World!</p><blockquote>Try <a href="https://example.com">This</a>!</blockquote>');
|
||||||
|
|
||||||
|
assert.deepEqual(result, '<p>Hello World!</p><blockquote><p>Try <a href="https://example.com">This</a>!</p></blockquote>');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can remove unwanted blank paragraphs', function () {
|
||||||
|
const result = JSONToHTML.cleanCsvHTML('<p>Hello World!</p><p><br></p><p>Goodbye World!</p>');
|
||||||
|
|
||||||
|
assert.deepEqual(result, '<p>Hello World!</p><p>Goodbye World!</p>');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue