Lines Matching refs:token

130 export function isTextToken(token: Token): token is TextToken {
131 return token?.type === TokenType.TEXT;
137 export function isHeadingToken(token: Token): token is HeadingToken {
138 return token?.type === TokenType.HEADING;
144 export function isListToken(token: Token): token is ListToken {
145 return token?.type === TokenType.LIST;
151 export function isListItemToken(token: Token): token is ListItemToken {
152 return token?.type === TokenType.LIST_ITEM;
166 for (const token of tokens) { constant
167 if (token.type === TokenType.LIST) {
168 token.depth = listDepth;
170 for (const item of token.items) {
190 for (const token of tokens) { constant
191 output += this.renderToken(token, { indent: 0 });
198 renderToken(token: Token, ctx: RenderingContext): string {
199 switch (token.type) {
201 return this.heading(token);
203 return this.list(token, ctx);
205 return this.listItem(token, ctx);
207 return this.paragraph(token, ctx);
209 return this.text(token, ctx);
211 return this.space(token);
213 return this.code(token, ctx);
215 return this.blockquote(token, ctx);
219 throw new Error(`Cannot parse token: ${token}`);
229 heading(token: HeadingToken): string {
230 return this.indent(token.depth, '#') + ' ' + token.text + EOL.repeat(2);
233 list(token: ListToken, ctx: { indent?: number }): string {
235 for (let i = 0; i < token.items.length; i++) {
236 output += this.listItem(token.items[i], {
238 orderedList: token.ordered,
245 listItem(token: ListItemToken, ctx: RenderingContext): string {
250 if (token.tokens[0]) {
253 output += this.renderToken(token.tokens[0], ctx).trim() + EOL;
256 for (const child of token.tokens.slice(1)) {
262 paragraph(token: ParagraphToken, ctx: RenderingContext): string {
263 return this.indent(ctx.indent) + token.text + EOL;
266 text(token: TextToken, ctx: RenderingContext): string {
268 return this.indent(ctx.indent) + token.text;
271 space(token: SpaceToken): string {
276 code(token: CodeToken, ctx: RenderingContext): string {
277 const lines = token.text.split(EOL);
280 lines.unshift('```' + token.lang ?? '');
286 blockquote(token: BlockquoteToken, ctx: RenderingContext): string {
291 token.tokens