+ turndownService.addRule('figcaption', {
+ filter: 'figcaption',
+ replacement: (content, node) => {
+ // extra newlines are necessary for markdown and HTML to render correctly together
+ return '\n\n\n\n' + content + '\n\n\n\n';
+ }
+ });
+
+ // convert into a code block with language when appropriate
+ turndownService.addRule('pre', {
+ filter: node => {
+ // a with inside will already render nicely, so don't interfere
+ return node.nodeName === 'PRE' && !node.querySelector('code');
+ },
+ replacement: (content, node) => {
+ const language = node.getAttribute('data-wetm-language') || '';
+ return '\n\n```' + language + '\n' + node.textContent + '\n```\n\n';
+ }
+ });
+
return turndownService;
}
-function getPostContent(post, turndownService, config) {
- let content = post.encoded[0];
+function getPostContent(postData, turndownService, config) {
+ let content = postData.encoded[0];
// insert an empty div element between double line breaks
// this nifty trick causes turndown to keep adjacent paragraphs separated
- // without mucking up content inside of other elemnts (like blocks)
+ // without mucking up content inside of other elements (like blocks)
content = content.replace(/(\r?\n){2}/g, '\n\n');
if (config.saveScrapedImages) {
@@ -70,10 +108,13 @@ function getPostContent(post, turndownService, config) {
content = content.replace(/(
]*src=").*?([^/"]+\.(?:gif|jpe?g|png))("[^>]*>)/gi, '$1images/$2$3');
}
- // this is a hack to make