import { allTools } from '@/tools/lib/all-tools'
import { allPlatforms } from '@/tools/lib/all-platforms'
export const tags: string[] = Object.keys(allTools).concat(allPlatforms).concat(['rowheaders'])
// The trailing newline is important. Without it, the line immediately after
// the `` will be considered part of the previous block, which means the Markdown following the `` will not be rendered to HTML correctly. For example:
//
//
Here's some stuff
// And *here* us also some stuff.
//
// Another **sentence** here.
//
// Will yield:
//
// Here's some stuff
// And *here* us also some stuff.
//
// Another sentence here.
//
// when rendering this template with unified.
// If you instead inject an extra newline after the ``, you
// go from:
//
// Here's some stuff
//
// And *here* us also some stuff.
//
// Another **sentence** here.
//
// which yields:
//
// Here's some stuff
//
// And here us also some stuff.
//
// Another sentence here.
//
// The Tool Liquid tags are a little bit fragile because we hope and assume
// that the author of the Liquid+Markdown *don't* do this:
//
// {% vscode %}Bla bla.{% endvscode %}Next stuff here...
//
const template = '{{ output }}
\n'
export const Tool = {
type: 'block' as const,
tagName: '',
// Liquid template objects don't have TypeScript definitions
templates: [] as unknown[],
// tagToken and remainTokens are Liquid internal types without TypeScript definitions
parse(tagToken: unknown, remainTokens: unknown) {
const token = tagToken as { name: string; getText: () => string }
this.tagName = token.name
this.templates = []
const stream = this.liquid.parser.parseStream(remainTokens)
stream
.on(`tag:end${this.tagName}`, () => stream.stop())
// tpl is a Liquid template object without TypeScript definitions
.on('template', (tpl: unknown) => this.templates.push(tpl))
.on('end', () => {
throw new Error(`tag ${token.getText()} not closed`)
})
stream.start()
},
// scope is a Liquid scope object, Generator yields/returns Liquid template values - no TypeScript definitions available
*render(scope: unknown): Generator {
const output = yield this.liquid.renderer.renderTemplates(this.templates, scope)
return yield this.liquid.parseAndRender(template, {
tagName: this.tagName,
output,
})
},
}