-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from James-Yu/parser-with-option
Add getParser() to inject plugin options
- Loading branch information
Showing
2 changed files
with
33 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,28 @@ | ||
import * as Ast from "@unified-latex/unified-latex-types"; | ||
import { unified } from "unified"; | ||
import { type FrozenProcessor, unified } from "unified"; | ||
import { unifiedLatexFromString } from "./plugin-from-string"; | ||
import type { PluginOptions } from "./plugin-from-string"; | ||
|
||
const parser = unified().use(unifiedLatexFromString).freeze(); | ||
let parser = unified().use(unifiedLatexFromString).freeze(); | ||
|
||
/** | ||
* Parse the string into an AST. | ||
*/ | ||
export function parse(str: string): Ast.Root { | ||
return parser.parse(str); | ||
} | ||
|
||
/** | ||
* Returns the default `unified-latex` parser, or create a new one with the | ||
* provided `unifiedLatexFromString` options | ||
* @param options Plugin options of `unifiedLatexFromString` plugin. | ||
* @returns The default `unified-latex` parser if `options` is `undefined`, or a | ||
* newly created `unified-latex` parser with the provided `options`. | ||
*/ | ||
export function getParser( | ||
options?: PluginOptions | ||
): FrozenProcessor<Ast.Root, Ast.Root, Ast.Root, void> { | ||
return options | ||
? unified().use(unifiedLatexFromString, options).freeze() | ||
: parser; | ||
} |