10 Commits

Author SHA1 Message Date
b2de8df538 0.1.7 2023-05-06 15:21:35 -07:00
25ae8b0bcb remove console.log 2023-05-06 15:21:31 -07:00
b5a427d669 0.1.6 2023-05-06 14:09:10 -07:00
455915dd98 readme 2023-05-06 14:08:59 -07:00
90f8c11288 0.1.5 2023-05-06 14:07:18 -07:00
4ceff93214 updates to frontmatter handling 2023-05-06 14:07:15 -07:00
a2866cade6 0.1.4 2023-05-06 14:05:00 -07:00
48041b5845 fix main declaration 2023-05-06 14:04:56 -07:00
7bbebb4574 0.1.3 2023-05-06 14:03:45 -07:00
5c05a87981 add npmignore 2023-05-06 14:03:40 -07:00
6 changed files with 24 additions and 16 deletions

2
.npmignore Normal file
View File

@@ -0,0 +1,2 @@
src
node_modules

4
package-lock.json generated
View File

@@ -29,7 +29,7 @@
"@types/qrcode": "^1.5.0", "@types/qrcode": "^1.5.0",
"typescript": "^5.0.4" "typescript": "^5.0.4"
}, },
"version": "0.1.2" "version": "0.1.7"
}, },
"node_modules/@tootallnate/once": { "node_modules/@tootallnate/once": {
"version": "2.0.0", "version": "2.0.0",
@@ -3483,5 +3483,5 @@
} }
} }
}, },
"version": "0.1.2" "version": "0.1.7"
} }

View File

@@ -1,6 +1,6 @@
{ {
"name": "@doc-utils/markdown2html", "name": "@doc-utils/markdown2html",
"version": "0.1.2", "version": "0.1.7",
"publishConfig": { "publishConfig": {
"registry": "https://gitea.home.jbrumond.me/api/packages/doc-utils/npm/" "registry": "https://gitea.home.jbrumond.me/api/packages/doc-utils/npm/"
}, },
@@ -11,7 +11,7 @@
"bin": { "bin": {
"markdown2html": "./bin/markdown2html" "markdown2html": "./bin/markdown2html"
}, },
"main": "./src/index.ts", "main": "./build/index.js",
"devDependencies": { "devDependencies": {
"@types/dompurify": "^2.3.3", "@types/dompurify": "^2.3.3",
"@types/jsdom": "^20.0.0", "@types/jsdom": "^20.0.0",

View File

@@ -68,11 +68,11 @@ foo:
# This is some markdown # This is some markdown
`; `;
const { frontmatter, markdown } = process_frontmatter(raw_content); const { frontmatter, document } = process_frontmatter(raw_content);
console.log(frontmatter.title); // "Example Markdown with front matter" console.log(frontmatter.title); // "Example Markdown with front matter"
console.log(frontmatter.foo); // [ "bar", "baz" ] console.log(frontmatter.foo); // [ "bar", "baz" ]
console.log(markdown); // "\n# This is some markdown\n" console.log(document); // "\n# This is some markdown\n"
``` ```

View File

@@ -88,7 +88,5 @@ export function parse_attributes(text: string, fallback_id?: Lazy<string>) {
} }
} }
console.log(attrs);
return attrs; return attrs;
} }

View File

@@ -1,18 +1,26 @@
import * as yaml from 'yaml'; import * as yaml from 'yaml';
export function process_frontmatter(document: string, parse = true) { export function process_frontmatter(raw_document: string, parse = true) {
if (! document.startsWith('---\n')) { if (! raw_document.startsWith('---\n')) {
return { return {
frontmatter: null, frontmatter: null,
markdown: document, document: raw_document,
}; };
} }
const endIndex = document.slice(3).indexOf('\n---\n') + 3; const end_index = raw_document.slice(3).indexOf('\n---\n') + 3;
const frontmatterYaml = document.slice(3, endIndex);
const markdown = document.slice(endIndex + 4); if (end_index === 2) {
const frontmatter = parse ? frontmatterYaml : yaml.parse(frontmatterYaml); return {
frontmatter: null,
document: raw_document,
};
}
return { frontmatter, markdown }; const formatter_yaml = raw_document.slice(3, end_index);
const document = raw_document.slice(end_index + 4);
const frontmatter = parse ? formatter_yaml : yaml.parse(formatter_yaml);
return { frontmatter, document };
} }