MCPcopy Create free account
hub / github.com/markdoc/markdoc / createToken

Function createToken

src/tokenizer/plugins/annotations.ts:15–49  ·  view source on GitHub ↗
(
  state: StateBlock | StateInline,
  content: string,
  contentStart?: number
)

Source from the content-addressed store, hash-verified

13import { OPEN, CLOSE } from '../../utils';
14
15function createToken(
16 state: StateBlock | StateInline,
17 content: string,
18 contentStart?: number
19): Token {
20 try {
21 const { type, meta, nesting = 0 } = parse(content, { Variable, Function });
22 const token = state.push(type, '', nesting);
23 token.info = content;
24 token.meta = meta;
25
26 if (!state.delimiters) {
27 state.delimiters = [];
28 }
29
30 return token;
31 } catch (error) {
32 if (!(error instanceof SyntaxError)) throw error;
33
34 const {
35 message,
36 location: { start, end },
37 } = error as SyntaxError;
38 const location = contentStart
39 ? {
40 start: { offset: start.offset + contentStart },
41 end: { offset: end.offset + contentStart },
42 }
43 : null;
44
45 const token = state.push('error', '', 0);
46 token.meta = { error: { message, location } };
47 return token;
48 }
49}
50
51function block(
52 state: StateBlock,

Callers 2

blockFunction · 0.85
inlineFunction · 0.85

Calls 2

pushMethod · 0.80
parseFunction · 0.70

Tested by

no test coverage detected