MCPcopy
hub / github.com/markedjs/marked / blockTokens

Method blockTokens

src/Lexer.ts:107–293  ·  view source on GitHub ↗
(src: string, tokens: Token[] = [], lastParagraphClipped = false)

Source from the content-addressed store, hash-verified

105 blockTokens(src: string, tokens?: Token[], lastParagraphClipped?: boolean): Token[];
106 blockTokens(src: string, tokens?: TokensList, lastParagraphClipped?: boolean): TokensList;
107 blockTokens(src: string, tokens: Token[] = [], lastParagraphClipped = false) {
108 this.tokenizer.lexer = this;
109 if (this.options.pedantic) {
110 src = src.replace(other.tabCharGlobal, ' ').replace(other.spaceLine, '');
111 }
112
113 let srcLength = Infinity;
114 while (src) {
115 if (src.length < srcLength) {
116 srcLength = src.length;
117 } else {
118 this.infiniteLoopError(src.charCodeAt(0));
119 break;
120 }
121
122 let token: Tokens.Generic | undefined;
123
124 if (this.options.extensions?.block?.some((extTokenizer) => {
125 if (token = extTokenizer.call({ lexer: this }, src, tokens)) {
126 src = src.substring(token.raw.length);
127 tokens.push(token);
128 return true;
129 }
130 return false;
131 })) {
132 continue;
133 }
134
135 // newline
136 if (token = this.tokenizer.space(src)) {
137 src = src.substring(token.raw.length);
138 const lastToken = tokens.at(-1);
139 if (token.raw.length === 1 && lastToken !== undefined) {
140 // if there's a single \n as a spacer, it's terminating the last line,
141 // so move it there so that we don't get unnecessary paragraph tags
142 lastToken.raw += '\n';
143 } else {
144 tokens.push(token);
145 }
146 continue;
147 }
148
149 // code
150 if (token = this.tokenizer.code(src)) {
151 src = src.substring(token.raw.length);
152 const lastToken = tokens.at(-1);
153 // An indented code block cannot interrupt a paragraph.
154 if (lastToken?.type === 'paragraph' || lastToken?.type === 'text') {
155 lastToken.raw += (lastToken.raw.endsWith('\n') ? '' : '\n') + token.raw;
156 lastToken.text += '\n' + token.text;
157 this.inlineQueue.at(-1)!.src = lastToken.text;
158 } else {
159 tokens.push(token);
160 }
161 continue;
162 }
163
164 // fences

Callers 3

lexMethod · 0.95
blockquoteMethod · 0.80
listMethod · 0.80

Calls 14

infiniteLoopErrorMethod · 0.95
fencesMethod · 0.80
lheadingMethod · 0.80
spaceMethod · 0.45
codeMethod · 0.45
headingMethod · 0.45
hrMethod · 0.45
blockquoteMethod · 0.45
listMethod · 0.45
htmlMethod · 0.45
defMethod · 0.45
tableMethod · 0.45

Tested by

no test coverage detected