marked/src/Hooks.ts
Spencer Whitehead 1f579f7628
fix: Remove unused plus typescript tightening (#3527)
* chore: remove unused build file

* chore: remove unused package

* chore: remove unused function

* chore: remove unnecessary | undefineds

* core: replace unnecessary &&s with optional chaining

* chore: use .at(-x) instead of .length - x property access

gives stricter TS typing, is more concise

* chore: tighten TS types

* chore: sort tokens alphabetically

* fix: typeof plus !== null check

* chore: type test for .parse, .use

* fix: if check
2024-11-17 21:53:28 -07:00

56 lines
1.1 KiB
TypeScript

import { _defaults } from './defaults.ts';
import { _Lexer } from './Lexer.ts';
import { _Parser } from './Parser.ts';
import type { MarkedOptions } from './MarkedOptions.ts';
import type { Token, TokensList } from './Tokens.ts';
export class _Hooks {
options: MarkedOptions;
block?: boolean;
constructor(options?: MarkedOptions) {
this.options = options || _defaults;
}
static passThroughHooks = new Set([
'preprocess',
'postprocess',
'processAllTokens',
]);
/**
* Process markdown before marked
*/
preprocess(markdown: string) {
return markdown;
}
/**
* Process HTML after marked is finished
*/
postprocess(html: string) {
return html;
}
/**
* Process all tokens before walk tokens
*/
processAllTokens(tokens: Token[] | TokensList) {
return tokens;
}
/**
* Provide function to tokenize markdown
*/
provideLexer() {
return this.block ? _Lexer.lex : _Lexer.lexInline;
}
/**
* Provide function to parse tokens
*/
provideParser() {
return this.block ? _Parser.parse : _Parser.parseInline;
}
}