feat: support custom key-value separator, #752

This commit is contained in:
Yang Jun
2024-09-22 21:55:44 +08:00
committed by Jun Yang
parent 5ada07c2c6
commit 6aeed2586a
10 changed files with 18 additions and 11 deletions
+4
View File
@@ -39,4 +39,8 @@ describe('Hash', function () {
num3: 4
})
})
it('should support custom separator', async function () {
const hash = await toPromise(new Hash('num=2.3', '=').render(new Context()))
expect(hash.num).toBe(2.3)
})
})
+1 -1
View File
@@ -15,7 +15,7 @@ type HashValueTokens = Record<string, Token | undefined>
*/
export class Hash {
hash: HashValueTokens = {}
constructor (markup: string, jekyllStyle?: boolean) {
constructor (markup: string, jekyllStyle?: boolean | string) {
const tokenizer = new Tokenizer(markup, {})
for (const hash of tokenizer.readHashes(jekyllStyle)) {
this.hash[hash.name.content] = hash.value
+1 -1
View File
@@ -21,7 +21,7 @@ export function createTagClass (options: TagImplOptions): TagClass {
}
}
* render (ctx: Context, emitter: Emitter): TagRenderReturn {
const hash = (yield new Hash(this.token.args).render(ctx)) as Record<string, any>
const hash = (yield new Hash(this.token.args, ctx.opts.keyValueSeparator).render(ctx)) as Record<string, any>
return yield options.render.call(this, ctx, emitter, hash)
}
}