Skip to content

Commit

Permalink
[docs-infra] Crash on invalid callout type
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Aug 31, 2024
1 parent ffddc91 commit 71850ae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 39 deletions.
25 changes: 0 additions & 25 deletions docs/pages/experiments/docs/callouts.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,31 +110,6 @@ It says, "You will fail if you don't heed this dire warning."
:::
```

## Empty

Should not be used, here just to ensure forgetting the token is not a big deal.

:::
This is a callout.
It says, "You will fail if you don't heed this dire warning."

- emphasised: **bold text**
- some code `<div/>`
- a [link](#link).

:::

```markup
:::
This is a callout.
It says, "You will fail if you don't heed this dire warning."
- emphasised: **bold text**
- some code `<div/>`
- a [link](#link).
:::
```

## With code

:::info
Expand Down
26 changes: 12 additions & 14 deletions packages/markdown/parseMarkdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,22 +458,20 @@ function createRender(context) {
}
return undefined;
},

renderer(token) {
return `<aside class="MuiCallout-root MuiCallout-${token.severity}">
${
['info', 'success', 'warning', 'error'].includes(token.severity)
? [
'<div class="MuiCallout-icon-container">',
'<svg focusable="false" aria-hidden="true" viewBox="0 0 24 24" data-testid="ContentCopyRoundedIcon">',
`<use class="MuiCode-copied-icon" xlink:href="#${token.severity}-icon" />`,
'</svg>',
'</div>',
].join('\n')
: ''
if (!['info', 'success', 'warning', 'error'].includes(token.severity)) {
throw new Error(`docs-infra: Callout :::${token.severity} is not supported`);
}
<div class="MuiCallout-content">
${this.parser.parse(token.tokens)}\n</div></aside>`;

return `<aside class="MuiCallout-root MuiCallout-${token.severity}">${[
'<div class="MuiCallout-icon-container">',
'<svg focusable="false" aria-hidden="true" viewBox="0 0 24 24" data-testid="ContentCopyRoundedIcon">',
`<use class="MuiCode-copied-icon" xlink:href="#${token.severity}-icon" />`,
'</svg>',
'</div>',
].join(
'\n',
)}<div class="MuiCallout-content">${this.parser.parse(token.tokens)}</div></aside>`;
},
},
],
Expand Down

0 comments on commit 71850ae

Please sign in to comment.