diff --git a/README.md b/README.md index cb7a7c15..7871c31f 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,7 @@ The SvelteMarkdown component accepts the following options: - `source` - _string_ The Markdown source to be parsed. - `renderers` - _object (optional)_ An object where the keys represent a node type and the value is a Svelte component. This object will be merged with the default renderers. For now you can check how the default renderers are written in the source code at `src/renderers`. - `options` - _object (optional)_ An object containing [options for Marked](https://marked.js.org/using_advanced#options) +- `use` - _object (optional)_ An object containing [extensions for Marked]([marked.use](https://marked.js.org/using_pro#use)) ## Events diff --git a/src/SvelteMarkdown.svelte b/src/SvelteMarkdown.svelte index 98edadd8..ef42bbb2 100644 --- a/src/SvelteMarkdown.svelte +++ b/src/SvelteMarkdown.svelte @@ -1,13 +1,14 @@ + +{message}: {value} diff --git a/tests/extensions.spec.js b/tests/extensions.spec.js new file mode 100644 index 00000000..38ddcee2 --- /dev/null +++ b/tests/extensions.spec.js @@ -0,0 +1,44 @@ +import '@testing-library/jest-dom/extend-expect' + +import { render, screen } from '@testing-library/svelte' + +import SvelteMarkdown from '../src/SvelteMarkdown.svelte' +import TestRenderer from './TestRenderer.svelte' + +describe('testing extensions', () => { + beforeAll(() => { + console.warn = jest.fn() + }) + + test('renders a custom token with an extension and custom component', () => { + const testTokenizerExtension = { + name: 'test', + level: 'inline', + start(src) { + return src.match(/\[\[/).index + }, + tokenizer(src) { + const rule = /^\[\[test(?:(?=.*?\svalue="(.*?)".*?|.*)(?=.*?\smessage="(.*?)(?test message: 5') + }) +}) diff --git a/types/index.d.ts b/types/index.d.ts index 82be46fe..1af0b092 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,4 +1,5 @@ import type { + marked, MarkedExtension as MarkedConfig, Tokens, TokensList, @@ -71,6 +72,11 @@ type Props = { */ renderers?: Partial + /** + * Parameters for the function [marked.use](https://marked.js.org/using_pro#use) + */ + use?: Omit[] + /** * Options for [marked](https://marked.js.org/using_advanced#options) */