mirror of
https://github.com/10h30/wordpress-export-to-markdown.git
synced 2026-06-05 15:09:59 +09:00
Preserve embedded tweets
This commit is contained in:
@@ -142,6 +142,12 @@ function initTurndownService() {
|
|||||||
codeBlockStyle: 'fenced'
|
codeBlockStyle: 'fenced'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// preserve embedded tweets
|
||||||
|
turndownService.addRule('tweet', {
|
||||||
|
filter: node => node.nodeName === 'BLOCKQUOTE' && node.getAttribute('class') === 'twitter-tweet',
|
||||||
|
replacement: (content, node) => '\n\n' + node.outerHTML
|
||||||
|
});
|
||||||
|
|
||||||
// preserve embedded codepens
|
// preserve embedded codepens
|
||||||
turndownService.addRule('codepen', {
|
turndownService.addRule('codepen', {
|
||||||
filter: node => {
|
filter: node => {
|
||||||
@@ -155,14 +161,15 @@ function initTurndownService() {
|
|||||||
},
|
},
|
||||||
replacement: (content, node) => '\n\n' + node.outerHTML
|
replacement: (content, node) => '\n\n' + node.outerHTML
|
||||||
});
|
});
|
||||||
|
|
||||||
// preserve embedded scripts (for gists, codepens, etc.)
|
// preserve embedded scripts (for tweets, codepens, gists, etc.)
|
||||||
turndownService.addRule('script', {
|
turndownService.addRule('script', {
|
||||||
filter: 'script',
|
filter: 'script',
|
||||||
replacement: (content, node) => {
|
replacement: (content, node) => {
|
||||||
let before = '\n\n';
|
let before = '\n\n';
|
||||||
if (node.getAttribute('src').endsWith('codepen.io/assets/embed/ei.js')) {
|
let src = node.getAttribute('src');
|
||||||
// keep codepen <script> tags snug with the codepen <p> tags before them
|
if (src.endsWith('twitter.com/widgets.js') || src.endsWith('codepen.io/assets/embed/ei.js')) {
|
||||||
|
// keep twitter and codepen <script> tags snug with the element above them
|
||||||
before = '\n';
|
before = '\n';
|
||||||
}
|
}
|
||||||
let html = node.outerHTML.replace('async=""', 'async');
|
let html = node.outerHTML.replace('async=""', 'async');
|
||||||
|
|||||||
Reference in New Issue
Block a user