MCPcopy
hub / github.com/GitbookIO/gitbook / parseTemplate

Method parseTemplate

packages/expr/src/runtime.ts:128–146  ·  view source on GitHub ↗

* Parse a template and validate all embedded expressions.

(template: string)

Source from the content-addressed store, hash-verified

126 * Parse a template and validate all embedded expressions.
127 */
128 public parseTemplate(template: string): { parts: TemplatePart[]; errors: ExpressionError[] } {
129 const parts = parseTemplateParts(template);
130 const errors: ExpressionError[] = [];
131
132 for (const part of parts) {
133 if (part.type === 'expression') {
134 try {
135 const { invalidNodes } = this.parse(part.value);
136 if (invalidNodes.length > 0) {
137 errors.push(new ExpressionError('Invalid expression'));
138 }
139 } catch (error) {
140 errors.push(error as ExpressionError);
141 }
142 }
143 }
144
145 return { parts, errors };
146 }
147
148 /**
149 * Evaluate a template string containing `{{ expression }}` placeholders.

Callers 1

evaluateTemplateMethod · 0.95

Calls 1

parseMethod · 0.95

Tested by

no test coverage detected