Comparing version 2.1.0 to 2.1.1
@@ -1,2 +0,2 @@ | ||
import { type MarkedExtension } from 'marked'; | ||
import { Marked, type MarkedExtension } from 'marked'; | ||
import type { CartaHistoryOptions } from './history'; | ||
@@ -11,2 +11,3 @@ import { CartaInput } from './input'; | ||
import type { ShjLanguageDefinition } from '@speed-highlight/core/index'; | ||
import { type GfmHeadingIdOptions } from 'marked-gfm-heading-id'; | ||
declare class CustomEvent<T> extends Event { | ||
@@ -82,2 +83,12 @@ detail: T; | ||
sanitizer?: (html: string) => string; | ||
/** | ||
* marked-mangle. | ||
* @default true | ||
*/ | ||
mangle?: false; | ||
/** | ||
* marked-gfm-heading-ids options. | ||
* Use `false` to disable it. | ||
*/ | ||
gfmHeadingId?: GfmHeadingIdOptions | false; | ||
} | ||
@@ -138,2 +149,4 @@ /** | ||
readonly dispatcher: EventTarget; | ||
readonly markedAsync: Marked; | ||
readonly markedSync: Marked; | ||
private _input; | ||
@@ -144,2 +157,3 @@ private _renderer; | ||
constructor(options?: CartaOptions | undefined); | ||
private useMarkedExtension; | ||
/** | ||
@@ -146,0 +160,0 @@ * Render markdown to html asynchronously. |
@@ -1,2 +0,2 @@ | ||
import { marked } from 'marked'; | ||
import { Marked } from 'marked'; | ||
import { CartaInput } from './input'; | ||
@@ -8,2 +8,4 @@ import { defaultKeyboardShortcuts } from './shortcuts'; | ||
import { loadCustomLanguage, highlight, highlightAutodetect } from './highlight.js'; | ||
import { mangle } from 'marked-mangle'; | ||
import { gfmHeadingId } from 'marked-gfm-heading-id'; | ||
// Node does not implement CustomEvent until v19, so we | ||
@@ -29,2 +31,4 @@ // "declare" it ourself for backward compatibility. | ||
dispatcher = new EventTarget(); | ||
markedAsync = new Marked(); | ||
markedSync = new Marked(); | ||
_input; | ||
@@ -71,2 +75,15 @@ _renderer; | ||
this.prefixes.push(...defaultPrefixes.filter((prefix) => options?.disablePrefixes === true ? false : !options?.disablePrefixes?.includes(prefix.id))); | ||
// Load default marked extensions | ||
if (options?.mangle !== false) { | ||
this.useMarkedExtension(mangle()); | ||
} | ||
else { | ||
this.useMarkedExtension({ mangle: false }); | ||
} | ||
if (options?.gfmHeadingId !== false) { | ||
this.useMarkedExtension(gfmHeadingId(options?.gfmHeadingId)); | ||
} | ||
else { | ||
this.useMarkedExtension({ headerIds: false }); | ||
} | ||
// Load marked extensions | ||
@@ -77,3 +94,5 @@ const markedExtensions = this.options?.extensions | ||
if (markedExtensions) | ||
marked.use(...markedExtensions); | ||
markedExtensions.forEach((ext) => { | ||
this.useMarkedExtension(ext); | ||
}); | ||
// Load highlight custom language | ||
@@ -98,2 +117,7 @@ import('./shj.js') | ||
} | ||
useMarkedExtension(exts) { | ||
this.markedAsync.use(exts); | ||
if (!exts.async) | ||
this.markedSync.use(exts); | ||
} | ||
/** | ||
@@ -105,3 +129,5 @@ * Render markdown to html asynchronously. | ||
async render(markdown) { | ||
const dirty = await marked.parse(markdown, { async: true }); | ||
const dirty = await this.markedAsync.parse(markdown, { async: true }); | ||
if (!dirty) | ||
return ''; | ||
this.dispatcher.dispatchEvent(new CustomEvent('carta-render', { detail: { carta: this } })); | ||
@@ -116,3 +142,5 @@ return (this.options?.sanitizer && this.options?.sanitizer(dirty)) ?? dirty; | ||
renderSSR(markdown) { | ||
const dirty = marked.parse(markdown, { async: false }); | ||
const dirty = this.markedSync.parse(markdown, { async: false }); | ||
if (typeof dirty != 'string') | ||
return ''; | ||
this.dispatcher.dispatchEvent(new CustomEvent('carta-render-ssr', { detail: { carta: this } })); | ||
@@ -119,0 +147,0 @@ if (this.options?.sanitizer) |
@@ -14,3 +14,3 @@ { | ||
}, | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"scripts": { | ||
@@ -32,3 +32,8 @@ "dev": "vite dev", | ||
"type": "module", | ||
"dependencies": { "@speed-highlight/core": "^1.2.2", "marked": "^6.0.0" }, | ||
"dependencies": { | ||
"@speed-highlight/core": "1.2.2", | ||
"marked": "^6.0.0", | ||
"marked-gfm-heading-id": "^3.0.5", | ||
"marked-mangle": "^1.1.1" | ||
}, | ||
"peerDependencies": { "svelte": "^3.54.0" }, | ||
@@ -35,0 +40,0 @@ "keywords": [ |
@@ -74,9 +74,9 @@ <div align="center"> | ||
| Name | Type | Description | | ||
| ---------------- | ------------------------- | ----------------------------------------- | | ||
| `carta` | `Carta` | Carta Editor | | ||
| `theme` | `string` | For custom css themes, see below for more | | ||
| `value` | `string` | Markdown input | | ||
| `mode` | `'tabs', 'split', 'auto'` | Tabs settings | | ||
| `disableToolbar` | `boolean` | Option to disable the toolbar | | ||
| Name | Type | Description | | ||
| ---------------- | ----------------------------- | ----------------------------------------- | | ||
| `carta` | `Carta` | Carta Editor | | ||
| `theme` | `string` | For custom css themes, see below for more | | ||
| `value` | `string` | Markdown input | | ||
| `mode` | `'tabs' \| 'split' \| 'auto'` | Tabs settings | | ||
| `disableToolbar` | `boolean` | Option to disable the toolbar | | ||
@@ -122,2 +122,4 @@ ### Plugins | ||
| `sanitizer` | `(html: string) => string` | HTML sanitizer | | ||
| `mangle` | `false` | Allows disabling of marked-mangle | | ||
| `gfmHeadingId` | `GfmHeadingIdOptions \| false` | marked-gfm-heading-id options, or disabling | | ||
@@ -124,0 +126,0 @@ You can easily extend Carta by creating custom plugins. Here are all the `CartaExtension` properties: |
87438
1969
145
5
+ Addedmarked-gfm-heading-id@^3.0.5
+ Addedmarked-mangle@^1.1.1
+ Added@speed-highlight/core@1.2.2(transitive)
+ Addedgithub-slugger@2.0.0(transitive)
+ Addedmarked-gfm-heading-id@3.2.0(transitive)
+ Addedmarked-mangle@1.1.10(transitive)
- Removed@speed-highlight/core@1.2.7(transitive)
Updated@speed-highlight/core@1.2.2