Skip to content

Commit

Permalink
fix(mdast): fix mdast attributes
Browse files Browse the repository at this point in the history
attributes now appear even when there is no note/warning
  • Loading branch information
Ahacad committed Jul 15, 2021
1 parent d11434d commit afbe59e
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions mdast-util-details/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,11 @@ function enterContainer(token) {
enter.call(this, 'detailsContainer', token, 'details');
}
function enterSummary(token) {
enter.call(this, 'detailsContainerSummary', token, 'summary');
}

function enter(type, token, name) {
this.enter(
{ type: type, name: name || '', attributes: {}, children: [] },
token,
);
}

function exitExpanded(token) {
this.setData('detailsAttributes', []);
this.getData('detailsAttributes').push(['open', true]);
}
function exitClassName(token) {
this.getData('detailsAttributes').push(['class', this.sliceSerialize(token)]);

// pushin all the attributes for <details> tag before entering <summary> tag
const attributes = this.getData('detailsAttributes');
const cleaned = {};
let index = -1;
let attribute;
// pushin all the attributes
while (++index < attributes.length) {
attribute = attributes[index];
if (attribute[0] === 'class' && cleaned.class) {
Expand All @@ -52,6 +35,22 @@ function exitClassName(token) {

this.setData('detailsAttributes');
this.stack[this.stack.length - 1].attributes = cleaned;

enter.call(this, 'detailsContainerSummary', token, 'summary');
}
function enter(type, token, name) {
this.enter(
{ type: type, name: name || '', attributes: {}, children: [] },
token,
);
}

function exitExpanded(token) {
this.setData('detailsAttributes', []);
this.getData('detailsAttributes').push(['open', true]);
}
function exitClassName(token) {
this.getData('detailsAttributes').push(['class', this.sliceSerialize(token)]);
}
function exit(token) {
this.exit(token);
Expand Down

0 comments on commit afbe59e

Please sign in to comment.