MCPcopy
hub / github.com/marktext/marktext / tokenizerFac

Function tokenizerFac

packages/muya/src/inlineRenderer/lexer.ts:25–641  ·  view source on GitHub ↗
(src: string, beginRules: BeginRules | null, inlineRules: InlineRules, pos = 0, top: boolean, labels: Labels, options: ITokenizerFacOptions)

Source from the content-addressed store, hash-verified

23 = /title|textarea|style|xmp|iframe|noembed|noframes|script|plaintext/i;
24
25function tokenizerFac(src: string, beginRules: BeginRules | null, inlineRules: InlineRules, pos = 0, top: boolean, labels: Labels, options: ITokenizerFacOptions) {
26 const originSrc = src;
27 const tokens: Token[] = [];
28 let pending = '';
29 let pendingStartPos = pos;
30 const { superSubScript, footnote } = options;
31 const pushPending = () => {
32 if (pending) {
33 tokens.push({
34 type: 'text',
35 parent: tokens,
36 raw: pending,
37 content: pending,
38 range: {
39 start: pendingStartPos,
40 end: pos,
41 },
42 });
43 }
44
45 pendingStartPos = pos;
46 pending = '';
47 };
48
49 if (beginRules && pos === 0) {
50 const beginRuleKeys = [
51 'header',
52 'hr',
53 'code_fence',
54 'multiple_math',
55 ] as const;
56
57 for (const ruleName of beginRuleKeys) {
58 const to = beginRules[ruleName].exec(src);
59
60 if (to) {
61 const token = {
62 type: ruleName,
63 raw: to[0],
64 parent: tokens,
65 marker: to[1],
66 content: to[2] || '',
67 backlash: to[3] || '',
68 range: {
69 start: pos,
70 end: pos + to[0].length,
71 },
72 };
73 tokens.push(token);
74 src = src.substring(to[0].length);
75 pos = pos + to[0].length;
76 break;
77 }
78 }
79 const def = beginRules.reference_definition.exec(src);
80 if (def && isLengthEven(def[3])) {
81 const token = {
82 type: 'reference_definition' as const,

Callers 1

tokenizerFunction · 0.70

Calls 9

isLengthEvenFunction · 0.90
validateEmphasizeFunction · 0.90
lowerPriorityFunction · 0.90
correctUrlFunction · 0.90
parseSrcAndTitleFunction · 0.90
getAttributesFunction · 0.90
pushMethod · 0.80
pushPendingFunction · 0.70
hasMethod · 0.65

Tested by

no test coverage detected