diff --git a/product-guide/authoring/mdx-component.mdx b/product-guide/authoring/mdx-component.mdx new file mode 100644 index 0000000..b1d5f67 --- /dev/null +++ b/product-guide/authoring/mdx-component.mdx @@ -0,0 +1,69 @@ +--- +title: MDX component +description: Wrap markdown sections in JSX with the component while headings, code fences, and anchors keep working. +--- + +The `` component renders its children as regular markdown. Content between the tags compiles exactly like markdown at the root of a page. Headings, code fences, tables, and callouts all work. + +Use `` when you need to place a markdown section inside JSX. The most common case is conditional content, such as a ternary expression. Without ``, markdown inside a JSX expression is treated as raw JSX and you would have to rewrite it element by element. + +## Basic usage + +Wrap any markdown section in `` tags: + +````mdx + + + ## Getting started + + Install the CLI, then run `init` to scaffold a project. + + ```bash + product init my-project + ``` + +```` + +The content renders the same as if it were written directly on the page. + +## Conditional markdown + +`` works inside `{...}` expressions, including ternaries. The markdown in each branch compiles at build time: + +```mdx +export const platform = "cloud" + +{platform === "cloud" ? +## Cloud setup + +Create a workspace from the dashboard, then invite your team. + : +## Self-hosted setup + +Download the installer and run it on your own infrastructure. +} +``` + +Only the branch that matches renders on the page. You can also nest `` inside another `` block, and snippets work inside `` content. + +## Heading anchors + +Headings inside `` get anchor IDs, so readers can link to them directly. To set a custom anchor, append `{#id}` to the heading: + +```mdx +{showAdvanced ? + ## Advanced options {#advanced} + + Tune these settings only after completing the basic setup. + : null} +``` + +Inside an `` block, `## Title {#id}` headings work at any indentation. This matters because authors often indent the body of an expression-level `` by four or more spaces, which would normally turn the line into an indented code block. Code fences inside the block are still treated as code and never become headings. + +## Table of contents + +Headings inside `` blocks merge into the page's table of contents in document order, alongside the page's own headings. Their anchor IDs are reserved so later headings on the page never reuse them. + + + Headings from every `` branch of a conditional appear in the table of contents, including branches that do not render. + diff --git a/product-guide/docs.json b/product-guide/docs.json index 635e01f..f12de09 100644 --- a/product-guide/docs.json +++ b/product-guide/docs.json @@ -63,6 +63,14 @@ "analytics/reports/scheduled-reports" ] }, + { + "group": "Authoring", + "icon": "pen-line", + "expanded": true, + "pages": [ + "authoring/mdx-component" + ] + }, { "group": "Integrations", "icon": "plug",