diff --git a/.vscode/settings.json b/.vscode/settings.json index 7fd34f4..85e3f0d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,11 +5,15 @@ "coldark", "dompurify", "flexsearch", + "Gemoji", "gruvbox", + "iconify", "Katex", "mdsvex", "oldschool", "rehype", + "shiki", + "shikijs", "tikz", "tikzjax", "typeof" @@ -17,5 +21,6 @@ "typescript.tsdk": "node_modules\\typescript\\lib", "[svelte]": { "editor.defaultFormatter": "svelte.svelte-vscode" - } + }, + "css.customData": [".vscode/tailwind.json"] } diff --git a/.vscode/tailwind.json b/.vscode/tailwind.json new file mode 100644 index 0000000..a45bccc --- /dev/null +++ b/.vscode/tailwind.json @@ -0,0 +1,55 @@ +{ + "version": 1.1, + "atDirectives": [ + { + "name": "@tailwind", + "description": "Use the `@tailwind` directive to insert Tailwind's `base`, `components`, `utilities` and `screens` styles into your CSS.", + "references": [ + { + "name": "Tailwind Documentation", + "url": "https://tailwindcss.com/docs/functions-and-directives#tailwind" + } + ] + }, + { + "name": "@apply", + "description": "Use the `@apply` directive to inline any existing utility classes into your own custom CSS. This is useful when you find a common utility pattern in your HTML that youโ€™d like to extract to a new component.", + "references": [ + { + "name": "Tailwind Documentation", + "url": "https://tailwindcss.com/docs/functions-and-directives#apply" + } + ] + }, + { + "name": "@responsive", + "description": "You can generate responsive variants of your own classes by wrapping their definitions in the `@responsive` directive:\n```css\n@responsive {\n .alert {\n background-color: #E53E3E;\n }\n}\n```\n", + "references": [ + { + "name": "Tailwind Documentation", + "url": "https://tailwindcss.com/docs/functions-and-directives#responsive" + } + ] + }, + { + "name": "@screen", + "description": "The `@screen` directive allows you to create media queries that reference your breakpoints by **name** instead of duplicating their values in your own CSS:\n```css\n@screen sm {\n /* ... */\n}\n```\nโ€ฆgets transformed into this:\n```css\n@media (min-width: 640px) {\n /* ... */\n}\n```\n", + "references": [ + { + "name": "Tailwind Documentation", + "url": "https://tailwindcss.com/docs/functions-and-directives#screen" + } + ] + }, + { + "name": "@variants", + "description": "Generate `hover`, `focus`, `active` and other **variants** of your own utilities by wrapping their definitions in the `@variants` directive:\n```css\n@variants hover, focus {\n .btn-brand {\n background-color: #3182CE;\n }\n}\n```\n", + "references": [ + { + "name": "Tailwind Documentation", + "url": "https://tailwindcss.com/docs/functions-and-directives#variants" + } + ] + } + ] +} diff --git a/README.md b/README.md index 4508e54..38235d5 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,25 @@
- npm + npm - bundle + bundle - license + license - docs + docs
-
- - banner - -
+[![Carta.png](https://i.postimg.cc/nV6DMXKM/Carta.png)](https://beartocode.github.io/carta/) -
- -
Carta
-
Swiftly edit and render Markdown, with no overhead.
+

Carta

+
Modern, lightweight, powerful Markdown Editor.

-Documentation +๐Ÿ“š Documentation ยท GitHub
@@ -34,24 +28,30 @@ # Introduction -Carta is a **lightweight**, **fast** and **extensible** Svelte Markdown editor and viewer, based on [Marked](https://github.com/markedjs/marked). Check out the [examples](http://beartocode.github.io/carta/examples) to see it in action. -Differently from most editors, Carta includes neither ProseMirror nor CodeMirror, allowing for an extremely small bundle size and fast loading time. +> [!NOTE] +> Carta has recently been updated to `v4`, which features numerous major changes. +> +> Follow the [Migration Guide](http://beartocode.github.io/carta/migration) to update your project. + +Carta is a **lightweight**, **fast** and **extensible** Svelte Markdown editor and viewer. It is powered by [unified](https://github.com/unifiedjs/unified), [remark](https://github.com/remarkjs/remark) and [rehype](https://github.com/rehypejs/rehype). Check out the [examples](http://beartocode.github.io/carta/examples) to see it in action. +Differently from most editors, Carta does not include a code editor, but it is _just_ a textarea with syntax highlighting, shortcuts and more. ## Features -- Keyboard **shortcuts** (extensible); -- Toolbar (extensible); -- Markdown syntax highlighting; -- Scroll sync; -- Accessibility friendly; -- **SSR** compatible; -- **Katex** support (plugin); -- **Slash** commands (plugin); -- **Emojis**, with included search (plugin); -- **Tikz** support (plugin); -- **Attachment** support (plugin); -- **Anchor** links in headings; -- Code blocks **syntax highlighting** (plugin). +- ๐ŸŒˆ Markdown syntax highlighting ([Shiki](https://shiki.style/)); +- ๐Ÿ› ๏ธ Toolbar (extensible); +- โŒจ๏ธ Keyboard **shortcuts** (extensible); +- ๐Ÿ“ฆ Supports **[150+ plugins](https://github.com/remarkjs/remark/blob/main/doc/plugins.md#list-of-plugins)** thanks to remark; +- ๐Ÿ”€ Scroll sync; +- โœ… Accessibility friendly; +- ๐Ÿ–ฅ๏ธ **SSR** compatible; +- โš—๏ธ **KaTeX** support (plugin); +- ๐Ÿ”จ **Slash** commands (plugin); +- ๐Ÿ˜„ **Emojis**, with included search (plugin); +- โœ๏ธ **TikZ** support (plugin); +- ๐Ÿ“‚ **Attachment** support (plugin); +- โš“ **Anchor** links in headings (plugin); +- ๐ŸŒˆ Code blocks **syntax highlighting** (plugin). ## Packages @@ -80,6 +80,7 @@ Differently from most editors, Carta includes neither ProseMirror nor CodeMirror > [!WARNING] > Sanitization is not dealt with by Carta. You need to provide a `sanitizer` in the options. > Common sanitizers are [isomorphic-dompurify](https://www.npmjs.com/package/isomorphic-dompurify) (suggested) and [sanitize-html](https://www.npmjs.com/package/sanitize-html). +> Checkout the documentation for an example. ## Installation @@ -99,11 +100,9 @@ npm i @cartamd/plugin-name ```svelte - + ``` diff --git a/docs/package.json b/docs/package.json index 1fd851b..7a24ff5 100644 --- a/docs/package.json +++ b/docs/package.json @@ -47,8 +47,8 @@ "clsx": "^2.0.0", "cmdk-sv": "^0.0.6", "flexsearch": "0.7.21", + "iconify-icon": "^2.0.0", "katex": "^0.16.10", - "radix-icons-svelte": "^1.2.1", "tailwind-merge": "^2.0.0" } } diff --git a/docs/src/lib/components/code/Code.svelte b/docs/src/lib/components/code/Code.svelte index f0b289b..8be7d1f 100644 --- a/docs/src/lib/components/code/Code.svelte +++ b/docs/src/lib/components/code/Code.svelte @@ -1,6 +1,4 @@ @@ -13,10 +11,10 @@ navigator.clipboard.writeText(elem.innerText); }} class=" - absolute right-4 top-[min(50%_,_32px)] -translate-y-1/2 transform - rounded p-2 hover:bg-neutral-800 hover:text-neutral-300 active:text-sky-300 + absolute right-4 top-[min(50%_,_32px)] aspect-square -translate-y-1/2 transform + rounded hover:bg-neutral-800 hover:text-neutral-300 active:text-sky-300 " > - + diff --git a/docs/src/lib/components/header-tracker/HeaderTracker.svelte b/docs/src/lib/components/header-tracker/HeaderTracker.svelte index f5a6b1d..d584c97 100644 --- a/docs/src/lib/components/header-tracker/HeaderTracker.svelte +++ b/docs/src/lib/components/header-tracker/HeaderTracker.svelte @@ -1,5 +1,7 @@ - + { + throttledHighlightHeader(); + debouncedHighlightHeader(); // So it is called at the end of the scroll event + }} +/>
{#each headers as header, i} {@const margin = Number(header.tagName.split('')[1]) - 1} - {@const nextHeader = headers[i + 1]} - {#if header.children[0] instanceof HTMLAnchorElement && header.children[0].href} - {#key scrollY} + {#key selectedHeaderIndex} + {#if header.children[0] instanceof HTMLAnchorElement && header.children[0].href} {header.innerText} - {/key} - {/if} + {/if} + {/key} {/each}
diff --git a/docs/src/lib/components/link/PluginLink.svelte b/docs/src/lib/components/link/PluginLink.svelte index 90a884b..8318e91 100644 --- a/docs/src/lib/components/link/PluginLink.svelte +++ b/docs/src/lib/components/link/PluginLink.svelte @@ -1,18 +1,16 @@ - diff --git a/docs/src/routes/+layout.ts b/docs/src/routes/+layout.ts index 189f71e..a4c5a95 100644 --- a/docs/src/routes/+layout.ts +++ b/docs/src/routes/+layout.ts @@ -1 +1,3 @@ +import 'iconify-icon'; // Register iconify web components + export const prerender = true; diff --git a/docs/src/routes/[...slug]/+page.svelte b/docs/src/routes/[...slug]/+page.svelte index a0df694..449ea7b 100644 --- a/docs/src/routes/[...slug]/+page.svelte +++ b/docs/src/routes/[...slug]/+page.svelte @@ -2,10 +2,10 @@ import type { PageData } from './$types'; import { onMount, type SvelteComponent } from 'svelte'; import { page } from '$app/stores'; + import { base } from '$app/paths'; import '$lib/styles/markdown.scss'; import '$lib/styles/coldark.scss'; - import { base } from '$app/paths'; export let data: PageData; diff --git a/packages/carta-md/README.md b/packages/carta-md/README.md index aadc55b..2b4495b 100644 --- a/packages/carta-md/README.md +++ b/packages/carta-md/README.md @@ -1,31 +1,25 @@ - +[![Carta.png](https://i.postimg.cc/nV6DMXKM/Carta.png)](https://beartocode.github.io/carta/) -
- -
Carta
-
Swiftly edit and render Markdown, with no overhead.
+

Carta

+
Modern, lightweight, powerful Markdown Editor.

@@ -34,38 +28,81 @@ # Introduction -Carta is a **lightweight**, **fast** and **extensible** Svelte Markdown editor and viewer, based on [Marked](https://github.com/markedjs/marked). Check out the [examples](http://beartocode.github.io/carta/examples) to see it in action. -Differently from most editors, Carta includes neither ProseMirror nor CodeMirror, allowing for an extremely small bundle size and fast loading time. +> **NOTE**: +> Carta has recently been updated to `v4`, which features numerous major changes. +> +> Follow the [Migration Guide](http://beartocode.github.io/carta/migration) to update your project. + +Carta is a **lightweight**, **fast** and **extensible** Svelte Markdown editor and viewer. It is powered by [unified](https://github.com/unifiedjs/unified), [remark](https://github.com/remarkjs/remark) and [rehype](https://github.com/rehypejs/rehype). Check out the [examples](http://beartocode.github.io/carta/examples) to see it in action. +Differently from most editors, Carta does not include a code editor, but it is _just_ a textarea with syntax highlighting, shortcuts and more. ## Features -- Keyboard **shortcuts** (extensible); -- Toolbar (extensible); -- Markdown syntax highlighting; -- Scroll sync; -- **SSR** compatible; -- **Katex** support (plugin); -- **Slash** commands (plugin); -- **Emojis**, with included search (plugin); -- **Tikz** support(plugin); -- **Attachment** support(plugin); -- Code blocks **syntax highlighting** (plugin). +- ๐ŸŒˆ Markdown syntax highlighting ([Shiki](https://shiki.style/)); +- ๐Ÿ› ๏ธ Toolbar (extensible); +- โŒจ๏ธ Keyboard **shortcuts** (extensible); +- ๐Ÿ“ฆ Supports **[150+ plugins](https://github.com/remarkjs/remark/blob/main/doc/plugins.md#list-of-plugins)** thanks to remark; +- ๐Ÿ”€ Scroll sync; +- โœ… Accessibility friendly; +- ๐Ÿ–ฅ๏ธ **SSR** compatible; +- โš—๏ธ **KaTeX** support (plugin); +- ๐Ÿ”จ **Slash** commands (plugin); +- ๐Ÿ˜„ **Emojis**, with included search (plugin); +- โœ๏ธ **TikZ** support (plugin); +- ๐Ÿ“‚ **Attachment** support (plugin); +- โš“ **Anchor** links in headings (plugin); +- ๐ŸŒˆ Code blocks **syntax highlighting** (plugin). + +## Packages + +| Package | Status | Docs | +| ----------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | ---------------------------------------------------------------------------- | +| [carta-md](https://www.npmjs.com/package/carta-md) | ![carta-md](https://img.shields.io/npm/v/carta-md) | [/](https://beartocode.github.io/carta/introduction) | +| [plugin-math](https://www.npmjs.com/package/@cartamd/plugin-math) | ![plugin-math](https://img.shields.io/npm/v/@cartamd/plugin-math) | [/plugins/math](https://beartocode.github.io/carta/plugins/math) | +| [plugin-code](https://www.npmjs.com/package/@cartamd/plugin-code) | ![plugin-code](https://img.shields.io/npm/v/@cartamd/plugin-code) | [/plugins/code](https://beartocode.github.io/carta/plugins/code) | +| [plugin-emoji](https://www.npmjs.com/package/@cartamd/plugin-emoji) | ![plugin-emoji](https://img.shields.io/npm/v/@cartamd/plugin-emoji) | [/plugins/emoji](https://beartocode.github.io/carta/plugins/emoji) | +| [plugin-slash](https://www.npmjs.com/package/@cartamd/plugin-slash) | ![plugin-slash](https://img.shields.io/npm/v/@cartamd/plugin-slash) | [/plugins/slash](https://beartocode.github.io/carta/plugins/slash) | +| [plugin-tikz](https://www.npmjs.com/package/@cartamd/plugin-tikz) | ![plugin-tikz](https://img.shields.io/npm/v/@cartamd/plugin-tikz) | [/plugins/tikz](https://beartocode.github.io/carta/plugins/tikz) | +| [plugin-attachment](https://www.npmjs.com/package/@cartamd/plugin-attachment) | ![plugin-attachment](https://img.shields.io/npm/v/@cartamd/plugin-attachment) | [/plugins/attachment](https://beartocode.github.io/carta/plugins/attachment) | +| [plugin-anchor](https://www.npmjs.com/package/@cartamd/plugin-anchor) | ![plugin-anchor](https://img.shields.io/npm/v/@cartamd/plugin-anchor) | [/plugins/anchor](https://beartocode.github.io/carta/plugins/anchor) | + +## Community plugins + +| Plugin | Description | +| ----------------------------------------------------------------------------- | ---------------------------------- | +| [carta-plugin-video](https://github.com/maisonsmd/carta-plugin-video) | Render online videos | +| [carta-plugin-imsize](https://github.com/maisonsmd/carta-plugin-imsize) | Render images in specific sizes | +| [carta-plugin-subscript](https://github.com/maisonsmd/carta-plugin-subscript) | Render subscripts and superscripts | +| [carta-plugin-ins-del](https://github.com/maisonsmd/carta-plugin-ins-del) | `` and `` tags support | # Getting started -> **Warning** +> **WARNING** > Sanitization is not dealt with by Carta. You need to provide a `sanitizer` in the options. > Common sanitizers are [isomorphic-dompurify](https://www.npmjs.com/package/isomorphic-dompurify) (suggested) and [sanitize-html](https://www.npmjs.com/package/sanitize-html). +> Checkout the documentation for an example. + +## Installation + +Core package: + +``` +npm i carta-md +``` + +Plugins: + +``` +npm i @cartamd/plugin-name +``` ## Basic configuration ```svelte - + ``` @@ -99,7 +137,33 @@ For the full documentation, examples, guides and more checkout the [website](htt - [Slash](https://beartocode.github.io/carta/plugins/slash) - [TikZ](https://beartocode.github.io/carta/plugins/tikz) - [Attachment](https://beartocode.github.io/carta/plugins/attachment) + - [Anchor](https://beartocode.github.io/carta/plugins/anchor) - API: - [Utilities](https://beartocode.github.io/carta/api/utilities) - [Core](https://beartocode.github.io/carta/api/core) - [Extension](https://beartocode.github.io/carta/api/extension) + +# Contributing & Development + +Every contribution is well accepted. If you have a feature request you can open a new issue. + +This package uses a [pnpm workspace](https://pnpm.io/workspaces), so pnpm is required to download and put everything together properly. + +### Committing + +This repository is [commitizen](https://github.com/commitizen/cz-cli) friendly. To commit use: + +``` +npm run commit +# or, if you have commitizen installed globally +git cz +``` + +### Running docs + +If you want to preview the docs: + +``` +cd docs +npm run dev +``` diff --git a/packages/carta-md/package.json b/packages/carta-md/package.json index b24e85d..bc074ef 100644 --- a/packages/carta-md/package.json +++ b/packages/carta-md/package.json @@ -14,10 +14,7 @@ "svelte": "./dist/index.js", "import": "./dist/index.js" }, - "./default.css": "./dist/default.css", - "./default-theme.css": "./dist/default.css", - "./light.css": "./dist/light.css", - "./dark.css": "./dist/dark.css" + "./default.css": "./dist/default.css" }, "version": "3.0.0", "scripts": { @@ -38,8 +35,12 @@ }, "type": "module", "dependencies": { - "@speed-highlight/core": "1.2.2", - "marked": "^9.1.5" + "rehype-stringify": "^10.0.0", + "remark-gfm": "^4.0.0", + "remark-parse": "^11.0.0", + "remark-rehype": "^11.1.0", + "shiki": "^1.4.0", + "unified": "^11.0.4" }, "peerDependencies": { "svelte": "^3.54.0 || ^4.0.0" diff --git a/packages/carta-md/src/lib/CartaViewer.svelte b/packages/carta-md/src/lib/Markdown.svelte similarity index 76% rename from packages/carta-md/src/lib/CartaViewer.svelte rename to packages/carta-md/src/lib/Markdown.svelte index 87ba240..25d3971 100644 --- a/packages/carta-md/src/lib/CartaViewer.svelte +++ b/packages/carta-md/src/lib/Markdown.svelte @@ -1,6 +1,6 @@ @@ -56,11 +92,14 @@ bind:this={elem} >
- + aria-hidden="true" + bind:this={highlighElem} + > + {@html highlighted} +