From 1c54dd62ceeff5ff4b080bd71db1d67da32a10eb Mon Sep 17 00:00:00 2001 From: mgt Date: Sat, 1 Jun 2024 15:27:44 +0800 Subject: [PATCH] save --- .../factory-details-class.ts | 4 ++- src/micromark-details/html.ts | 1 - src/micromark-details/syntax.ts | 26 ++++++++++--------- test/test11.ts | 16 +++--------- 4 files changed, 20 insertions(+), 27 deletions(-) diff --git a/src/micromark-details/factory-details-class.ts b/src/micromark-details/factory-details-class.ts index cc2c461..f29fd95 100644 --- a/src/micromark-details/factory-details-class.ts +++ b/src/micromark-details/factory-details-class.ts @@ -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'); @@ -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'; @@ -58,6 +60,6 @@ export const factoryDetailsClass: Tokenizer = function (effects, ok, nok) { return nok(code); } effects.enter('detailsContainerClassName'); - return className; + return className(code); }; }; diff --git a/src/micromark-details/html.ts b/src/micromark-details/html.ts index 88ca0a3..610e4cc 100644 --- a/src/micromark-details/html.ts +++ b/src/micromark-details/html.ts @@ -32,7 +32,6 @@ export const detailsHtml: Extension = { detailsExpanded() { (this as any).tag(' open'); }, - detailsContainerFence() {}, detailsContainerContent() { // this.tag('

'); }, diff --git a/src/micromark-details/syntax.ts b/src/micromark-details/syntax.ts index 00fee62..1e2b515 100644 --- a/src/micromark-details/syntax.ts +++ b/src/micromark-details/syntax.ts @@ -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; @@ -31,6 +31,7 @@ const tokenizeDetailsContainer: Tokenizer = function (effects, ok, nok) { } }; const open2: State = function (code) { + console.log(`open2 code: ${code}`); if (code === openingMark) { effects.consume(code); sizeOpen++; @@ -38,10 +39,11 @@ const tokenizeDetailsContainer: Tokenizer = function (effects, ok, nok) { } 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); @@ -49,7 +51,6 @@ const tokenizeDetailsContainer: Tokenizer = function (effects, ok, nok) { } 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 @@ -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)}`); @@ -133,9 +137,7 @@ 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; @@ -143,10 +145,10 @@ const tokenizeDetailsContainer: Tokenizer = function (effects, ok, nok) { // 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); diff --git a/test/test11.ts b/test/test11.ts index 5e62664..289b8b6 100644 --- a/test/test11.ts +++ b/test/test11.ts @@ -24,10 +24,7 @@ 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( @@ -35,15 +32,8 @@ 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 })