diff --git a/src/translator.js b/src/translator.js index 615781a..7fa6348 100644 --- a/src/translator.js +++ b/src/translator.js @@ -79,6 +79,18 @@ function initTurndownService() { } }); + // 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;
 }
 
@@ -100,6 +112,10 @@ function getPostContent(post, turndownService, config) {
 	// by escaping angle brackets (will be unescaped during turndown conversion)
 	content = content.replace(/<(!--more( .*)?--)>/, '<$1>');
 
+	// some WordPress plugins specify a code language in an HTML comment above a
+	// 
 block, save it to a data attribute so the "pre" rule can use it
+	content = content.replace(/(\r?\n