-
Notifications
You must be signed in to change notification settings - Fork 3
Add GitHub Alert Syntax #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| @@ -1 +1 @@ | |||
| window.contentConfig = {"title":"Access8Math","latexDelimiter":"bracket","documentFormat":"block","documentDisplay":"markdown","sourceText":"## Question 1\n\n1. \\({{\\left( -3 \\right)}^{3}}\\)之值為何?\n(A) \\(-27\\)\n(B) \\(-9\\)\n(C) \\(9\\)\n(D) \\(27\\)\n2. aewf",documentColor: "dark"} No newline at end of file | |||
| window.contentConfig = {"title":"Access8Math","latexDelimiter":"bracket","documentFormat":"block","documentDisplay":"markdown","documentColor": "light","sourceText":"## Question 1\n\n1. \\({{\\left( -3 \\right)}^{3}}\\)之值為何?\n(A) \\(-27\\)\n(B) \\(-9\\)\n(C) \\(9\\)\n(D) \\(27\\)\n2. aewf\n ## Alert Example\n\n> [!NOTE]\n> Highlights information that users should take into account, even when skimming.\n\n> [!TIP]\n> Optional information to help a user be more successful.\n\n> [!IMPORTANT]\n> Crucial information necessary for users to succeed.\n\n> [!WARNING]\n> Critical content demanding immediate user attention due to potential risks.\n\n> [!CAUTION]\n> Negative potential consequences of an action."} No newline at end of file | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 新增 alert 的 sample 文字
- 把 sourceText 放到最後面,方便看其他 property 的值
| if (matchedVariant) { | ||
| const { | ||
| type: variantType, | ||
| icon, | ||
| title = ucfirst(variantType), | ||
| titleClassName = `${className}-title`, | ||
| } = matchedVariant; | ||
| const typeRegexp = new RegExp(createSyntaxPattern(variantType)); | ||
|
|
||
| Object.assign(token, { | ||
| type: 'alert', | ||
| meta: { | ||
| className, | ||
| variant: variantType, | ||
| icon, | ||
| title, | ||
| titleClassName, | ||
| }, | ||
| }); | ||
|
|
||
| const firstLine = token.tokens?.[0]; | ||
| const firstLineText = firstLine.raw?.replace(typeRegexp, '').trim(); | ||
|
|
||
| if (firstLineText) { | ||
| const patternToken = firstLine.tokens[0]; | ||
|
|
||
| Object.assign(patternToken, { | ||
| raw: patternToken.raw.replace(typeRegexp, ''), | ||
| text: patternToken.text.replace(typeRegexp, ''), | ||
| }); | ||
|
|
||
| if (firstLine.tokens[1]?.type === 'br') { | ||
| firstLine.tokens.splice(1, 1); | ||
| } | ||
| } else { | ||
| token.tokens?.shift(); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we avoid "nested if-block" and "else"?
if (!matchedVariant) return;
// some codes
if (!firstLineText) token.tokens?.shift();
// some codes
if (firstLine.tokens[1]?.type === 'br') {
firstLine.tokens.splice(1, 1);
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing that out, it’s a great suggestion
aee4baa
| const firstLine = token.tokens?.[0]; | ||
| const firstLineText = firstLine.raw?.replace(typeRegexp, '').trim(); | ||
|
|
||
| if (!firstLineText) { | ||
| token.tokens?.shift(); | ||
| return; | ||
| } | ||
|
|
||
| const patternToken = firstLine.tokens[0]; | ||
|
|
||
| Object.assign(patternToken, { | ||
| raw: patternToken.raw.replace(typeRegexp, ''), | ||
| text: patternToken.text.replace(typeRegexp, ''), | ||
| }); | ||
|
|
||
| if (firstLine.tokens[1]?.type === 'br') { | ||
| firstLine.tokens.splice(1, 1); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know mutating is the pattern the official demos, so it's okay to me to mutate directly on token. However, could you avoid mutating the children of token by accessing and mutating? For readability, please consider reassgin instead of deep mutation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ve updated the code to avoid deep mutations on children of token and switched to reassigning instead. I think it’s more readable now. Let me know if you have any additional suggestions!
9f63a68
| return Object.values( | ||
| [...defaultAlertVariant, ...variants].reduce((map, item) => { | ||
| map[item.type] = item; | ||
| return map; | ||
| }, {}), | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- please do not mutate the argument in a reduce.
- why do we need a
reducebut turn out we only return the values of the map from reduce? it looks like it is equivalent to[...defaultAlertVariant, ...variants]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, the handling of this function isn’t ideal. I originally wanted to make it similar to the marked alert package by allowing external options, but looking at it now, it feels unnecessary and just adds complexity. So, I’ve removed the function for now. Let me know if you’ve got other thoughts!
ded5016


Description
Discussion
完整引入 tailwind css:css 2kb

只引入 utilities:css 763B

11/18 討論結論