Skip to content

Commit

Permalink
Markdown conversion improvements: Use Prettier to clean up code block…
Browse files Browse the repository at this point in the history
…s, 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
  • Loading branch information
zachleat committed Nov 27, 2024
1 parent 1698186 commit 27361e1
Show file tree
Hide file tree
Showing 5 changed files with 285 additions and 41 deletions.
76 changes: 68 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,20 @@
"dependencies": {
"@11ty/eleventy-fetch": "^5.0.1",
"@11ty/posthtml-urls": "^1.0.0",
"@prettier/sync": "^0.5.2",
"@sindresorhus/slugify": "^2.2.1",
"dotenv": "^16.4.5",
"entities": "^5.0.0",
"fast-xml-parser": "^4.5.0",
"filesize": "^10.1.6",
"github-publish": "^6.0.0",
"graceful-fs": "^4.2.11",
"js-yaml": "^4.1.0",
"kleur": "^4.1.5",
"posthtml": "^0.16.6",
"turndown": "^7.2.0"
"prettier": "^3.4.1",
"striptags": "^3.2.0",
"turndown": "github:zachleat/fork-turndown"
},
"devDependencies": {
"husky": "^9.1.7"
Expand Down
12 changes: 8 additions & 4 deletions src/Importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,10 @@ class Importer {
entry.content = await this.htmlTransformer.transform(entry.content, entry);
}
if(Importer.shouldConvertToMarkdown(entry) && options.contentType === "markdown") {
entry.content = await this.markdownService.toMarkdown(entry.content, entry.url);
await this.markdownService.asyncInit();

entry.content = await this.markdownService.toMarkdown(entry.content, entry);

entry.contentType = "markdown";
}

Expand Down Expand Up @@ -301,18 +304,19 @@ class Importer {
fallbackPath = (new URL(url)).pathname;
}

// Data source specific override
let outputOverrideFn = source?.getFilepathFormatFunction();
if(outputOverrideFn && typeof outputOverrideFn === "function") { // entry override
if(outputOverrideFn && typeof outputOverrideFn === "function") {
let pathname = outputOverrideFn(url, fallbackPath);
if(pathname === false) {
return false;
}

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

// WordPress drafts only have a UUID query param e.g. ?p=ID_NUMBER
// WordPress draft posts only have a `p` query param e.g. ?p=ID_NUMBER
if(fallbackPath === "/") {
fallbackPath = Fetcher.createHash(entry.url);
}
Expand Down
Loading

0 comments on commit 27361e1

Please sign in to comment.