Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
Enter-tainer committed Jun 1, 2024
1 parent ca4a886 commit 1c54dd6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 27 deletions.
4 changes: 3 additions & 1 deletion src/micromark-details/factory-details-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const factoryDetailsClass: Tokenizer = function (effects, ok, nok) {
let detailsClass: 'note' | 'abstract' | 'info' | 'tip' | 'success' | 'failure' | 'bug' | 'danger' | 'example' | 'warning' | 'question';
let num = 0;
const className: State = function (code) {
console.log(`factoryDetailsClass: className: code=${code}, num=${num}`);
if (num === detailsClass.length) {
if (markdownSpace(code)) {
effects.exit('detailsContainerClassName');
Expand All @@ -20,6 +21,7 @@ export const factoryDetailsClass: Tokenizer = function (effects, ok, nok) {
return className;
};
return (code) => {
console.log(`factoryDetailsClass: code=${code}`);
switch (code) {
case codes.lowercaseN:
detailsClass = 'note';
Expand Down Expand Up @@ -58,6 +60,6 @@ export const factoryDetailsClass: Tokenizer = function (effects, ok, nok) {
return nok(code);
}
effects.enter('detailsContainerClassName');
return className;
return className(code);
};
};
1 change: 0 additions & 1 deletion src/micromark-details/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export const detailsHtml: Extension = {
detailsExpanded() {
(this as any).tag(' open');
},
detailsContainerFence() {},
detailsContainerContent() {
// this.tag('</p>');
},
Expand Down
26 changes: 14 additions & 12 deletions src/micromark-details/syntax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const tokenizeDetailsContainer: Tokenizer = function (effects, ok, nok) {
let openingMark: number; // can be "?" or "!"

const open: State = (code) => {
console.log(`open code: ${code}`);
effects.enter('detailsContainer');
effects.enter('detailsContainerFence');
effects.enter('detailsContainerSequence');
if (code === codes.questionMark) {
openingMark = codes.questionMark;
Expand All @@ -31,25 +31,26 @@ const tokenizeDetailsContainer: Tokenizer = function (effects, ok, nok) {
}
};
const open2: State = function (code) {
console.log(`open2 code: ${code}`);
if (code === openingMark) {
effects.consume(code);
sizeOpen++;
return open2;
}
if (sizeOpen < constants.codeFencedSequenceSizeMin) return nok(code);
effects.exit('detailsContainerSequence');
return isExpanded;
return isExpanded(code);
};

const isExpanded: State = function (code) {
console.log(`isExpanded code: ${code}`);
if (code === codes.plusSign) {
effects.enter('detailsExpanded');
effects.consume(code);
effects.exit('detailsExpanded');
} else if (code !== codes.space) {
return nok(code);
}
effects.exit('detailsContainerFence');

// first get space, than try if there is class name
// if so try again for space, and then get summary
Expand Down Expand Up @@ -119,11 +120,14 @@ const tokenizeDetailsContainer: Tokenizer = function (effects, ok, nok) {
}
const token = effects.enter(types.chunkDocument, {
contentType: constants.contentTypeDocument,
previous,
// previous,
});
if (previous) previous.next = token;
previous = token;
return contentContinue;
token.next = undefined;
// if (previous && previous !== token) {
// previous.next = token;
// previous = token;
// }
return contentContinue(code);
};
const contentContinue: State = function (code) {
console.log(`contentContinue code: ${code}: ${String.fromCharCode(code as number)}`);
Expand All @@ -133,20 +137,18 @@ const tokenizeDetailsContainer: Tokenizer = function (effects, ok, nok) {
return after(code);
}
if (markdownLineEnding(code)) {
// return effects.check(nonLazyLine, nonLazyLineAfter,
// lineAfter)(code);
return nonLazyLineAfter;
return nonLazyLineAfter(code);
}
effects.consume(code);
return contentContinue;
};
// FIXME: change name for this func
const nonLazyLineAfter: State = function (code) {
console.log(`nonLazyLineAfter code: ${code}`);
effects.consume(code); // consume line ending
effects.exit(types.chunkDocument);
// effects.consume(code); // consume line ending
// self.parser.lazy[token.start.line] = false;
return lineStart;
return lineStart(code);
};
const lineAfter: State = function (code) {
const token = effects.exit(types.chunkDocument);
Expand Down
16 changes: 3 additions & 13 deletions test/test11.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,16 @@ const processor = input => {
// the main plugin written, based on micromark
.use(remarkDetails)
// the function above, transform details related tags to html-compilable
.use(htmlDetails)
.use(remark2rehype)
.use(rehypeStringify)
.processSync(input).value as string;
.parse(input);
}

const res = processor(
`
???+ note 总结
how to do this
how to do that
!!! example
what happened if we nested details
and this
and continue
123
234`
)

console.log(res)
console.dir(res, { depth: null })

0 comments on commit 1c54dd6

Please sign in to comment.