
Product
Socket Now Supports pylock.toml Files
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
@cartamd/plugin-component
Advanced tools
This plugin adds support for mapping certain elements to **components** inside the editor.
This plugin adds support for mapping certain elements to components inside the editor.
npm i @cartamd/plugin-component
The first thing to do is to map certain elements(nodes) to their corresponding components. For example, if you want to use a custom renderer for images:
<!-- Image.svelte -->
<script>
export let src;
export let alt;
</script>
<!-- Your custom component... -->
<img {src} {alt} />
import { Carta } from 'carta-md';
import { component } from '@cartamd/plugin-component';
import { svelte, initializeComponents } from '@cartamd/plugin-component/svelte';
import Image from './Image.svelte';
const mapped = [svelte('img', Image) /* other components ... */];
const carta = new Carta({
extensions: [component(mapped, initializeComponents)]
// ...
});
You can use custom logic when selecting which nodes to map:
import { svelteCustom } from '@cartamd/plugin-component/svelte';
import MyComponent from '...';
const mapped = [
svelteCustom(
'my-component-id',
(node) => {
// Do something with the node to determine whether to replace it
},
MyComponent
) /* other components ... */
];
<slot />
To render children, you need to use a custom <Slot />
component:
<!-- Heading.svelte -->
<script>
import { Slot } from '@cartamd/plugin-component/svelte';
</script>
<h1>
<Slot />
</h1>
When pre-rendering content on the server (using the <PreRendered>
component), the components will not be mounted by default. You need to use the initializeComponents
function yourself.
<script>
import { initializeComponents } from '@cartamd/plugin-component/svelte';
import { onMount } from 'svelte';
// ...
export let data;
let container;
// Needs access to the mapped components
const mapped = [
/* ... */
];
onMount(() => {
initializeComponents(mapped, container);
});
</script>
<div bind:this={container}>
<PreRendered html={data.html} />
</div>
<svelte:head>
is not available during server-side rendering.FAQs
This plugin adds support for mapping certain elements to **components** inside the editor.
The npm package @cartamd/plugin-component receives a total of 19 weekly downloads. As such, @cartamd/plugin-component popularity was classified as not popular.
We found that @cartamd/plugin-component demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
Security News
Research
Socket uncovered two npm packages that register hidden HTTP endpoints to delete all files on command.
Research
Security News
Malicious Ruby gems typosquat Fastlane plugins to steal Telegram bot tokens, messages, and files, exploiting demand after Vietnam’s Telegram ban.