How to Globally override HTML element with components? #2271
-
Hi community, I'm building a personal site using MDX integration with Astro, I would like to globally replace some HTML elements like import H1 from '../components/H1.astro'
import H2 from '../components/H2.astro'
import H3 from '../components/H3.astro'
import P from '../components/P.astro'
import Ul from '../components/Ul.astro'
import Ol from '../components/Ol.astro'
import Pre from '../components/Pre.astro'
// ... more components
// this is the only way I know to replace them
// but I need to do it for every file
export const components = {
h1: H1
h2: H2
h3: H3
p: P
ul: Ul
ol: Ol
pre: Pre
// more replacement
}
# This is just a example
Defining some content in MDX as markdown syntax.
- With some elements I was wondering if there is a better way to do this, one where I can avoid having to import and export for each file? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hey! a) A solution likely relates more to your framework, so best to ask Astro folks. |
Beta Was this translation helpful? Give feedback.
Hey!
a) A solution likely relates more to your framework, so best to ask Astro folks.
b)
export const components
is not an MDX thing, if that works, that’s Astroc) In MDX, you can pass components to components: https://mdxjs.com/docs/using-mdx/. See particularly the section on “Components”