Usage for shortcodes #153
-
Hi! I'm excited to try Iles for my project and I'm trying to wrap my head around Shortcodes. I'm most likely not doing it right, but I don't see a correct way to do this either. I'm referring to: https://iles.pages.dev/guide/markdown#override-components-globally. I wish to provide a custom component for the I've this in my import {defineApp} from 'iles'
import CustomPre from '~/components/CustomPre.vue'
export default defineApp({
mdxComponents: {
pre: CustomPre
}
}) Now my question is, how do I access the content of the The documentation mentions we can use custom components, but doesn't mention how to actually access the data. I tried referring to: #33, but |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
Hi Hrishikesh! Have you seen this example in the docs site? The registered Vue components are able to access props, If you want the content, try |
Beta Was this translation helpful? Give feedback.
-
Sorry, I should have checked that. After spending another hour at this, now I realised that the HTML attribute name is itself the prop name. So for |
Beta Was this translation helpful? Give feedback.
-
For future explorers, I was able to get the text inside the <script
setup>
import {useSlots} from 'vue'
const code = useSlots().default()[0].children.match(/<code[^>]*>([\s\S]*?)<\/code>/)[1]
</script> |
Beta Was this translation helpful? Give feedback.
-
@hrishikesh-k I ran into this same issue and found a nice solution: https://www.npmjs.com/package/remark-mdx-code-meta. You can add this to your ```js showLineNumbers filename="index.js" This code block, when used with that Remark plugin, exposes these props: {
"showLineNumbers": true,
"filename": "index.js"
} So that means you can use props like this and it will work like expected in a Vue component: defineProps<{
showLineNumbers?: boolean;
filename?: string;
}>(); |
Beta Was this translation helpful? Give feedback.
Hi Hrishikesh!
Have you seen this example in the docs site?
The registered Vue components are able to access props,
$attrs
, and$slots
as usual.If you want the content, try
useSlots
inscripts setup
,<slot>
, or$slots
in the template.