Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
feat: highlight markdown in code editor (#3893)
Bogdan Chadkinc1d812353e30
diff --git a/apps/builder/app/builder/shared/code-editor-base.tsx b/apps/builder/app/builder/shared/code-editor-base.tsxindex 53cfc77815..cd10c423eb 100644--- a/apps/builder/app/builder/shared/code-editor-base.tsx+++ b/apps/builder/app/builder/shared/code-editor-base.tsx@@ -112,11 +112,11 @@ const editorContentStyle = css({const highlightStyle = HighlightStyle.define([// darker comment variant from https://github.com/vadimdemedes/thememirror/blob/main/source/themes/ayu-light.ts#L17-L20{- tag: tags.comment,+ tag: [tags.comment, tags.annotation],color: "#787b8099",},{- tag: [tags.string, tags.special(tags.brace), tags.regexp],+ tag: [tags.string, tags.special(tags.brace), tags.regexp, tags.url],color: "#5D90CD",},{@@ -132,7 +132,7 @@ const highlightStyle = HighlightStyle.define([color: "#C52727",},{- tag: [tags.angleBracket, tags.tagName, tags.attributeName],+ tag: [tags.angleBracket, tags.tagName, tags.attributeName, tags.separator],color: "#606060",},{diff --git a/apps/builder/app/builder/shared/code-editor.tsx b/apps/builder/app/builder/shared/code-editor.tsxindex 2d04c02996..5da089982a 100644--- a/apps/builder/app/builder/shared/code-editor.tsx+++ b/apps/builder/app/builder/shared/code-editor.tsx@@ -1,4 +1,5 @@import { forwardRef, useMemo, type ComponentProps, useEffect } from "react";+import { styleTags, tags } from "@lezer/highlight";import {keymap,tooltips,@@ -13,6 +14,7 @@ import {completionKeymap,} from "@codemirror/autocomplete";import { html } from "@codemirror/lang-html";+import { markdown } from "@codemirror/lang-markdown";import { theme, textVariants, css } from "@webstudio-is/design-system";import { CodeEditorBase, getMinMaxHeightVars } from "./code-editor-base";@@ -85,16 +87,49 @@ const getHtmlExtensions = () => [keymap.of([...closeBracketsKeymap, ...completionKeymap]),];+const getMarkdownExtensions = () => [+ highlightActiveLine(),+ highlightSpecialChars(),+ indentOnInput(),+ markdown({+ extensions: [+ {+ props: [+ styleTags({+ HorizontalRule: tags.separator,+ HeaderMark: tags.annotation,+ QuoteMark: tags.annotation,+ ListMark: tags.annotation,+ LinkMark: tags.annotation,+ EmphasisMark: tags.annotation,+ CodeMark: tags.annotation,+ InlineCode: tags.string,+ URL: tags.url,+ }),+ ],+ },+ ],+ }),+ bracketMatching(),+ closeBrackets(),+ keymap.of(closeBracketsKeymap),+];+export const CodeEditor = forwardRef<HTMLDivElement,Omit<ComponentProps<typeof CodeEditorBase>, "extensions"> & {lang?: "html" | "markdown";}>(({ lang, ...props }, ref) => {- const extensions = useMemo(- () => (lang === "html" ? getHtmlExtensions() : []),- [lang]- );+ const extensions = useMemo(() => {+ if (lang === "html") {+ return getHtmlExtensions();+ }+ if (lang === "markdown") {+ return getMarkdownExtensions();+ }+ return [];+ }, [lang]);// prevent clicking on autocomplete options propagating to body// and closing dialogs and popoversdiff --git a/apps/builder/package.json b/apps/builder/package.jsonindex c5a07b8c51..e78a2e9e54 100644--- a/apps/builder/package.json+++ b/apps/builder/package.json@@ -17,13 +17,14 @@},"dependencies": {"@atlaskit/pragmatic-drag-and-drop": "^1.1.11",- "@codemirror/autocomplete": "^6.16.2",- "@codemirror/commands": "^6.5.0",+ "@codemirror/autocomplete": "^6.18.0",+ "@codemirror/commands": "^6.6.0","@codemirror/lang-html": "^6.4.9","@codemirror/lang-javascript": "^6.2.2",- "@codemirror/language": "^6.10.1",+ "@codemirror/lang-markdown": "^6.2.5",+ "@codemirror/language": "^6.10.2","@codemirror/state": "^6.4.1",- "@codemirror/view": "^6.26.3",+ "@codemirror/view": "^6.30.0","@floating-ui/dom": "^1.6.5","@fontsource-variable/inter": "^5.0.13","@fontsource-variable/manrope": "^5.0.15",@@ -85,7 +86,7 @@"immer": "^10.0.3","immerhin": "^0.9.0","lexical": "^0.16.0",- "match-sorter": "^6.3.1",+ "match-sorter": "^6.3.4","mdast-util-from-markdown": "^2.0.1","mdast-util-gfm": "^3.0.0","micromark-extension-gfm": "^3.0.0",diff --git a/packages/design-system/package.json b/packages/design-system/package.jsonindex 9dc2109a9c..741e40a2b6 100644--- a/packages/design-system/package.json+++ b/packages/design-system/package.json@@ -63,7 +63,7 @@"change-case": "^5.4.4","downshift": "^6.1.7","immer": "^10.0.3",- "match-sorter": "^6.3.1",+ "match-sorter": "^6.3.4","react-field-sizing-content": "^1.0.0","react-hot-toast": "^2.4.1","token-transformer": "^0.0.28",diff --git a/packages/sdk-components-react/src/markdown-embed.ws.ts b/packages/sdk-components-react/src/markdown-embed.ws.tsindex cafceb2df1..0eeb4c7ac2 100644--- a/packages/sdk-components-react/src/markdown-embed.ws.ts+++ b/packages/sdk-components-react/src/markdown-embed.ws.ts@@ -70,7 +70,7 @@ export const meta: WsComponentMeta = {},],},- order: 5,+ order: 4,template: [{type: "instance",diff --git a/packages/sdk-components-react/src/time.ws.ts b/packages/sdk-components-react/src/time.ws.tsindex e7faa25343..a897428af0 100644--- a/packages/sdk-components-react/src/time.ws.ts+++ b/packages/sdk-components-react/src/time.ws.ts@@ -23,7 +23,7 @@ export const meta: WsComponentMeta = {icon: CalendarIcon,states: defaultStates,presetStyle,- order: 4,+ order: 5,};export const propsMeta: WsComponentPropsMeta = {diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 6e50efa62e..69bb62574d 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -125,26 +125,29 @@ importers:specifier: ^1.1.11version: 1.1.11'@codemirror/autocomplete':- specifier: ^6.16.2- version: 6.16.2(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected])+ specifier: ^6.18.0+ version: 6.18.0(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected])'@codemirror/commands':- specifier: ^6.5.0- version: 6.5.0+ specifier: ^6.6.0+ version: 6.6.0'@codemirror/lang-html':specifier: ^6.4.9version: 6.4.9'@codemirror/lang-javascript':specifier: ^6.2.2version: 6.2.2+ '@codemirror/lang-markdown':+ specifier: ^6.2.5+ version: 6.2.5'@codemirror/language':- specifier: ^6.10.1- version: 6.10.1+ specifier: ^6.10.2+ version: 6.10.2'@codemirror/state':specifier: ^6.4.1version: 6.4.1'@codemirror/view':- specifier: ^6.26.3- version: 6.26.3+ specifier: ^6.30.0+ version: 6.30.0'@floating-ui/dom':specifier: ^1.6.5version: 1.6.5@@ -329,8 +332,8 @@ importers:specifier: ^0.16.0version: 0.16.0match-sorter:- specifier: ^6.3.1- version: 6.3.1+ specifier: ^6.3.4+ version: 6.3.4mdast-util-from-markdown:specifier: ^2.0.1version: 2.0.1@@ -1327,8 +1330,8 @@ importers:specifier: ^10.0.3version: 10.0.3match-sorter:- specifier: ^6.3.1- version: 6.3.1+ specifier: ^6.3.4+ version: 6.3.4react-field-sizing-content:specifier: ^1.0.0version: 1.0.0([email protected])@@ -2821,6 +2824,10 @@ packages:resolution: {integrity: sha512-XsDuspWKLUsxwCp6r7EhsExHtYfbe5oAGQ19kqngTdCPUoPQzOPdUbD/pB9PJiwb2ptYKQDjSJT3R6dC+EPqfQ==}engines: {node: '>=6.9.0'}+ '@babel/[email protected]':+ resolution: {integrity: sha512-7dRy4DwXwtzBrPbZflqxnvfxLF8kdZXPkhymtDeFoFqE6ldzjQFgYTtYIFARcLEYDrqfBfYcZt1WqFxRoyC9Rw==}+ engines: {node: '>=6.9.0'}+'@babel/[email protected]':resolution: {integrity: sha512-X7yV7eiwAxdj9k94NEylvbVHLiVG1nvzCV2EAowhxLTwODV1jl9UzZ48leOC0sH7OnuHrIkllaBgneUykIcZaw==}engines: {node: '>=6.9.0'}@@ -2918,16 +2925,16 @@ packages:'@cloudflare/[email protected]':resolution: {integrity: sha512-6Cu6NIAicmb8H6CkzFdQG5Ib+TDs9HU8AKQEGlxnbvEBDmhUNpmL30ETXpLS0asdeyc+rTb2xag0hSv0Z1BflQ==}- '@codemirror/[email protected]':- resolution: {integrity: sha512-MjfDrHy0gHKlPWsvSsikhO1+BOh+eBHNgfH1OXs1+DAf30IonQldgMM3kxLDTG9ktE7kDLaA1j/l7KMPA4KNfw==}+ '@codemirror/[email protected]':+ resolution: {integrity: sha512-5DbOvBbY4qW5l57cjDsmmpDh3/TeK1vXfTHa+BUMrRzdWdcxKZ4U4V7vQaTtOpApNU4kLS4FQ6cINtLg245LXA==}peerDependencies:'@codemirror/language': ^6.0.0'@codemirror/state': ^6.0.0'@codemirror/view': ^6.0.0'@lezer/common': ^1.0.0- '@codemirror/[email protected]':- resolution: {integrity: sha512-rK+sj4fCAN/QfcY9BEzYMgp4wwL/q5aj/VfNSoH1RWPF9XS/dUwBkvlL3hpWgEjOqlpdN1uLC9UkjJ4tmyjJYg==}+ '@codemirror/[email protected]':+ resolution: {integrity: sha512-qnY+b7j1UNcTS31Eenuc/5YJB6gQOzkUoNmJQc0rznwqSRpeaWWpjkWy2C/MPTcePpsKJEM26hXrOXl1+nceXg==}'@codemirror/[email protected]':resolution: {integrity: sha512-/UNWDNV5Viwi/1lpr/dIXJNWiwDxpw13I4pTUAsNxZdg6E0mI2kTQb0P2iHczg1Tu+H4EBgJR+hYhKiHKko7qg==}@@ -2938,8 +2945,11 @@ packages:'@codemirror/[email protected]':resolution: {integrity: sha512-VGQfY+FCc285AhWuwjYxQyUQcYurWlxdKYT4bqwr3Twnd5wP5WSeu52t4tvvuWmljT4EmgEgZCqSieokhtY8hg==}- '@codemirror/[email protected]':- resolution: {integrity: sha512-5GrXzrhq6k+gL5fjkAwt90nYDmjlzTIJV8THnxNFtNKWotMIlzzN+CpqxqwXOECnUdOndmSeWntVrVcv5axWRQ==}+ '@codemirror/[email protected]':+ resolution: {integrity: sha512-Hgke565YcO4fd9pe2uLYxnMufHO5rQwRr+AAhFq8ABuhkrjyX8R5p5s+hZUTdV60O0dMRjxKhBLxz8pu/MkUVA==}++ '@codemirror/[email protected]':+ resolution: {integrity: sha512-kgbTYTo0Au6dCSc/TFy7fK3fpJmgHDv1sG1KNQKJXVi+xBTEeBPY/M30YXiU6mMXeH+YIDLsbrT4ZwNRdtF+SA==}'@codemirror/[email protected]':resolution: {integrity: sha512-wzRkluWb1ptPKdzlsrbwwjYCPLgzU6N88YBAmlZi8WFyuiEduSd05MnJYNogzyc8rPK7pj6m95ptUApc8sHKVA==}@@ -2947,8 +2957,8 @@ packages:'@codemirror/[email protected]':resolution: {integrity: sha512-QkEyUiLhsJoZkbumGZlswmAhA7CBU02Wrz7zvH4SrcifbsqwlXShVXg65f3v/ts57W3dqyamEriMhij1Z3Zz4A==}- '@codemirror/[email protected]':- resolution: {integrity: sha512-gmqxkPALZjkgSxIeeweY/wGQXBfwTUaLs8h7OKtSwfbj9Ct3L11lD+u1sS7XHppxFQoMDiMDp07P9f3I2jWOHw==}+ '@codemirror/[email protected]':+ resolution: {integrity: sha512-96Nmn8OeLh6aONQprIeYk8hGVnEuYpWuxKSkdsODOx9hWPxyuyZGvmvxV/JmLsp+CubMO1PsLaN5TNNgrl0UrQ==}'@cspotcode/[email protected]':resolution: {integrity: sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==}@@ -3934,6 +3944,9 @@ packages:'@lezer/[email protected]':resolution: {integrity: sha512-z5mY4LStlA3yL7aHT/rqgG614cfcvklS+8oFRFBYrs4YaWLJyKKM4+nN6KopToX0o9Hj6zmH6M5kinOYuy06ug==}+ '@lezer/[email protected]':+ resolution: {integrity: sha512-ErbEQ15eowmJUyT095e9NJc3BI9yZ894fjSDtHftD0InkfUBGgnKSU6dvan9jqsZuNHg2+ag/1oyDRxNsENupQ==}+'@mdx-js/[email protected]':resolution: {integrity: sha512-jLuwRlz8DQfQNiUCJR50Y09CGPq3fLtmtUQfVrj79E0JWu3dvsVcxVIcfhR5h0iXu+/z++zDrYeiJqifRynJkA==}@@ -7620,8 +7633,8 @@ packages:peerDependencies:react: 18.3.0-canary-14898b6a9-20240318- resolution: {integrity: sha512-mxybbo3pPNuA+ZuCUhm5bwNkXrJTbsk5VWbR5wiwz/GC6LIiegBGn2w3O08UG/jdbYLinw51fSQ5xNU1U3MgBw==}+ resolution: {integrity: sha512-jfZW7cWS5y/1xswZo8VBOdudUiSd9nifYRWphc9M5D/ee4w4AoXLgBEdRbgVaxbMuagBPeUC5y2Hi8DO6o9aDg==}resolution: {integrity: sha512-T1GITYmFaKuO91vxyoQMFETst+O71VUPEU3ze5GNzDm0OWdP8v1ziTaAEPUr/3kLsY3Sftgz242A1SetQiDL7g==}@@ -8766,6 +8779,9 @@ packages:resolution: {integrity: sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==}+ resolution: {integrity: sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==}+resolution: {integrity: sha512-hfMp2BoF0qOk3uc5V20ALGDS2ddjQaLrdl7xrGXvAIow7qeWRM2VA2HuCHkUKk9slq3VwEwLNK3DFBqDfPGYtg==}@@ -8853,8 +8869,8 @@ packages:react: 18.3.0-canary-14898b6a9-20240318react-dom: 18.3.0-canary-14898b6a9-20240318- resolution: {integrity: sha512-7pXIJqJOq5tFgG1A2Zxti3Ht8jJF337m4sowbuHsW30ZnkQFnDzy9qBNhgzX8ZLW4+UBcXiiR7SwR6pokHsxiA==}+ resolution: {integrity: sha512-8g3/Otx1eJaVD12e31UbJj1YzdtVvzH85HV7t+9MJYk/u3XmkOUJ5Ys9wQrf9PCPK8+xn4ymzqYCiZl6QWKn+A==}resolution: {integrity: sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==}@@ -10902,6 +10918,10 @@ snapshots:dependencies:regenerator-runtime: 0.13.11+ '@babel/[email protected]':+ dependencies:+ regenerator-runtime: 0.14.1+'@babel/[email protected]':dependencies:'@babel/code-frame': 7.24.2@@ -11023,24 +11043,24 @@ snapshots:'@cloudflare/[email protected]': {}- '@codemirror/[email protected](@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected])':+ '@codemirror/[email protected](@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected])':dependencies:- '@codemirror/language': 6.10.1+ '@codemirror/language': 6.10.2'@codemirror/state': 6.4.1- '@codemirror/view': 6.26.3+ '@codemirror/view': 6.30.0'@lezer/common': 1.2.1- '@codemirror/[email protected]':+ '@codemirror/[email protected]':dependencies:- '@codemirror/language': 6.10.1+ '@codemirror/language': 6.10.2'@codemirror/state': 6.4.1- '@codemirror/view': 6.26.3+ '@codemirror/view': 6.30.0'@lezer/common': 1.2.1- '@codemirror/[email protected](@codemirror/[email protected])':+ '@codemirror/[email protected](@codemirror/[email protected])':dependencies:- '@codemirror/autocomplete': 6.16.2(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected])- '@codemirror/language': 6.10.1+ '@codemirror/autocomplete': 6.18.0(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected])+ '@codemirror/language': 6.10.2'@codemirror/state': 6.4.1'@lezer/common': 1.2.1'@lezer/css': 1.1.4@@ -11049,30 +11069,40 @@ snapshots:'@codemirror/[email protected]':dependencies:- '@codemirror/autocomplete': 6.16.2(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected])- '@codemirror/lang-css': 6.2.1(@codemirror/[email protected])+ '@codemirror/autocomplete': 6.18.0(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected])+ '@codemirror/lang-css': 6.2.1(@codemirror/[email protected])'@codemirror/lang-javascript': 6.2.2- '@codemirror/language': 6.10.1+ '@codemirror/language': 6.10.2'@codemirror/state': 6.4.1- '@codemirror/view': 6.26.3+ '@codemirror/view': 6.30.0'@lezer/common': 1.2.1'@lezer/css': 1.1.4'@lezer/html': 1.3.7'@codemirror/[email protected]':dependencies:- '@codemirror/autocomplete': 6.16.2(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected])- '@codemirror/language': 6.10.1+ '@codemirror/autocomplete': 6.18.0(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected])+ '@codemirror/language': 6.10.2'@codemirror/lint': 6.4.2'@codemirror/state': 6.4.1- '@codemirror/view': 6.26.3+ '@codemirror/view': 6.30.0'@lezer/common': 1.2.1'@lezer/javascript': 1.4.10- '@codemirror/[email protected]':+ '@codemirror/[email protected]':dependencies:+ '@codemirror/autocomplete': 6.18.0(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected])+ '@codemirror/lang-html': 6.4.9+ '@codemirror/language': 6.10.2'@codemirror/state': 6.4.1- '@codemirror/view': 6.26.3+ '@codemirror/view': 6.30.0+ '@lezer/common': 1.2.1+ '@lezer/markdown': 1.3.0++ '@codemirror/[email protected]':+ dependencies:+ '@codemirror/state': 6.4.1+ '@codemirror/view': 6.30.0'@lezer/common': 1.2.1'@lezer/highlight': 1.2.0'@lezer/lr': 1.3.14@@ -11081,12 +11111,12 @@ snapshots:'@codemirror/[email protected]':dependencies:'@codemirror/state': 6.4.1- '@codemirror/view': 6.26.3+ '@codemirror/view': 6.30.0crelt: 1.0.6'@codemirror/[email protected]': {}- '@codemirror/[email protected]':+ '@codemirror/[email protected]':dependencies:'@codemirror/state': 6.4.1style-mod: 4.1.0@@ -11919,6 +11949,11 @@ snapshots:dependencies:'@lezer/common': 1.2.1+ '@lezer/[email protected]':+ dependencies:+ '@lezer/common': 1.2.1+ '@lezer/highlight': 1.2.0+'@mdx-js/[email protected]':dependencies:'@types/estree-jsx': 1.0.0@@ -16385,10 +16420,10 @@ snapshots:dependencies:react: 18.3.0-canary-14898b6a9-20240318dependencies:- '@babel/runtime': 7.22.3- remove-accents: 0.4.2+ '@babel/runtime': 7.25.0+ remove-accents: 0.5.0dependencies:@@ -17892,6 +17927,8 @@ snapshots:+ [email protected]: {}+dependencies:'@babel/runtime': 7.22.3@@ -18020,7 +18057,7 @@ snapshots:react: 18.3.0-canary-14898b6a9-20240318react-dom: 18.3.0-canary-14898b6a9-20240318([email protected])- [email protected]: {}+ [email protected]: {}