Skip to content

Commit

Permalink
fix: export parser
Browse files Browse the repository at this point in the history
  • Loading branch information
uetchy committed Jun 24, 2020
1 parent c1d22f7 commit c78c800
Show file tree
Hide file tree
Showing 3 changed files with 380 additions and 354 deletions.
10 changes: 5 additions & 5 deletions packages/vfm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"mdast-util-to-hast": "^9.1.0",
"mdast-util-to-string": "^1.1.0",
"meow": "^7.0.1",
"rehype-document": "^5.0.0",
"rehype-document": "^5.1.0",
"rehype-mathjax": "^2.0.0",
"rehype-raw": "^4.0.2",
"rehype-slug": "^3.0.0",
Expand All @@ -35,13 +35,13 @@
},
"devDependencies": {
"@types/debug": "^4.1.5",
"@types/jest": "^26.0.0",
"@types/jest": "^26.0.2",
"@types/js-yaml": "^3.12.4",
"@types/node": "^14.0.13",
"@types/node": "^14.0.14",
"@types/vfile": "^4.0.0",
"jest": "^26.0.1",
"jest": "^26.1.0",
"shx": "^0.3.2",
"ts-jest": "^26.1.0",
"ts-jest": "^26.1.1",
"typescript": "^3.9.5"
},
"types": "lib/index.d.ts",
Expand Down
27 changes: 14 additions & 13 deletions packages/vfm/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import unified from 'unified';
import {VFile} from 'vfile';
import unified, {Processor} from 'unified';
import doc from 'rehype-document';
import rehypeStringify from 'rehype-stringify';

Expand All @@ -12,27 +11,29 @@ export interface StringifyMarkdownOptions {
partial?: boolean;
}

export function process(
markdownString: string,
{stylesheet = undefined, partial = false}: StringifyMarkdownOptions = {},
): VFile {
export function VFM({
stylesheet = undefined,
partial = false,
}: StringifyMarkdownOptions = {}): Processor {
const processor = unified().use(markdown).use(html);
if (!partial) {
processor.use(doc, {language: 'ja', css: stylesheet});
}
processor.use(rehypeStringify);

if (debug.enabled) {
const inspect = require('unist-util-inspect');
debug(inspect(processor.parse(markdownString)));
}

return processor.processSync(markdownString);
return processor;
}

export function stringify(
markdownString: string,
options: StringifyMarkdownOptions = {},
): string {
return String(process(markdownString, options));
const processor = VFM(options);

if (debug.enabled) {
const inspect = require('unist-util-inspect');
debug(inspect(processor.parse(markdownString)));
}

return String(processor.processSync(markdownString));
}
Loading

0 comments on commit c78c800

Please sign in to comment.