Skip to content

Commit 27361e1

Browse files
committed
Markdown conversion improvements: Use Prettier to clean up code blocks, Keep a bunch of HTML tags by default, Fix asset cleanup to work based on filePath (not url), Fix issue with encoding/decoding html entities in turndown
1 parent 1698186 commit 27361e1

File tree

5 files changed

+285
-41
lines changed

5 files changed

+285
-41
lines changed

package-lock.json

Lines changed: 68 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,20 @@
3737
"dependencies": {
3838
"@11ty/eleventy-fetch": "^5.0.1",
3939
"@11ty/posthtml-urls": "^1.0.0",
40+
"@prettier/sync": "^0.5.2",
4041
"@sindresorhus/slugify": "^2.2.1",
4142
"dotenv": "^16.4.5",
43+
"entities": "^5.0.0",
4244
"fast-xml-parser": "^4.5.0",
4345
"filesize": "^10.1.6",
4446
"github-publish": "^6.0.0",
4547
"graceful-fs": "^4.2.11",
4648
"js-yaml": "^4.1.0",
4749
"kleur": "^4.1.5",
4850
"posthtml": "^0.16.6",
49-
"turndown": "^7.2.0"
51+
"prettier": "^3.4.1",
52+
"striptags": "^3.2.0",
53+
"turndown": "github:zachleat/fork-turndown"
5054
},
5155
"devDependencies": {
5256
"husky": "^9.1.7"

src/Importer.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,10 @@ class Importer {
260260
entry.content = await this.htmlTransformer.transform(entry.content, entry);
261261
}
262262
if(Importer.shouldConvertToMarkdown(entry) && options.contentType === "markdown") {
263-
entry.content = await this.markdownService.toMarkdown(entry.content, entry.url);
263+
await this.markdownService.asyncInit();
264+
265+
entry.content = await this.markdownService.toMarkdown(entry.content, entry);
266+
264267
entry.contentType = "markdown";
265268
}
266269

@@ -301,18 +304,19 @@ class Importer {
301304
fallbackPath = (new URL(url)).pathname;
302305
}
303306

307+
// Data source specific override
304308
let outputOverrideFn = source?.getFilepathFormatFunction();
305-
if(outputOverrideFn && typeof outputOverrideFn === "function") { // entry override
309+
if(outputOverrideFn && typeof outputOverrideFn === "function") {
306310
let pathname = outputOverrideFn(url, fallbackPath);
307311
if(pathname === false) {
308312
return false;
309313
}
310314

311-
// does *not* add a file extension for you
315+
// does method does *not* add a file extension for you, you must supply one in `filepathFormat` function
312316
return path.join(this.#outputFolder, pathname);
313317
}
314318

315-
// WordPress drafts only have a UUID query param e.g. ?p=ID_NUMBER
319+
// WordPress draft posts only have a `p` query param e.g. ?p=ID_NUMBER
316320
if(fallbackPath === "/") {
317321
fallbackPath = Fetcher.createHash(entry.url);
318322
}

0 commit comments

Comments
 (0)