import dedent from 'dedent' import React from 'react' import { renderToStaticMarkup } from 'react-dom/server' import { expect, test } from 'vitest' import { z } from 'zod' import { mdxParse } from './parse.js' import { MdastToJsx, mdastBfs, type ComponentPropsSchema } from './safe-mdx.js' import { completeJsxTags } from './streaming.js' const components = { Heading({ level, children, ...props }) { return

{children}

}, Cards({ level, children, ...props }) { return
{children}
}, Tabs({ items, children, ...props }) { return
{children}
}, } function render(code, componentPropsSchema?: ComponentPropsSchema, allowClientEsmImports?: boolean, addMarkdownLineNumbers?: boolean) { const mdast = mdxParse(code) const visitor = new MdastToJsx({ markdown: code, mdast, components, componentPropsSchema, allowClientEsmImports, addMarkdownLineNumbers }) const result = visitor.run() const html = renderToStaticMarkup(result) // console.log(JSON.stringify(result, null, 2)) return { result, errors: visitor.errors || [], html } } test('reference links with titles', () => { const code = dedent` > **Heads-up:** Check the [API docs][1] for more info. Visit [Slack developers][2] for details. [1]: https://api.slack.com/methods/search.messages "search.messages method - Slack API" [2]: https://slack.dev/secure-data-connectivity/ "Secure Data Connectivity - Slack Developers" ` const { html } = render(code) expect(html).toMatchInlineSnapshot(`"

Heads-up: Check the API docs for more info.

Visit Slack developers for details.

"`) }) test('markdown inside jsx', () => { const code = dedent` # Hello Component *children*
some *bold* content
` expect(render(code)).toMatchInlineSnapshot(` { "errors": [], "html": "

Hello

Component children

some bold content

", "result":

Hello

Component children

some bold content

, } `) }) test('can complete jsx code with completeJsxTags', () => { const code = dedent` # Hello some value Component *children* ` expect(render(completeJsxTags(code))).toMatchInlineSnapshot(` { "errors": [], "html": "

Hello

", "result":

Hello

, } `) }) test('remark and jsx does not wrap in p', () => { const code = dedent` --- title: createSearchParams --- # Hello i am a paragraph heading sone \`inline code\` \`\`\`tsx some code \`\`\` what ` const mdast = mdxParse(code) mdastBfs(mdast, (x) => { delete x.position }) expect(mdast).toMatchInlineSnapshot(` { "children": [ { "type": "yaml", "value": "title: createSearchParams", }, { "children": [ { "type": "text", "value": "Hello", }, ], "depth": 1, "type": "heading", }, { "children": [ { "type": "text", "value": "i am a paragraph", }, ], "type": "paragraph", }, { "attributes": [], "children": [ { "type": "text", "value": "heading", }, ], "name": "Heading", "type": "mdxJsxFlowElement", }, { "children": [ { "type": "text", "value": "sone ", }, { "type": "inlineCode", "value": "inline code", }, ], "type": "paragraph", }, { "lang": "tsx", "meta": null, "type": "code", "value": "some code", }, { "children": [ { "type": "text", "value": "what", }, ], "type": "paragraph", }, ], "type": "root", } `) }) test('basic', () => { expect( render(dedent` # Hello i am a paragraph heading `), ).toMatchInlineSnapshot(` { "errors": [], "html": "

Hello

i am a paragraph

heading

", "result":

Hello

i am a paragraph

heading
, } `) }) test('frontmatter', () => { expect( render(dedent` --- hello: 5 --- # Hello i am a paragraph `), ).toMatchInlineSnapshot(` { "errors": [], "html": "

Hello

i am a paragraph

", "result":

Hello

i am a paragraph

, } `) }) test('table', () => { expect( render(dedent` # Hello | Tables | Are | Cool | | ------------- |:-------------:| -----:| | col 3 is | right-aligned | $1600 | | col 2 is | centered | $12 | `), ).toMatchInlineSnapshot(` { "errors": [], "html": "

Hello

TablesAreCool
col 3 isright-aligned$1600
col 2 iscentered$12
", "result":

Hello

Tables Are Cool
col 3 is right-aligned $1600
col 2 is centered $12
, } `) }) test('table, only head', () => { expect( render(dedent` # Hello | Tables | Are | Cool | | ------------- |:-------------:| -----:| `), ).toMatchInlineSnapshot(` { "errors": [], "html": "

Hello

TablesAreCool
", "result":

Hello

Tables Are Cool
, } `) }) test('inline jsx', () => { expect( render(dedent` hello `), ).toMatchInlineSnapshot(` { "errors": [], "html": "

hello

", "result": hello , } `) }) test('block jsx', () => { expect( render(dedent` > hello `), ).toMatchInlineSnapshot(` { "errors": [], "html": "

hello

", "result":

hello

, } `) }) test('complex jsx, self closing tags', () => { expect( render(dedent` # hello

content `), ).toMatchInlineSnapshot(` { "errors": [], "html": "

hello


content

", "result":

hello


content

, } `) }) test('missing components are ignored', () => { expect( render(dedent` `), ).toMatchInlineSnapshot(` { "errors": [ { "line": 1, "message": "Unsupported jsx component MissingComponent", }, ], "html": "", "result": , } `) }) test('props parsing', () => { expect( render(dedent` } undef={undefined} null={null} someJson={{"a": 1}} {...{ spread: true }} > hi `), ).toMatchInlineSnapshot(` { "errors": [ { "line": 8, "message": "Failed to evaluate expression attribute: expression2={Boolean(1)}. Functions are not supported", }, { "line": 8, "message": "Expressions in jsx prop not evaluated: (expression2={Boolean(1)})", }, { "line": 9, "message": "Unsupported jsx component SomeComponent in attribute", }, { "line": 9, "message": "Failed to evaluate expression attribute: jsx={}. visitor "JSXElement" is not supported", }, { "line": 9, "message": "Expressions in jsx prop not evaluated: (jsx={})", }, ], "html": "

hi

", "result":

hi

, } `) }) test('jsx attributes with arithmetic expressions', () => { expect( render(dedent` 3} concat={"hello " + "world"} /> `), ).toMatchInlineSnapshot(` { "errors": [], "html": "

", "result": , } `) }) test('jsx attributes with complex objects and arrays', () => { expect( render(dedent` `), ).toMatchInlineSnapshot(` { "errors": [], "html": "

", "result": , } `) }) test('breaks', () => { expect( render(dedent` To have a line break without a paragraph, you will need to use two trailing spaces. Note that this line is separate, but within the same paragraph. (This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.) `), ).toMatchInlineSnapshot(` { "errors": [], "html": "

To have a line break without a paragraph, you will need to use two trailing spaces. Note that this line is separate, but within the same paragraph. (This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.)

", "result":

To have a line break without a paragraph, you will need to use two trailing spaces. Note that this line is separate, but within the same paragraph. (This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.)

, } `) }) // https://github.com/obedm503/markdown-kitchen-sink/blob/master/README.md?plain=1 test('kitchen sink', () => { expect( render(dedent` # Markdown Kitchen Sink This file is https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet plus a few fixes and additions. Used by [obedm503/bootmark](https://github.com/obedm503/bootmark) to [demonstrate](https://obedm503.github.io/bootmark/docs/markdown-cheatsheet.html) it's styling features. This is intended as a quick reference and showcase. For more complete info, see [John Gruber's original spec](http://daringfireball.net/projects/markdown/) and the [Github-flavored Markdown info page](http://github.github.com/github-flavored-markdown/). Note that there is also a [Cheatsheet specific to Markdown Here](./Markdown-Here-Cheatsheet) if that's what you're looking for. You can also check out [more Markdown tools](./Other-Markdown-Tools). ##### Table of Contents [Headers](#headers) [Emphasis](#emphasis) [Lists](#lists) [Links](#links) [Images](#images) [Code and Syntax Highlighting](#code) [Tables](#tables) [Blockquotes](#blockquotes) [Inline HTML](#html) [Horizontal Rule](#hr) [Line Breaks](#lines) [YouTube Videos](#videos) ## Headers # H1 ## H2 ### H3 #### H4 ##### H5 ###### H6 Alternatively, for H1 and H2, an underline-ish style: Alt-H1 ====== Alt-H2 ------ # H1 ## H2 ### H3 #### H4 ##### H5 ###### H6 Alternatively, for H1 and H2, an underline-ish style: Alt-H1 ====== Alt-H2 ------ ## Emphasis \`\`\`no-highlight Emphasis, aka italics, with *asterisks* or _underscores_. Strong emphasis, aka bold, with **asterisks** or __underscores__. Combined emphasis with **asterisks and _underscores_**. Strikethrough uses two tildes. ~~Scratch this.~~ \`\`\` Emphasis, aka italics, with *asterisks* or _underscores_. Strong emphasis, aka bold, with **asterisks** or __underscores__. Combined emphasis with **asterisks and _underscores_**. Strikethrough uses two tildes. ~~Scratch this.~~ ## Lists (In this example, leading and trailing spaces are shown with with dots: ⋅) \`\`\`no-highlight 1. First ordered list item 2. Another item ⋅⋅* Unordered sub-list. 1. Actual numbers don't matter, just that it's a number ⋅⋅1. Ordered sub-list 4. And another item. ⋅⋅⋅You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown). ⋅⋅⋅To have a line break without a paragraph, you will need to use two trailing spaces.⋅⋅ ⋅⋅⋅Note that this line is separate, but within the same paragraph.⋅⋅ ⋅⋅⋅(This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.) * Unordered list can use asterisks - Or minuses + Or pluses \`\`\` 1. First ordered list item 2. Another item * Unordered sub-list. 1. Actual numbers don't matter, just that it's a number 1. Ordered sub-list 4. And another item. You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown). To have a line break without a paragraph, you will need to use two trailing spaces. Note that this line is separate, but within the same paragraph. (This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.) * Unordered list can use asterisks - Or minuses + Or pluses ## Links There are two ways to create links. \`\`\`no-highlight [I'm an inline-style link](https://www.google.com) [I'm an inline-style link with title](https://www.google.com "Google's Homepage") [I'm a reference-style link][Arbitrary case-insensitive reference text] [I'm a relative reference to a repository file](../blob/master/LICENSE) [You can use numbers for reference-style link definitions][1] Or leave it empty and use the [link text itself]. URLs and URLs in angle brackets will automatically get turned into links. http://www.example.com and sometimes example.com (but not on Github, for example). Some text to show that the reference links can follow later. [arbitrary case-insensitive reference text]: https://www.mozilla.org [1]: http://slashdot.org [link text itself]: http://www.reddit.com \`\`\` [I'm an inline-style link](https://www.google.com) [I'm an inline-style link with title](https://www.google.com "Google's Homepage") [I'm a reference-style link][Arbitrary case-insensitive reference text] [I'm a relative reference to a repository file](../blob/master/LICENSE) [You can use numbers for reference-style link definitions][1] Or leave it empty and use the [link text itself]. URLs and URLs in angle brackets will automatically get turned into links. http://www.example.com and sometimes example.com (but not on Github, for example). Some text to show that the reference links can follow later. [arbitrary case-insensitive reference text]: https://www.mozilla.org [1]: http://slashdot.org [link text itself]: http://www.reddit.com ## Images \`\`\`no-highlight Here's our logo (hover to see the title text): Inline-style: ![alt text](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 1") Reference-style: ![alt text][logo] [logo]: https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 2" \`\`\` Here's our logo (hover to see the title text): Inline-style: ![alt text](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 1") Reference-style: ![alt text][logo] [logo]: https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 2" ## Code and Syntax Highlighting Code blocks are part of the Markdown spec, but syntax highlighting isn't. However, many renderers -- like Github's and *Markdown Here* -- support syntax highlighting. Which languages are supported and how those language names should be written will vary from renderer to renderer. *Markdown Here* supports highlighting for dozens of languages (and not-really-languages, like diffs and HTTP headers); to see the complete list, and how to write the language names, see the [highlight.js demo page](http://softwaremaniacs.org/media/soft/highlight/test.html). \`\`\`no-highlight Inline \`code\` has \`back-ticks around\` it. \`\`\` Inline \`code\` has \`back-ticks around\` it. Blocks of code are either fenced by lines with three back-ticks \`\`\`, or are indented with four spaces. I recommend only using the fenced code blocks -- they're easier and only they support syntax highlighting. \`\`\`javascript var s = "JavaScript syntax highlighting"; alert(s); \`\`\` \`\`\`python s = "Python syntax highlighting" print s \`\`\` \`\`\` No language indicated, so no syntax highlighting. But let's throw in a <b>tag</b>. \`\`\` \`\`\`javascript var s = "JavaScript syntax highlighting"; alert(s); \`\`\` \`\`\`python s = "Python syntax highlighting" print s \`\`\` \`\`\` No language indicated, so no syntax highlighting in Markdown Here (varies on Github). But let's throw in a tag. \`\`\` ## Tables Tables aren't part of the core Markdown spec, but they are part of GFM and *Markdown Here* supports them. They are an easy way of adding tables to your email -- a task that would otherwise require copy-pasting from another application. \`\`\`no-highlight Colons can be used to align columns. | Tables | Are | Cool | | ------------- |:-------------:| -----:| | col 3 is | right-aligned | $1600 | | col 2 is | centered | $12 | | zebra stripes | are neat | $1 | There must be at least 3 dashes separating each header cell. The outer pipes (|) are optional, and you don't need to make the raw Markdown line up prettily. You can also use inline Markdown. Markdown | Less | Pretty --- | --- | --- *Still* | \`renders\` | **nicely** 1 | 2 | 3 \`\`\` Colons can be used to align columns. | Tables | Are | Cool | | ------------- |:-------------:| -----:| | col 3 is | right-aligned | $1600 | | col 2 is | centered | $12 | | zebra stripes | are neat | $1 | There must be at least 3 dashes separating each header cell. The outer pipes (|) are optional, and you don't need to make the raw Markdown line up prettily. You can also use inline Markdown. Markdown | Less | Pretty --- | --- | --- *Still* | \`renders\` | **nicely** 1 | 2 | 3 ## Blockquotes \`\`\`no-highlight > Blockquotes are very handy in email to emulate reply text. > This line is part of the same quote. Quote break. > This is a very long line that will still be quoted properly when it wraps. Oh boy let's keep writing to make sure this is long enough to actually wrap for everyone. Oh, you can *put* **Markdown** into a blockquote. \`\`\` > Blockquotes are very handy in email to emulate reply text. > This line is part of the same quote. Quote break. > This is a very long line that will still be quoted properly when it wraps. Oh boy let's keep writing to make sure this is long enough to actually wrap for everyone. Oh, you can *put* **Markdown** into a blockquote. ## Inline HTML You can also use raw HTML in your Markdown, and it'll mostly work pretty well. \`\`\`no-highlight
Definition list
Is something people use sometimes.
Markdown in HTML
Does *not* work **very** well. Use HTML tags.
\`\`\`
Definition list
Is something people use sometimes.
Markdown in HTML
Does *not* work **very** well. Use HTML tags.
## Horizontal Rule \`\`\` Three or more... --- Hyphens *** Asterisks ___ Underscores \`\`\` Three or more... --- Hyphens *** Asterisks ___ Underscores ## Line Breaks My basic recommendation for learning how line breaks work is to experiment and discover -- hit <Enter> once (i.e., insert one newline), then hit it twice (i.e., insert two newlines), see what happens. You'll soon learn to get what you want. "Markdown Toggle" is your friend. Here are some things to try out: \`\`\` Here's a line for us to start with. This line is separated from the one above by two newlines, so it will be a *separate paragraph*. This line is also a separate paragraph, but... This line is only separated by a single newline, so it's a separate line in the *same paragraph*. \`\`\` Here's a line for us to start with. This line is separated from the one above by two newlines, so it will be a *separate paragraph*. This line is also begins a separate paragraph, but... This line is only separated by a single newline, so it's a separate line in the *same paragraph*. (Technical note: *Markdown Here* uses GFM line breaks, so there's no need to use MD's two-space line breaks.) ## YouTube Videos They can't be added directly but you can add an image with a link to the video like this: \`\`\`no-highlight IMAGE ALT TEXT HERE \`\`\` Or, in pure Markdown, but losing the image sizing and border: \`\`\`no-highlight [![IMAGE ALT TEXT HERE](http://img.youtube.com/vi/YOUTUBE_VIDEO_ID_HERE/0.jpg)](http://www.youtube.com/watch?v=YOUTUBE_VIDEO_ID_HERE) \`\`\` `), ).toMatchInlineSnapshot(` { "errors": [], "html": "

Markdown Kitchen Sink

This file is https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet plus a few fixes and additions. Used by obedm503/bootmark to demonstrate it's styling features.

This is intended as a quick reference and showcase. For more complete info, see John Gruber's original spec and the Github-flavored Markdown info page.

Note that there is also a Cheatsheet specific to Markdown Here if that's what you're looking for. You can also check out more Markdown tools.

Table of Contents

Headers Emphasis Lists Links Images Code and Syntax Highlighting Tables Blockquotes Inline HTML Horizontal Rule Line Breaks YouTube Videos

Headers

H1

H2

H3

H4

H5
H6

Alternatively, for H1 and H2, an underline-ish style:

Alt-H1

Alt-H2

H1

H2

H3

H4

H5
H6

Alternatively, for H1 and H2, an underline-ish style:

Alt-H1

Alt-H2

Emphasis

Emphasis, aka italics, with *asterisks* or _underscores_.

      Strong emphasis, aka bold, with **asterisks** or __underscores__.

      Combined emphasis with **asterisks and _underscores_**.

      Strikethrough uses two tildes. ~~Scratch this.~~

Emphasis, aka italics, with asterisks or underscores.

Strong emphasis, aka bold, with asterisks or underscores.

Combined emphasis with asterisks and underscores.

Strikethrough uses two tildes. Scratch this.

Lists

(In this example, leading and trailing spaces are shown with with dots: ⋅)

1. First ordered list item
      2. Another item
      ⋅⋅* Unordered sub-list.
      1. Actual numbers don't matter, just that it's a number
      ⋅⋅1. Ordered sub-list
      4. And another item.

      ⋅⋅⋅You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown).

      ⋅⋅⋅To have a line break without a paragraph, you will need to use two trailing spaces.⋅⋅
      ⋅⋅⋅Note that this line is separate, but within the same paragraph.⋅⋅
      ⋅⋅⋅(This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.)

      * Unordered list can use asterisks
      - Or minuses
      + Or pluses
  1. First ordered list item

  2. Another item

  • Unordered sub-list.

  1. Actual numbers don't matter, just that it's a number

  2. Ordered sub-list

  3. And another item.

    You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown).

    To have a line break without a paragraph, you will need to use two trailing spaces. Note that this line is separate, but within the same paragraph. (This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.)

  • Unordered list can use asterisks

  • Or minuses

  • Or pluses

Links

There are two ways to create links.

[I'm an inline-style link](https://www.google.com)

      [I'm an inline-style link with title](https://www.google.com "Google's Homepage")

      [I'm a reference-style link][Arbitrary case-insensitive reference text]

      [I'm a relative reference to a repository file](../blob/master/LICENSE)

      [You can use numbers for reference-style link definitions][1]

      Or leave it empty and use the [link text itself].

      URLs and URLs in angle brackets will automatically get turned into links.
      http://www.example.com and sometimes
      example.com (but not on Github, for example).

      Some text to show that the reference links can follow later.

      [arbitrary case-insensitive reference text]: https://www.mozilla.org
      [1]: http://slashdot.org
      [link text itself]: http://www.reddit.com

I'm an inline-style link

I'm an inline-style link with title

I'm a reference-style link

I'm a relative reference to a repository file

You can use numbers for reference-style link definitions

Or leave it empty and use the link text itself.

URLs and URLs in angle brackets will automatically get turned into links. http://www.example.com and sometimes example.com (but not on Github, for example).

Some text to show that the reference links can follow later.

Images

Here's our logo (hover to see the title text):

      Inline-style:
      ![alt text](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 1")

      Reference-style:
      ![alt text][logo]

      [logo]: https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 2"

Here's our logo (hover to see the title text):

Inline-style: alt text

Reference-style:

Code and Syntax Highlighting

Code blocks are part of the Markdown spec, but syntax highlighting isn't. However, many renderers -- like Github's and Markdown Here -- support syntax highlighting. Which languages are supported and how those language names should be written will vary from renderer to renderer. Markdown Here supports highlighting for dozens of languages (and not-really-languages, like diffs and HTTP headers); to see the complete list, and how to write the language names, see the highlight.js demo page.

Inline \`code\` has \`back-ticks around\` it.

Inline code has back-ticks around it.

Blocks of code are either fenced by lines with three back-ticks \`\`\`, or are indented with four spaces. I recommend only using the fenced code blocks -- they're easier and only they support syntax highlighting.

var s = "JavaScript syntax highlighting";
      alert(s);
s = "Python syntax highlighting"
      print s
No language indicated, so no syntax highlighting.
      But let's throw in a &lt;b&gt;tag&lt;/b&gt;.
var s = "JavaScript syntax highlighting";
      alert(s);
s = "Python syntax highlighting"
      print s
No language indicated, so no syntax highlighting in Markdown Here (varies on Github).
      But let's throw in a <b>tag</b>.

Tables

Tables aren't part of the core Markdown spec, but they are part of GFM and Markdown Here supports them. They are an easy way of adding tables to your email -- a task that would otherwise require copy-pasting from another application.

Colons can be used to align columns.

      | Tables        | Are           | Cool  |
      | ------------- |:-------------:| -----:|
      | col 3 is      | right-aligned | $1600 |
      | col 2 is      | centered      |   $12 |
      | zebra stripes | are neat      |    $1 |

      There must be at least 3 dashes separating each header cell.
      The outer pipes (|) are optional, and you don't need to make the
      raw Markdown line up prettily. You can also use inline Markdown.

      Markdown | Less | Pretty
      --- | --- | ---
      *Still* | \`renders\` | **nicely**
      1 | 2 | 3

Colons can be used to align columns.

TablesAreCool
col 3 isright-aligned$1600
col 2 iscentered$12
zebra stripesare neat$1

There must be at least 3 dashes separating each header cell. The outer pipes (|) are optional, and you don't need to make the raw Markdown line up prettily. You can also use inline Markdown.

MarkdownLessPretty
Stillrendersnicely
123

Blockquotes

> Blockquotes are very handy in email to emulate reply text.
      > This line is part of the same quote.

      Quote break.

      > This is a very long line that will still be quoted properly when it wraps. Oh boy let's keep writing to make sure this is long enough to actually wrap for everyone. Oh, you can *put* **Markdown** into a blockquote.

Blockquotes are very handy in email to emulate reply text. This line is part of the same quote.

Quote break.

This is a very long line that will still be quoted properly when it wraps. Oh boy let's keep writing to make sure this is long enough to actually wrap for everyone. Oh, you can put Markdown into a blockquote.

Inline HTML

You can also use raw HTML in your Markdown, and it'll mostly work pretty well.

<dl>
        <dt>Definition list</dt>
        <dd>Is something people use sometimes.</dd>

        <dt>Markdown in HTML</dt>
        <dd>Does *not* work **very** well. Use HTML <em>tags</em>.</dd>
      </dl>
Definition list
Is something people use sometimes.
Markdown in HTML
Does not work very well. Use HTML tags.

Horizontal Rule

Three or more...

      ---

      Hyphens

      ***

      Asterisks

      ___

      Underscores

Three or more...


Hyphens


Asterisks


Underscores

Line Breaks

My basic recommendation for learning how line breaks work is to experiment and discover -- hit <Enter> once (i.e., insert one newline), then hit it twice (i.e., insert two newlines), see what happens. You'll soon learn to get what you want. "Markdown Toggle" is your friend.

Here are some things to try out:

Here's a line for us to start with.

      This line is separated from the one above by two newlines, so it will be a *separate paragraph*.

      This line is also a separate paragraph, but...
      This line is only separated by a single newline, so it's a separate line in the *same paragraph*.

Here's a line for us to start with.

This line is separated from the one above by two newlines, so it will be a separate paragraph.

This line is also begins a separate paragraph, but... This line is only separated by a single newline, so it's a separate line in the same paragraph.

(Technical note: Markdown Here uses GFM line breaks, so there's no need to use MD's two-space line breaks.)

YouTube Videos

They can't be added directly but you can add an image with a link to the video like this:

<a href="http://www.youtube.com/watch?feature=player_embedded&v=YOUTUBE_VIDEO_ID_HERE
      " target="_blank"><img src="http://img.youtube.com/vi/YOUTUBE_VIDEO_ID_HERE/0.jpg"
      alt="IMAGE ALT TEXT HERE" width="240" height="180" border="10" /></a>

Or, in pure Markdown, but losing the image sizing and border:

[![IMAGE ALT TEXT HERE](http://img.youtube.com/vi/YOUTUBE_VIDEO_ID_HERE/0.jpg)](http://www.youtube.com/watch?v=YOUTUBE_VIDEO_ID_HERE)
", "result":

Markdown Kitchen Sink

This file is https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet plus a few fixes and additions. Used by obedm503/bootmark to demonstrate it's styling features.

This is intended as a quick reference and showcase. For more complete info, see John Gruber's original spec and the Github-flavored Markdown info page .

Note that there is also a Cheatsheet specific to Markdown Here if that's what you're looking for. You can also check out more Markdown tools .

Table of Contents

Headers Emphasis Lists Links Images Code and Syntax Highlighting Tables Blockquotes Inline HTML Horizontal Rule Line Breaks YouTube Videos

Headers

H1

H2

H3

H4

H5
H6

Alternatively, for H1 and H2, an underline-ish style:

Alt-H1

Alt-H2

H1

H2

H3

H4

H5
H6

Alternatively, for H1 and H2, an underline-ish style:

Alt-H1

Alt-H2

Emphasis

            
              Emphasis, aka italics, with *asterisks* or _underscores_.

      Strong emphasis, aka bold, with **asterisks** or __underscores__.

      Combined emphasis with **asterisks and _underscores_**.

      Strikethrough uses two tildes. ~~Scratch this.~~
            
          

Emphasis, aka italics, with asterisks or underscores .

Strong emphasis, aka bold, with asterisks or underscores .

Combined emphasis with asterisks and underscores .

Strikethrough uses two tildes. Scratch this.

Lists

(In this example, leading and trailing spaces are shown with with dots: ⋅)

            
              1. First ordered list item
      2. Another item
      ⋅⋅* Unordered sub-list.
      1. Actual numbers don't matter, just that it's a number
      ⋅⋅1. Ordered sub-list
      4. And another item.

      ⋅⋅⋅You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown).

      ⋅⋅⋅To have a line break without a paragraph, you will need to use two trailing spaces.⋅⋅
      ⋅⋅⋅Note that this line is separate, but within the same paragraph.⋅⋅
      ⋅⋅⋅(This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.)

      * Unordered list can use asterisks
      - Or minuses
      + Or pluses
            
          
  1. First ordered list item

  2. Another item

  • Unordered sub-list.

  1. Actual numbers don't matter, just that it's a number

  2. Ordered sub-list

  3. And another item.

    You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown).

    To have a line break without a paragraph, you will need to use two trailing spaces. Note that this line is separate, but within the same paragraph. (This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.)

  • Unordered list can use asterisks

  • Or minuses

  • Or pluses

Links

There are two ways to create links.

            
              [I'm an inline-style link](https://www.google.com)

      [I'm an inline-style link with title](https://www.google.com "Google's Homepage")

      [I'm a reference-style link][Arbitrary case-insensitive reference text]

      [I'm a relative reference to a repository file](../blob/master/LICENSE)

      [You can use numbers for reference-style link definitions][1]

      Or leave it empty and use the [link text itself].

      URLs and URLs in angle brackets will automatically get turned into links.
      http://www.example.com and sometimes
      example.com (but not on Github, for example).

      Some text to show that the reference links can follow later.

      [arbitrary case-insensitive reference text]: https://www.mozilla.org
      [1]: http://slashdot.org
      [link text itself]: http://www.reddit.com
            
          

I'm an inline-style link

I'm an inline-style link with title

I'm a reference-style link

I'm a relative reference to a repository file

You can use numbers for reference-style link definitions

Or leave it empty and use the link text itself .

URLs and URLs in angle brackets will automatically get turned into links. http://www.example.com and sometimes example.com (but not on Github, for example).

Some text to show that the reference links can follow later.

Images

            
              Here's our logo (hover to see the title text):

      Inline-style:
      ![alt text](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 1")

      Reference-style:
      ![alt text][logo]

      [logo]: https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 2"
            
          

Here's our logo (hover to see the title text):

Inline-style: alt text

Reference-style:

Code and Syntax Highlighting

Code blocks are part of the Markdown spec, but syntax highlighting isn't. However, many renderers -- like Github's and Markdown Here -- support syntax highlighting. Which languages are supported and how those language names should be written will vary from renderer to renderer. Markdown Here supports highlighting for dozens of languages (and not-really-languages, like diffs and HTTP headers); to see the complete list, and how to write the language names, see the highlight.js demo page .

            
              Inline \`code\` has \`back-ticks around\` it.
            
          

Inline code has back-ticks around it.

Blocks of code are either fenced by lines with three back-ticks \`\`\` , or are indented with four spaces. I recommend only using the fenced code blocks -- they're easier and only they support syntax highlighting.

            
              var s = "JavaScript syntax highlighting";
      alert(s);
            
          
            
              s = "Python syntax highlighting"
      print s
            
          
            
              No language indicated, so no syntax highlighting.
      But let's throw in a <b>tag</b>.
            
          
            
              var s = "JavaScript syntax highlighting";
      alert(s);
            
          
            
              s = "Python syntax highlighting"
      print s
            
          
            
              No language indicated, so no syntax highlighting in Markdown Here (varies on Github).
      But let's throw in a <b>tag</b>.
            
          

Tables

Tables aren't part of the core Markdown spec, but they are part of GFM and Markdown Here supports them. They are an easy way of adding tables to your email -- a task that would otherwise require copy-pasting from another application.

            
              Colons can be used to align columns.

      | Tables        | Are           | Cool  |
      | ------------- |:-------------:| -----:|
      | col 3 is      | right-aligned | $1600 |
      | col 2 is      | centered      |   $12 |
      | zebra stripes | are neat      |    $1 |

      There must be at least 3 dashes separating each header cell.
      The outer pipes (|) are optional, and you don't need to make the
      raw Markdown line up prettily. You can also use inline Markdown.

      Markdown | Less | Pretty
      --- | --- | ---
      *Still* | \`renders\` | **nicely**
      1 | 2 | 3
            
          

Colons can be used to align columns.

Tables Are Cool
col 3 is right-aligned $1600
col 2 is centered $12
zebra stripes are neat $1

There must be at least 3 dashes separating each header cell. The outer pipes (|) are optional, and you don't need to make the raw Markdown line up prettily. You can also use inline Markdown.

Markdown Less Pretty
Still renders nicely
1 2 3

Blockquotes

            
              > Blockquotes are very handy in email to emulate reply text.
      > This line is part of the same quote.

      Quote break.

      > This is a very long line that will still be quoted properly when it wraps. Oh boy let's keep writing to make sure this is long enough to actually wrap for everyone. Oh, you can *put* **Markdown** into a blockquote.
            
          

Blockquotes are very handy in email to emulate reply text. This line is part of the same quote.

Quote break.

This is a very long line that will still be quoted properly when it wraps. Oh boy let's keep writing to make sure this is long enough to actually wrap for everyone. Oh, you can put Markdown into a blockquote.

Inline HTML

You can also use raw HTML in your Markdown, and it'll mostly work pretty well.

            
              <dl>
        <dt>Definition list</dt>
        <dd>Is something people use sometimes.</dd>

        <dt>Markdown in HTML</dt>
        <dd>Does *not* work **very** well. Use HTML <em>tags</em>.</dd>
      </dl>
            
          
Definition list
Is something people use sometimes.
Markdown in HTML
Does not work very well. Use HTML tags .

Horizontal Rule

            
              Three or more...

      ---

      Hyphens

      ***

      Asterisks

      ___

      Underscores
            
          

Three or more...


Hyphens


Asterisks


Underscores

Line Breaks

My basic recommendation for learning how line breaks work is to experiment and discover -- hit <Enter> once (i.e., insert one newline), then hit it twice (i.e., insert two newlines), see what happens. You'll soon learn to get what you want. "Markdown Toggle" is your friend.

Here are some things to try out:

            
              Here's a line for us to start with.

      This line is separated from the one above by two newlines, so it will be a *separate paragraph*.

      This line is also a separate paragraph, but...
      This line is only separated by a single newline, so it's a separate line in the *same paragraph*.
            
          

Here's a line for us to start with.

This line is separated from the one above by two newlines, so it will be a separate paragraph .

This line is also begins a separate paragraph, but... This line is only separated by a single newline, so it's a separate line in the same paragraph .

(Technical note: Markdown Here uses GFM line breaks, so there's no need to use MD's two-space line breaks.)

YouTube Videos

They can't be added directly but you can add an image with a link to the video like this:

            
              <a href="http://www.youtube.com/watch?feature=player_embedded&v=YOUTUBE_VIDEO_ID_HERE
      " target="_blank"><img src="http://img.youtube.com/vi/YOUTUBE_VIDEO_ID_HERE/0.jpg"
      alt="IMAGE ALT TEXT HERE" width="240" height="180" border="10" /></a>
            
          

Or, in pure Markdown, but losing the image sizing and border:

            
              [![IMAGE ALT TEXT HERE](http://img.youtube.com/vi/YOUTUBE_VIDEO_ID_HERE/0.jpg)](http://www.youtube.com/watch?v=YOUTUBE_VIDEO_ID_HERE)
            
          
, } `) }) test('mdx jsx with unknown components are ignored', () => { // Note: In MDX, is treated as MDX JSX, not raw HTML // Unknown JSX components are ignored completely (including their content) const code = dedent` # Heading with JSX This is a paragraph with some JSX components.
This is a valid div
This unknown component should be ignored This span is valid Another unknown component content More text after JSX. ` const { html, result, errors } = render(code) // Check that valid HTML elements are present expect(html).toContain('
This is a valid div
') expect(html).toContain('') // Check that unknown components are completely ignored expect(html).not.toContain('CustomElement') expect(html).not.toContain('AnotherUnknown') expect(html).not.toContain('This unknown component should be ignored') expect(html).not.toContain('Another unknown component content') // Check that errors were generated for unknown components expect(errors).toHaveLength(2) expect(errors[0].message).toContain('Unsupported jsx component CustomElement') expect(errors[1].message).toContain('Unsupported jsx component AnotherUnknown') expect(result).toMatchInlineSnapshot(`

Heading with JSX

This is a paragraph with some JSX components.

This is a valid div
This span is valid

More text after JSX.

`) }) test('code block rendering', () => { const code = dedent` ` expect( render(dedent` \`\`\`typescript const x = 1; \`\`\` \`\`\`invalid-language const y = 2; \`\`\` `), ).toMatchInlineSnapshot(` { "errors": [], "html": "
const x = 1;
const y = 2;
", "result":
            
              const x = 1;
            
          
            
              const y = 2;
            
          
, } `) }) test('code is not wrapped by p', () => { const code = ` --- title: createSearchParams --- # createSearchParams [MODES: framework, data, declarative] ## Summary [Reference Documentation ↗](https://api.reactrouter.com/v7/functions/react_router.createSearchParams.html) Creates a URLSearchParams object using the given initializer. This is identical to \`new URLSearchParams(init)\` except it also supports arrays as values in the object form of the initializer instead of just strings. This is convenient when you need multiple values for a given key, but don't want to use an array initializer. For example, instead of: \`\`\`tsx let searchParams = new URLSearchParams([ ["sort", "name"], ["sort", "price"], ]); \`\`\` you can do: \`\`\` let searchParams = createSearchParams({ sort: ['name', 'price'] }); \`\`\` ## Signature \`\`\`tsx createSearchParams(init): URLSearchParams \`\`\` ## Params ### init [modes: framework, data, declarative] _No documentation_ ` const jsx = render(code) expect(jsx.result).toMatchInlineSnapshot(`

title: createSearchParams

createSearchParams

[MODES: framework, data, declarative]

Summary

Reference Documentation ↗

Creates a URLSearchParams object using the given initializer.

This is identical to new URLSearchParams(init) except it also supports arrays as values in the object form of the initializer instead of just strings. This is convenient when you need multiple values for a given key, but don't want to use an array initializer.

For example, instead of:

          
            let searchParams = new URLSearchParams([
        ["sort", "name"],
        ["sort", "price"],
      ]);
          
        

you can do:

          
            let searchParams = createSearchParams({
        sort: ['name', 'price']
      });
          
        

Signature

          
            createSearchParams(init): URLSearchParams
          
        

Params

init

[modes: framework, data, declarative]

No documentation

`) }) test('component props schema validation with zod', () => { const HeadingSchema = z.object({ level: z.number().min(1).max(6), title: z.string().optional(), }) const CardsSchema = z.object({ count: z.number().positive(), variant: z.enum(['default', 'outline']).optional(), }) const componentPropsSchema: ComponentPropsSchema = { Heading: HeadingSchema, Cards: CardsSchema, } const code = dedent` Valid heading Valid cards Invalid heading - level too high Invalid cards - negative count Invalid cards - wrong type ` expect(render(code, componentPropsSchema)).toMatchInlineSnapshot(` { "errors": [ { "line": 5, "message": "Invalid props for component "Heading" at "level": Number must be less than or equal to 6", "schemaPath": "level", }, { "line": 7, "message": "Invalid props for component "Cards" at "count": Number must be greater than 0", "schemaPath": "count", }, { "line": 9, "message": "Invalid props for component "Cards" at "count": Expected number, received string", "schemaPath": "count", }, ], "html": "

Valid heading

Valid cards

Invalid heading - level too high

Invalid cards - negative count
Invalid cards - wrong type
", "result": Valid heading Valid cards Invalid heading - level too high Invalid cards - negative count Invalid cards - wrong type , } `) }) test('mdx expressions evaluation', () => { expect( render(dedent` # Expression Test Simple math: {1 + 2} Inside JSX: {3 * 4} Boolean: {true} String concat: {"hello" + " world"} `), ).toMatchInlineSnapshot(` { "errors": [], "html": "

Expression Test

Simple math: 3

Inside JSX: 12

Boolean: String concat: hello world

", "result":

Expression Test

Simple math: 3

Inside JSX: 12

Boolean: true String concat: hello world

, } `) }) test('mdx expressions with unsupported functions', () => { expect( render(dedent` Math function: {Math.max(5, 10)} Console: {console.log("test")} `), ).toMatchInlineSnapshot(` { "errors": [ { "line": 1, "message": "Failed to evaluate expression: Math.max(5, 10). Functions are not supported", }, { "line": 2, "message": "Failed to evaluate expression: console.log("test"). Functions are not supported", }, ], "html": "

Math function: Console:

", "result":

Math function: Console:

, } `) }) test('schema validation without errors', () => { const HeadingSchema = z.object({ level: z.number().min(1).max(6), title: z.string().optional(), }) const componentPropsSchema: ComponentPropsSchema = { Heading: HeadingSchema, } const code = dedent` Valid heading Another valid heading ` expect(render(code, componentPropsSchema)).toMatchInlineSnapshot(` { "errors": [], "html": "

Valid heading

Another valid heading

", "result": Valid heading Another valid heading , } `) }) test('component without schema should not be validated', () => { const HeadingSchema = z.object({ level: z.number().min(1).max(6), }) const componentPropsSchema: ComponentPropsSchema = { Heading: HeadingSchema, } const code = dedent` Valid heading with schema Cards without schema - should not be validated ` expect(render(code, componentPropsSchema)).toMatchInlineSnapshot(` { "errors": [], "html": "

Valid heading with schema

Cards without schema - should not be validated
", "result": Valid heading with schema Cards without schema - should not be validated , } `) }) test('validation error includes schema path', () => { const ComplexSchema = z.object({ user: z.object({ name: z.string(), age: z.number().min(0), }), settings: z.object({ theme: z.enum(['light', 'dark']), }), }) const componentPropsSchema: ComponentPropsSchema = { Heading: ComplexSchema, } const code = dedent` Complex validation ` expect(render(code, componentPropsSchema)).toMatchInlineSnapshot(` { "errors": [ { "line": 1, "message": "Invalid props for component "Heading" at "user.age": Number must be greater than or equal to 0", "schemaPath": "user.age", }, { "line": 1, "message": "Invalid props for component "Heading" at "settings.theme": Invalid enum value. Expected 'light' | 'dark', received 'invalid'", "schemaPath": "settings.theme", }, ], "html": "

Complex validation

", "result": Complex validation , } `) }) test('mdxJsxExpressionAttribute spread syntax', () => { expect( render(dedent` Content with spread `), ).toMatchInlineSnapshot(` { "errors": [], "html": "

Content with spread

", "result":

Content with spread

, } `) }) test('mdxJsxExpressionAttribute complex spread cases', () => { expect( render(dedent` Complex spread test Multiple spreads `), ).toMatchInlineSnapshot(` { "errors": [], "html": "

Complex spread test

Multiple spreads

", "result":

Complex spread test

Multiple spreads

, } `) }) test('mdxJsxExpressionAttribute edge cases', () => { expect( render(dedent` Empty spread Null/undefined Complex types `), ).toMatchInlineSnapshot(` { "errors": [ { "line": 3, "message": "Failed to evaluate expression attribute: ...{null: null, undefined: undefined}. undefined is undefined", }, ], "html": "

Empty spread

Null/undefined

Complex types

", "result": Empty spread Null/undefined Complex types , } `) }) test('ESM imports from https URLs', () => { const code = dedent` import Button from 'https://esm.sh/some-button-component' import { Card, Modal } from 'https://esm.sh/some-ui-library' # Hello Content inside card Modal content ` const mdast = mdxParse(code) const visitor = new MdastToJsx({ markdown: code, mdast, components, allowClientEsmImports: true }) const result = visitor.run() // Check that imports were parsed correctly expect(visitor.esmImports.size).toBe(3) expect(visitor.esmImports.get('Button')).toBe('https://esm.sh/some-button-component') expect(visitor.esmImports.get('Card')).toBe('https://esm.sh/some-ui-library#Card') expect(visitor.esmImports.get('Modal')).toBe('https://esm.sh/some-ui-library#Modal') // Since these are dynamic imports that only work on client, the server render should return null const html = renderToStaticMarkup(result) expect(html).toMatchInlineSnapshot(`"

Hello

"`) expect(visitor.errors).toEqual([]) }) test('ESM imports error handling', () => { const code = dedent` import Button from 'file:///local/path' import Component from './relative/path' # Test Relative import should not work ` const mdast = mdxParse(code) const visitor = new MdastToJsx({ markdown: code, mdast, components, allowClientEsmImports: true }) const result = visitor.run() // Only https imports should be processed expect(visitor.esmImports.size).toBe(0) // Should have 4 errors: 2 for invalid imports, 2 for unsupported components expect(visitor.errors.length).toBe(4) // First two errors are for invalid imports expect(visitor.errors[0].message).toContain('Invalid import URL') expect(visitor.errors[1].message).toContain('Invalid import URL') // Last two errors are for unsupported components expect(visitor.errors[2].message).toContain('Unsupported jsx component Button') expect(visitor.errors[3].message).toContain('Unsupported jsx component Component') }) test('jsx components in attributes', () => { const code = dedent` # JSX Components in Attributes 👋} level={1}> Hello World Item 1}> Some content ` const { result, errors, html } = render(code) // Should not have any errors expect(errors).toMatchInlineSnapshot(`[]`) // Should render correctly expect(html).toMatchInlineSnapshot(`"

JSX Components in Attributes

Hello World

Some content

"`) expect(result).toMatchInlineSnapshot(`

JSX Components in Attributes

👋 } level={1} >

Hello World

Item 1 } >

Some content

`) }) test('jsx components in attributes with ESM imports', () => { const code = dedent` import Button from 'https://esm.sh/some-button-component' import { Icon } from 'https://esm.sh/some-icon-library' # ESM Components in Attributes } level={1}> Hello World Click me}> Some content ` const { result, errors, html } = render(code, undefined, true) // Should not have any errors expect(errors).toMatchInlineSnapshot(`[]`) // Should render correctly - ESM components should be wrapped in DynamicEsmComponent expect(html).toMatchInlineSnapshot(`"

ESM Components in Attributes

Hello World

Some content

"`) expect(result).toMatchInlineSnapshot(`

ESM Components in Attributes

} level={1} >

Hello World

Click me } >

Some content

`) }) test('ESM imports disabled by default', () => { const code = dedent` import Button from 'https://esm.sh/some-button-component' # Test Default Behavior ` const { result, errors, html } = render(code) // No allowClientEsmImports flag // ESM imports should not be processed when disabled const mdast = mdxParse(code) const visitor = new MdastToJsx({ markdown: code, mdast, components }) // Default allowClientEsmImports: false expect(visitor.esmImports.size).toBe(0) // Should have error for unsupported component expect(errors.length).toBeGreaterThan(0) expect(errors.some(e => e.message.includes('Unsupported jsx component Button'))).toBe(true) // Should render heading but not the button expect(html).toMatchInlineSnapshot(`"

Test Default Behavior

"`) }) test("jsx components in attributes error handling", () => { const code = dedent` # Error Handling Test } level={1}> Hello World ` const { result, errors, html } = render(code) // Should have an error for the unsupported component expect(errors).toMatchInlineSnapshot(` [ { "line": 3, "message": "Unsupported jsx component UnsupportedComponent in attribute", }, { "line": 3, "message": "Failed to evaluate expression attribute: icon={}. visitor "JSXElement" is not supported", }, { "line": 3, "message": "Expressions in jsx prop not evaluated: (icon={})", }, ] `) // Should still render the rest of the content expect(html).toMatchInlineSnapshot(`"

Error Handling Test

Hello World

"`) expect(result).toMatchInlineSnapshot(`

Error Handling Test

Hello World

`) }) test('addMarkdownLineNumbers adds data-markdown-line attributes', () => { const code = dedent` # Hello World This is a **paragraph** with *emphasis*. Custom component - List item 1 - List item 2 | Column 1 | Column 2 | |----------|----------| | Cell 1 | Cell 2 | ` const { result, errors, html } = render(code, undefined, false, true) // Should not have any errors expect(errors).toMatchInlineSnapshot(`[]`) // Check that data-markdown-line attributes are present in HTML expect(html).toContain('data-markdown-line="1"') expect(html).toContain('data-markdown-line="3"') expect(html).toContain('data-markdown-line="9"') expect(result).toMatchInlineSnapshot(`

Hello World

This is a paragraph with emphasis .

Custom component

  • List item 1

  • List item 2

Column 1 Column 2
Cell 1 Cell 2
`) }) test('addMarkdownLineNumbers works with custom MDX components', () => { const code = dedent` # Regular Heading Custom component on line 3 Regular paragraph. Another custom component on line 9 ` const { result, errors, html } = render(code, undefined, false, true) // Should not have any errors expect(errors).toMatchInlineSnapshot(`[]`) // Check that custom components have line numbers expect(html).toContain('data-markdown-line="3"') expect(html).toContain('data-markdown-line="9"') expect(result).toMatchInlineSnapshot(`

Regular Heading

Custom component on line 3

Regular paragraph.

Another custom component on line 9

`) }) test('jsx component with complex array props should show clear error message', () => { const code = dedent` ` const { errors } = render(code) // Should have error with original error message included expect(errors.length).toBeGreaterThan(0) // Find the error that contains the expression evaluation message const expressionError = errors.find(err => err.message.includes('Failed to evaluate expression attribute: items={invalidFunction()}') ) expect(expressionError).toBeDefined() expect(expressionError!.message).toContain('Functions are not supported') expect(expressionError!.line).toBe(1) }) test('override renderNode to wrap bold text in colored span', () => { const code = dedent` This is **bold text** and this is regular text. Another line with **more bold** content. ` const mdast = mdxParse(code) const visitor = new MdastToJsx({ markdown: code, mdast, components, renderNode: (node, transform) => { if (node.type === 'strong') { return ( {node.children?.map(child => transform(child))} ) } // Return undefined to use default rendering return undefined } }) const result = visitor.run() const html = renderToStaticMarkup(result) expect(html).toMatchInlineSnapshot(`"

This is bold text and this is regular text.

Another line with more bold content.

"`) }) test("skip unknown elements in raw HTML content", () => { const { html } = render(` Some text before

Valid paragraph

This content should be preserved
Valid div
Another preserved content Some text after `); expect(html).toMatchInlineSnapshot(`"

Some text before

Some text after

"`); }); test("skip unknown elements in complex nested HTML structures", () => { const { html } = render(` # Main Title

Article Title

This paragraph should be preserved

A famous quote

- Author Name from a book published in 2024

Nested Heading

  • First item with nested code
  • Second item
  • Third item should show
## Another Section
Header 2 content
Header 1
Cell 1 Cell 2
`); expect(html).toMatchInlineSnapshot(`"

Main Title

Article Title

A famous quote

Another Section

"`); });