Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class Markdown implements OnChanges {
@Input() value?: string | MarkdownDocumentType

/** Parser options (excluding plugins) */
@Input() options: Exclude<ParserOptions, 'plugins'> = {}
@Input() options: Omit<ParserOptions, 'plugins'> = {}

/** Additional plugins to use */
@Input() plugins: ParserOptions['plugins'] = []
Expand Down
2 changes: 1 addition & 1 deletion packages/comark-react/src/components/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface MarkdownProps {
/**
* Parser options (excluding plugins)
*/
options?: Exclude<ParserOptions, 'plugins'>
options?: Omit<ParserOptions, 'plugins'>

/**
* Parser to use instead of one resolved from `options` and `plugins`
Expand Down
2 changes: 1 addition & 1 deletion packages/comark-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function defineMarkdownComponent(config: DefineMarkdownComponentOptions =
} = config

const MarkdownComponent: React.FC<MarkdownProps> = (props) => {
const mergedOptions: Exclude<ParserOptions, 'plugins'> = {
const mergedOptions: Omit<ParserOptions, 'plugins'> = {
...parseOptions,
...props.options,
}
Expand Down
2 changes: 1 addition & 1 deletion packages/comark-svelte/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface MarkdownDocumentProps {
export interface MarkdownProps {
/** The markdown content to parse and render, or a pre-parsed MarkdownDocument */
value?: string | MarkdownDocument
options?: Exclude<ParserOptions, 'plugins'>
options?: Omit<ParserOptions, 'plugins'>
plugins?: ComarkPlugin[]

/**
Expand Down
214 changes: 119 additions & 95 deletions packages/comark-vue/src/components/Markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface MarkdownProps {
/**
* Parser options (excluding plugins)
*/
options?: Exclude<ParserOptions, 'plugins'>
options?: Omit<ParserOptions, 'plugins'>

/**
* Additional plugins to use
Expand Down Expand Up @@ -68,10 +68,125 @@ export interface MarkdownProps {
* Additional data to pass to the renderer
*/
data?: Record<string, unknown>

/**
* Document key used to subscribe to live updates via `globalThis.comarkContext`
*/
documentKey?: string
}

type MarkdownComponent = ReturnType<typeof defineComponent<MarkdownProps>>

/**
* Runtime prop declarations for `<Markdown>`.
*
* Exported so `defineMarkdownComponent` can reuse them verbatim instead of
* hand-copying the table, which had drifted: `value` was declared `String`
* only, and `data` and `documentKey` were missing entirely.
*/
export const markdownProps = {
/**
* The markdown content to parse and render, or a pre-parsed MarkdownDocument
*/
value: {
type: [String, Object] as PropType<string | MarkdownDocumentType>,
default: undefined,
},

/**
* Parser options
*/
options: {
type: Object as PropType<Omit<ParserOptions, 'plugins'>>,
default: () => ({}),
},

/**
* Additional plugins to use
*/
plugins: {
type: Array as PropType<ParserOptions['plugins']>,
default: () => [],
},

/**
* Parser to use instead of one resolved from `options` and `plugins`
*/
parser: {
type: Function as PropType<ComarkParseFn>,
default: undefined,
},

/**
* Strip wrapper tags from the top level of the document — shorthand for
* `options.unwrap`. `true` unwraps `<p>`; a space-separated string or array
* unwraps the listed tags.
*/
unwrap: {
type: [Boolean, String, Array] as PropType<boolean | string | string[]>,
default: false,
},

/**
* Custom component mappings for element tags
* Key: tag name (e.g., 'h1', 'p', 'MyComponent')
* Value: Vue component
*/
components: {
type: Object as PropType<Record<string, any>>,
default: () => ({}),
},

/**
* Dynamic component resolver function
* Used to resolve components that aren't in the components map
*/
componentsManifest: {
type: Function as PropType<ComponentManifest>,
default: undefined,
},

/**
* Enable streaming mode with stream-specific components
*/
streaming: {
type: Boolean as PropType<boolean>,
default: false,
},

/**
* If document has a <!-- more --> comment, only render the content before the comment
*/
summary: {
type: Boolean as PropType<boolean>,
default: false,
},

/**
* If caret is true, a caret will be appended to the document's last text node
*/
caret: {
type: [Boolean, Object] as PropType<boolean | { class: string }>,
default: false,
},

/**
* Additional data to pass to the renderer
*/
data: {
type: Object as PropType<Record<string, unknown>>,
default: () => ({}),
},

/**
* Document key used to subscribe to live updates via `globalThis.comarkContext`
*/
documentKey: {
type: String as PropType<string>,
default: undefined,
},
} as const

/**
* Markdown component
*
Expand Down Expand Up @@ -107,100 +222,7 @@ type MarkdownComponent = ReturnType<typeof defineComponent<MarkdownProps>>
export const Markdown: MarkdownComponent = defineComponent({
name: 'Markdown',

props: {
/**
* The markdown content to parse and render, or a pre-parsed MarkdownDocument
*/
value: {
type: [String, Object] as PropType<string | MarkdownDocumentType>,
default: undefined,
},

/**
* Parser options
*/
options: {
type: Object as PropType<Exclude<ParserOptions, 'plugins'>>,
default: () => ({}),
},

/**
* Additional plugins to use
*/
plugins: {
type: Array as PropType<ParserOptions['plugins']>,
default: () => [],
},

/**
* Parser to use instead of one resolved from `options` and `plugins`
*/
parser: {
type: Function as PropType<ComarkParseFn>,
default: undefined,
},

/**
* Strip wrapper tags from the top level of the document — shorthand for
* `options.unwrap`. `true` unwraps `<p>`; a space-separated string or array
* unwraps the listed tags.
*/
unwrap: {
type: [Boolean, String, Array] as PropType<boolean | string | string[]>,
default: false,
},

/**
* Custom component mappings for element tags
* Key: tag name (e.g., 'h1', 'p', 'MyComponent')
* Value: Vue component
*/
components: {
type: Object as PropType<Record<string, any>>,
default: () => ({}),
},

/**
* Dynamic component resolver function
* Used to resolve components that aren't in the components map
*/
componentsManifest: {
type: Function as PropType<ComponentManifest>,
default: undefined,
},

/**
* Enable streaming mode with stream-specific components
*/
streaming: {
type: Boolean as PropType<boolean>,
default: false,
},

/**
* If document has a <!-- more --> comment, only render the content before the comment
*/
summary: {
type: Boolean as PropType<boolean>,
default: false,
},

/**
* If caret is true, a caret will be appended to the document's last text node
*/
caret: {
type: [Boolean, Object] as PropType<boolean | { class: string }>,
default: false,
},

/**
* Additional data to pass to the renderer
*/
data: {
type: Object as PropType<Record<string, unknown>>,
default: () => ({}),
},
},
props: markdownProps,

async setup(props, ctx) {
const markdown = computed(() => {
Expand Down Expand Up @@ -269,6 +291,7 @@ export const Markdown: MarkdownComponent = defineComponent({
class: props.streaming ? 'comark-stream' : '',
caret: props.caret,
data: props.data,
documentKey: props.documentKey,
})
}

Expand All @@ -281,6 +304,7 @@ export const Markdown: MarkdownComponent = defineComponent({
class: props.streaming ? 'comark-stream' : '',
caret: props.caret,
data: props.data,
documentKey: props.documentKey,
})
}
},
Expand Down
Loading
Loading