From e778d8682d36c1fea9564ed6417d0e209e7ff6a0 Mon Sep 17 00:00:00 2001 From: Ahad Birang Date: Thu, 10 Jun 2021 18:20:38 +0430 Subject: [PATCH] fix: handle boolean attributes (#404) --- .../directive/remark-directive/from-markdown.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/core/parser/markdown/directive/remark-directive/from-markdown.ts b/src/core/parser/markdown/directive/remark-directive/from-markdown.ts index 2a8d2a7ba..c610708ef 100644 --- a/src/core/parser/markdown/directive/remark-directive/from-markdown.ts +++ b/src/core/parser/markdown/directive/remark-directive/from-markdown.ts @@ -29,6 +29,12 @@ const exit = { directiveContainerLabel: exitContainerLabel, directiveContainerName: exitName, + directiveContainerAttributeInitializerMarker() { + // If an attribute name follows by `=` it should be treat as string + const attributes = this.getData('directiveAttributes') + attributes[attributes.length - 1][1] = '' + }, + directiveLeaf: exitToken, directiveLeafAttributeClassValue: exitAttributeClassValue, directiveLeafAttributeIdValue: exitAttributeIdValue, @@ -144,7 +150,9 @@ function exitAttributeValue(token: Token) { function exitAttributeName(token: Token) { // Attribute names in CommonMark are significantly limited, so character // references can’t exist. - this.getData('directiveAttributes').push([this.sliceSerialize(token), '']) + + // Use `true` as attrubute default value to solve issue of attributes without value (example `:block{attr1 attr2}`) + this.getData('directiveAttributes').push([this.sliceSerialize(token), true]) } function exitAttributes() {