draftly 0.1.0-alpha.0 → 1.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/README.md +346 -0
  2. package/dist/chunk-2B3A3VSQ.cjs +3382 -0
  3. package/dist/chunk-2B3A3VSQ.cjs.map +1 -0
  4. package/dist/chunk-72ZYRGRT.cjs +399 -0
  5. package/dist/chunk-72ZYRGRT.cjs.map +1 -0
  6. package/dist/chunk-CG4M4TC7.js +392 -0
  7. package/dist/chunk-CG4M4TC7.js.map +1 -0
  8. package/dist/chunk-DFQYXFOP.js +86 -0
  9. package/dist/chunk-DFQYXFOP.js.map +1 -0
  10. package/dist/chunk-HPSMS2WB.js +182 -0
  11. package/dist/chunk-HPSMS2WB.js.map +1 -0
  12. package/dist/chunk-KBQDZ5IW.cjs +192 -0
  13. package/dist/chunk-KBQDZ5IW.cjs.map +1 -0
  14. package/dist/chunk-KDEDLC3D.cjs +93 -0
  15. package/dist/chunk-KDEDLC3D.cjs.map +1 -0
  16. package/dist/chunk-N3WL3XPB.js +3360 -0
  17. package/dist/chunk-N3WL3XPB.js.map +1 -0
  18. package/dist/draftly-BLnx3uGX.d.cts +293 -0
  19. package/dist/draftly-BLnx3uGX.d.ts +293 -0
  20. package/dist/editor/index.cjs +57 -0
  21. package/dist/editor/index.cjs.map +1 -0
  22. package/dist/editor/index.d.cts +15 -0
  23. package/dist/editor/index.d.ts +15 -0
  24. package/dist/editor/index.js +4 -0
  25. package/dist/editor/index.js.map +1 -0
  26. package/dist/index.cjs +120 -1129
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.cts +9 -257
  29. package/dist/index.d.ts +9 -257
  30. package/dist/index.js +4 -1126
  31. package/dist/index.js.map +1 -1
  32. package/dist/plugins/index.cjs +66 -0
  33. package/dist/plugins/index.cjs.map +1 -0
  34. package/dist/plugins/index.d.cts +515 -0
  35. package/dist/plugins/index.d.ts +515 -0
  36. package/dist/plugins/index.js +5 -0
  37. package/dist/plugins/index.js.map +1 -0
  38. package/dist/preview/index.cjs +29 -0
  39. package/dist/preview/index.cjs.map +1 -0
  40. package/dist/preview/index.d.cts +143 -0
  41. package/dist/preview/index.d.ts +143 -0
  42. package/dist/preview/index.js +4 -0
  43. package/dist/preview/index.js.map +1 -0
  44. package/package.json +22 -1
  45. package/src/{draftly.ts → editor/draftly.ts} +28 -27
  46. package/src/editor/index.ts +5 -0
  47. package/src/{plugin.ts → editor/plugin.ts} +62 -34
  48. package/src/editor/theme.ts +62 -0
  49. package/src/editor/utils.ts +143 -0
  50. package/src/{view-plugin.ts → editor/view-plugin.ts} +25 -140
  51. package/src/index.ts +4 -7
  52. package/src/plugins/code-plugin.ts +1119 -0
  53. package/src/plugins/heading-plugin.ts +108 -74
  54. package/src/plugins/hr-plugin.ts +102 -0
  55. package/src/plugins/html-plugin.ts +59 -53
  56. package/src/plugins/image-plugin.ts +447 -0
  57. package/src/plugins/index.ts +57 -0
  58. package/src/plugins/inline-plugin.ts +178 -39
  59. package/src/plugins/link-plugin.ts +509 -0
  60. package/src/plugins/list-plugin.ts +492 -211
  61. package/src/plugins/math-plugin.ts +514 -0
  62. package/src/plugins/mermaid-plugin.ts +500 -0
  63. package/src/plugins/paragraph-plugin.ts +38 -0
  64. package/src/plugins/quote-plugin.ts +146 -0
  65. package/src/preview/context.ts +38 -0
  66. package/src/preview/css-generator.ts +51 -0
  67. package/src/preview/default-renderers.ts +29 -0
  68. package/src/preview/index.ts +20 -0
  69. package/src/preview/preview.ts +40 -0
  70. package/src/preview/renderer.ts +157 -0
  71. package/src/preview/types.ts +72 -0
  72. package/src/plugins/plugins.ts +0 -9
  73. package/src/theme.ts +0 -86
  74. package/src/utils.ts +0 -21
@@ -0,0 +1,143 @@
1
+ import * as _lezer_markdown from '@lezer/markdown';
2
+ import { MarkdownConfig } from '@lezer/markdown';
3
+ import { d as DraftlyPlugin, T as ThemeEnum } from '../draftly-BLnx3uGX.js';
4
+ import { SyntaxNode } from '@lezer/common';
5
+ import '@codemirror/state';
6
+ import '@codemirror/view';
7
+ import 'style-mod';
8
+
9
+ /**
10
+ * Context passed to plugin preview methods
11
+ */
12
+ interface PreviewContext {
13
+ /** Full document text */
14
+ readonly doc: string;
15
+ /** Current theme */
16
+ readonly theme: ThemeEnum;
17
+ /** Slice document text between positions */
18
+ sliceDoc(from: number, to: number): string;
19
+ /** Sanitize HTML content (for HTMLBlock/HTMLTag) */
20
+ sanitize(html: string): string;
21
+ /** Render children of a node to HTML */
22
+ renderChildren(node: SyntaxNode): Promise<string>;
23
+ }
24
+ /**
25
+ * Configuration for the preview renderer
26
+ */
27
+ interface PreviewConfig {
28
+ /** Plugins to use for rendering */
29
+ plugins?: DraftlyPlugin[];
30
+ /** Markdown extensions to use for rendering */
31
+ markdown?: _lezer_markdown.MarkdownConfig[];
32
+ /** CSS class for the wrapper element */
33
+ wrapperClass?: string;
34
+ /** HTML tag for the wrapper element */
35
+ wrapperTag?: "article" | "div" | "section";
36
+ /** Whether to sanitize HTML blocks (default: true) */
37
+ sanitize?: boolean;
38
+ /** Theme to use */
39
+ theme?: ThemeEnum;
40
+ }
41
+ /**
42
+ * Result of CSS generation
43
+ */
44
+ interface GenerateCSSConfig {
45
+ /** Plugins to extract styles from */
46
+ plugins?: DraftlyPlugin[];
47
+ /** Theme to use */
48
+ theme?: ThemeEnum;
49
+ /** Wrapper class for scoping (default: "draftly-preview") */
50
+ wrapperClass?: string;
51
+ /** Include base styles */
52
+ includeBase?: boolean;
53
+ }
54
+ /**
55
+ * Node renderer function type
56
+ */
57
+ type NodeRenderer = (node: SyntaxNode, children: string, ctx: PreviewContext) => string;
58
+ /**
59
+ * Map of node names to their renderers
60
+ */
61
+ type NodeRendererMap = Record<string, NodeRenderer>;
62
+
63
+ /**
64
+ * Render markdown to semantic HTML
65
+ *
66
+ * @param markdown - Markdown string to render
67
+ * @param config - Preview configuration
68
+ * @returns HTML string
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * import { preview } from 'draftly/preview';
73
+ * import { HeadingPlugin, ListPlugin } from 'draftly/plugins';
74
+ *
75
+ * const html = preview('# Hello World', {
76
+ * plugins: [new HeadingPlugin(), new ListPlugin()],
77
+ * wrapperClass: 'draftly-preview',
78
+ * });
79
+ * ```
80
+ */
81
+ declare function preview(markdown: string, config?: PreviewConfig): Promise<string>;
82
+
83
+ /**
84
+ * Generate CSS for preview rendering
85
+ *
86
+ * @param config - CSS generation configuration
87
+ * @returns CSS string
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * import { generateCSS } from 'draftly/preview';
92
+ * import { HeadingPlugin, ListPlugin } from 'draftly/plugins';
93
+ *
94
+ * const css = generateCSS({
95
+ * plugins: [new HeadingPlugin(), new ListPlugin()],
96
+ * theme: ThemeEnum.AUTO,
97
+ * includeBase: true,
98
+ * });
99
+ * ```
100
+ */
101
+ declare function generateCSS(config?: GenerateCSSConfig): string;
102
+
103
+ /**
104
+ * Escape HTML special characters
105
+ */
106
+ declare function escapeHtml(text: string): string;
107
+ /**
108
+ * Default node renderers for all markdown node types
109
+ */
110
+ declare const defaultRenderers: NodeRendererMap;
111
+
112
+ /**
113
+ * Renderer class that walks the syntax tree and produces HTML
114
+ */
115
+ declare class PreviewRenderer {
116
+ private doc;
117
+ private theme;
118
+ private plugins;
119
+ private markdown;
120
+ private sanitizeHtml;
121
+ private renderers;
122
+ private ctx;
123
+ private nodeToPlugins;
124
+ constructor(doc: string, plugins: DraftlyPlugin[] | undefined, markdown: MarkdownConfig[], theme?: ThemeEnum, sanitize?: boolean);
125
+ /**
126
+ * Build a map from node names to plugins that handle them
127
+ */
128
+ private buildNodePluginMap;
129
+ /**
130
+ * Render the document to HTML
131
+ */
132
+ render(): Promise<string>;
133
+ /**
134
+ * Render a single node to HTML
135
+ */
136
+ private renderNode;
137
+ /**
138
+ * Render all children of a node, including text between nodes
139
+ */
140
+ private renderChildren;
141
+ }
142
+
143
+ export { type GenerateCSSConfig, type NodeRenderer, type NodeRendererMap, type PreviewConfig, type PreviewContext, PreviewRenderer, defaultRenderers, escapeHtml, generateCSS, preview };
@@ -0,0 +1,4 @@
1
+ export { PreviewRenderer, defaultRenderers, escapeHtml, generateCSS, preview } from '../chunk-HPSMS2WB.js';
2
+ import '../chunk-DFQYXFOP.js';
3
+ //# sourceMappingURL=index.js.map
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "draftly",
3
- "version": "0.1.0-alpha.0",
3
+ "version": "1.0.0-alpha.2",
4
4
  "description": "Core library for draftly",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -33,6 +33,9 @@
33
33
  "@lezer/highlight": "^1.2.3",
34
34
  "@lezer/markdown": "^1.6.3",
35
35
  "dompurify": "^3.3.1",
36
+ "katex": "^0.16.28",
37
+ "mermaid": "^11.12.2",
38
+ "style-mod": "^4.1.3",
36
39
  "zod": "^4.3.6"
37
40
  },
38
41
  "exports": {
@@ -42,6 +45,24 @@
42
45
  "require": "./dist/index.cjs",
43
46
  "default": "./dist/index.js"
44
47
  },
48
+ "./editor": {
49
+ "types": "./dist/editor/index.d.ts",
50
+ "import": "./dist/editor/index.js",
51
+ "require": "./dist/editor/index.cjs",
52
+ "default": "./dist/editor/index.js"
53
+ },
54
+ "./plugins": {
55
+ "types": "./dist/plugins/index.d.ts",
56
+ "import": "./dist/plugins/index.js",
57
+ "require": "./dist/plugins/index.cjs",
58
+ "default": "./dist/plugins/index.js"
59
+ },
60
+ "./preview": {
61
+ "types": "./dist/preview/index.d.ts",
62
+ "import": "./dist/preview/index.js",
63
+ "require": "./dist/preview/index.cjs",
64
+ "default": "./dist/preview/index.js"
65
+ },
45
66
  "./src": {
46
67
  "types": "./src/index.ts",
47
68
  "default": "./src/index.ts"
@@ -1,12 +1,5 @@
1
1
  import { Extension, Prec } from "@codemirror/state";
2
- import {
3
- drawSelection,
4
- EditorView,
5
- highlightActiveLine,
6
- KeyBinding,
7
- keymap,
8
- rectangularSelection,
9
- } from "@codemirror/view";
2
+ import { EditorView, highlightActiveLine, KeyBinding, keymap } from "@codemirror/view";
10
3
  import { markdown, markdownKeymap, markdownLanguage } from "@codemirror/lang-markdown";
11
4
  import type { MarkdownConfig } from "@lezer/markdown";
12
5
  import { DraftlyPlugin, PluginContext } from "./plugin";
@@ -14,7 +7,8 @@ import { createDraftlyViewExtension } from "./view-plugin";
14
7
  import { defaultKeymap, history, historyKeymap, indentWithTab } from "@codemirror/commands";
15
8
  import { indentOnInput } from "@codemirror/language";
16
9
  import { languages } from "@codemirror/language-data";
17
- import { defaultPlugins } from "./plugins/plugins";
10
+ import { ThemeEnum } from "./utils";
11
+ import { markdownResetExtension } from "./theme";
18
12
 
19
13
  /**
20
14
  * DraftlyNode: represents a node in the markdown tree
@@ -33,6 +27,12 @@ export type DraftlyNode = {
33
27
  * Configuration options for the draftly editor
34
28
  */
35
29
  export interface DraftlyConfig {
30
+ /** Theme */
31
+ theme?: ThemeEnum;
32
+
33
+ /** Weather to load base styles */
34
+ baseStyles?: boolean;
35
+
36
36
  /** Plugins to load */
37
37
  plugins?: DraftlyPlugin[];
38
38
 
@@ -57,15 +57,9 @@ export interface DraftlyConfig {
57
57
  /** Enable indent with tab */
58
58
  indentWithTab?: boolean;
59
59
 
60
- /** Draw selection */
61
- drawSelection?: boolean;
62
-
63
60
  /** Highlight active line */
64
61
  highlightActiveLine?: boolean;
65
62
 
66
- /** Rectangular selection */
67
- rectangularSelection?: boolean;
68
-
69
63
  /** Line wrapping in raw markdown mode */
70
64
  lineWrapping?: boolean;
71
65
 
@@ -96,6 +90,8 @@ export interface DraftlyConfig {
96
90
  */
97
91
  export function draftly(config: DraftlyConfig = {}): Extension[] {
98
92
  const {
93
+ theme: configTheme = ThemeEnum.AUTO,
94
+ baseStyles = true,
99
95
  plugins = [],
100
96
  extensions = [],
101
97
  keymap: configKeymap = [],
@@ -103,14 +99,12 @@ export function draftly(config: DraftlyConfig = {}): Extension[] {
103
99
  defaultKeybindings = true,
104
100
  history: configHistory = true,
105
101
  indentWithTab: configIndentWithTab = true,
106
- drawSelection: configDrawSelection = true,
107
102
  highlightActiveLine: configHighlightActiveLine = true,
108
- rectangularSelection: configRectangularSelection = true,
109
103
  lineWrapping: configLineWrapping = true,
110
104
  onNodesChange: configOnNodesChange = undefined,
111
105
  } = config;
112
106
 
113
- const allPlugins = [...defaultPlugins, ...plugins];
107
+ const allPlugins = [...plugins];
114
108
 
115
109
  // Collect all extensions from plugins
116
110
  const pluginExtensions: Extension[] = [];
@@ -137,6 +131,12 @@ export function draftly(config: DraftlyConfig = {}): Extension[] {
137
131
  pluginKeymaps.push(...keys);
138
132
  }
139
133
 
134
+ // Collect theme via class method
135
+ const theme = plugin.theme;
136
+ if (baseStyles && theme && typeof theme === "function") {
137
+ pluginExtensions.push(EditorView.theme(theme(configTheme)));
138
+ }
139
+
140
140
  // Collect markdown parser extensions via class method
141
141
  const md = plugin.getMarkdownConfig();
142
142
  if (md) {
@@ -163,14 +163,15 @@ export function draftly(config: DraftlyConfig = {}): Extension[] {
163
163
  ...(defaultKeybindings ? [keymap.of(defaultKeymap)] : []),
164
164
  ...(configHistory ? [history(), keymap.of(historyKeymap)] : []),
165
165
  ...(configIndentWithTab ? [indentOnInput(), keymap.of([indentWithTab])] : []),
166
- ...(configDrawSelection ? [drawSelection()] : []),
167
166
  ...(configHighlightActiveLine && disableViewPlugin ? [highlightActiveLine()] : []),
168
- ...(configRectangularSelection ? [rectangularSelection()] : []),
169
167
  ];
170
168
 
171
169
  // draftly extensions (pass plugins for decoration support)
172
170
  const draftlyExtensions: Extension[] = [];
173
- if (!disableViewPlugin) draftlyExtensions.push(createDraftlyViewExtension(allPlugins, configOnNodesChange));
171
+ if (!disableViewPlugin) {
172
+ draftlyExtensions.push(createDraftlyViewExtension(configTheme, baseStyles, allPlugins, configOnNodesChange));
173
+ draftlyExtensions.push(Prec.highest(markdownResetExtension));
174
+ }
174
175
  if (!disableViewPlugin || configLineWrapping) draftlyExtensions.push(EditorView.lineWrapping);
175
176
 
176
177
  // Compose all extensions together
@@ -179,19 +180,19 @@ export function draftly(config: DraftlyConfig = {}): Extension[] {
179
180
  Prec.high(markdownSupport),
180
181
  Prec.high(keymap.of(markdownKeymap)),
181
182
 
182
- // Core CodeMirror extensions
183
- ...baseExtensions,
184
-
185
183
  // draftly view plugin for rich rendering
186
- ...draftlyExtensions,
184
+ draftlyExtensions,
185
+
186
+ // Core CodeMirror extensions
187
+ baseExtensions,
187
188
 
188
189
  // Plugin extensions & keymaps
189
- ...pluginExtensions,
190
+ pluginExtensions,
190
191
  pluginKeymaps.length > 0 ? keymap.of(pluginKeymaps) : [],
191
192
 
192
193
  // Config keymaps & extensions
193
194
  configKeymap.length > 0 ? keymap.of(configKeymap) : [],
194
- ...extensions,
195
+ extensions,
195
196
  ];
196
197
 
197
198
  return composedExtensions;
@@ -0,0 +1,5 @@
1
+ // Core editor
2
+ export * from "./draftly";
3
+ export * from "./plugin";
4
+ export * from "./utils";
5
+ export * from "./theme";
@@ -1,7 +1,10 @@
1
- import { Decoration, EditorView, KeyBinding, ViewUpdate, WidgetType } from "@codemirror/view";
1
+ import { Decoration, EditorView, KeyBinding, ViewUpdate } from "@codemirror/view";
2
2
  import { Extension, Range } from "@codemirror/state";
3
3
  import { MarkdownConfig } from "@lezer/markdown";
4
+ import { SyntaxNode } from "@lezer/common";
4
5
  import { DraftlyConfig } from "./draftly";
6
+ import { createTheme, ThemeEnum, ThemeStyle } from "./utils";
7
+ import { StyleModule } from "style-mod";
5
8
 
6
9
  /**
7
10
  * Context passed to plugin lifecycle methods
@@ -51,9 +54,15 @@ export abstract class DraftlyPlugin {
51
54
  /** Plugin version (abstract - must be implemented) */
52
55
  abstract readonly version: string;
53
56
 
57
+ /** Decoration priority (higher = applied later) */
58
+ readonly decorationPriority: number = 100;
59
+
54
60
  /** Plugin dependencies - names of required plugins */
55
61
  readonly dependencies: string[] = [];
56
62
 
63
+ /** Node types this plugin handles for decorations and preview rendering */
64
+ readonly requiredNodes: readonly string[] = [];
65
+
57
66
  /** Private configuration storage */
58
67
  private _config: PluginConfig = {};
59
68
 
@@ -75,6 +84,15 @@ export abstract class DraftlyPlugin {
75
84
  return this._context;
76
85
  }
77
86
 
87
+ /** Plugin theme */
88
+ get theme(): (theme: ThemeEnum) => ThemeStyle {
89
+ return createTheme({
90
+ default: {},
91
+ dark: {},
92
+ light: {},
93
+ });
94
+ }
95
+
78
96
  // ============================================
79
97
  // EXTENSION METHODS (overridable by subclasses)
80
98
  // ============================================
@@ -107,14 +125,6 @@ export abstract class DraftlyPlugin {
107
125
  // DECORATION METHODS (overridable by subclasses)
108
126
  // ============================================
109
127
 
110
- /**
111
- * Decoration priority (higher = applied later)
112
- * Override to customize priority. Default: 100
113
- */
114
- get decorationPriority(): number {
115
- return 100;
116
- }
117
-
118
128
  /**
119
129
  * Build decorations for the current view state
120
130
  * Override to contribute decorations to the editor
@@ -169,47 +179,67 @@ export abstract class DraftlyPlugin {
169
179
  }
170
180
 
171
181
  // ============================================
172
- // ACCESSIBILITY METHODS (overridable by subclasses)
182
+ // PROTECTED UTILITIES (for subclasses)
173
183
  // ============================================
174
184
 
175
185
  /**
176
- * Return ARIA attributes to add to the editor
177
- * Override to improve accessibility
186
+ * Helper to get current editor state
187
+ * @param view - The EditorView instance
178
188
  */
179
- getAriaAttributes(): Record<string, string> {
180
- return {};
189
+ protected getState(view: EditorView) {
190
+ return view.state;
181
191
  }
182
192
 
183
- // ============================================
184
- // VIEW CONTRIBUTIONS (overridable by subclasses)
185
- // ============================================
186
-
187
193
  /**
188
- * Return widget types this plugin provides
189
- * Override to contribute custom widgets
194
+ * Helper to get current document
195
+ * @param view - The EditorView instance
190
196
  */
191
- getWidgets(): WidgetType[] {
192
- return [];
197
+ protected getDocument(view: EditorView) {
198
+ return view.state.doc;
193
199
  }
194
200
 
195
201
  // ============================================
196
- // PROTECTED UTILITIES (for subclasses)
202
+ // PREVIEW RENDERING METHODS (for draftly/preview)
197
203
  // ============================================
198
204
 
199
205
  /**
200
- * Helper to get current editor state
201
- * @param view - The EditorView instance
206
+ * Render a syntax node to HTML for preview mode
207
+ * Override to provide custom HTML rendering for specific node types
208
+ *
209
+ * @param node - The syntax node to render
210
+ * @param children - Pre-rendered children HTML
211
+ * @param ctx - Preview context with document and utilities
212
+ * @returns HTML string to use, or null to use default rendering
202
213
  */
203
- protected getState(view: EditorView) {
204
- return view.state;
214
+ renderToHTML?(
215
+ node: SyntaxNode,
216
+ children: string,
217
+ ctx: { sliceDoc(from: number, to: number): string; sanitize(html: string): string }
218
+ ): string | null | Promise<string | null>;
219
+
220
+ /**
221
+ * Get CSS styles for preview mode
222
+ * Override to provide custom CSS for preview rendering
223
+ *
224
+ * @param theme - Current theme enum
225
+ * @returns CSS string for preview styles
226
+ */
227
+ getPreviewStyles(theme: ThemeEnum, wrapperClass: string): string {
228
+ const themeStyles = this.theme(theme);
229
+ return this.transformToCss(themeStyles, wrapperClass);
205
230
  }
206
231
 
207
232
  /**
208
- * Helper to get current document
209
- * @param view - The EditorView instance
233
+ * Transform ThemeStyle object to CSS string for preview
234
+ * Uses cssClassMap to convert CM selectors to semantic selectors
210
235
  */
211
- protected getDocument(view: EditorView) {
212
- return view.state.doc;
236
+ protected transformToCss(themeStyles: ThemeStyle, wrapperClass: string): string {
237
+ const styleMod = new StyleModule(themeStyles, {
238
+ finish: (sel) => {
239
+ return `.${wrapperClass} ${sel}`;
240
+ },
241
+ });
242
+ return styleMod.getRules();
213
243
  }
214
244
  }
215
245
 
@@ -222,9 +252,7 @@ export abstract class DecorationPlugin extends DraftlyPlugin {
222
252
  * Decoration priority - lower than default for decoration plugins
223
253
  * Override to customize
224
254
  */
225
- override get decorationPriority(): number {
226
- return 50;
227
- }
255
+ override decorationPriority = 50;
228
256
 
229
257
  /**
230
258
  * Subclasses must implement this to provide decorations
@@ -0,0 +1,62 @@
1
+ import { EditorView } from "@codemirror/view";
2
+
3
+ /**
4
+ * Base theme for draftly styling
5
+ * Note: Layout styles are scoped under .cm-draftly which is added by the view plugin
6
+ */
7
+ export const draftlyBaseTheme = EditorView.theme({
8
+ // Container styles - only apply when view plugin is enabled
9
+ "&.cm-draftly": {
10
+ fontSize: "16px",
11
+ lineHeight: "1.6",
12
+ },
13
+
14
+ "&.cm-draftly .cm-content": {
15
+ width: "100%",
16
+ maxWidth: "48rem",
17
+ padding: "0 0.5rem",
18
+ margin: "0 auto",
19
+ fontFamily: "var(--font-sans, sans-serif)",
20
+ fontSize: "16px",
21
+ lineHeight: "1.6",
22
+ },
23
+
24
+ "&.cm-draftly .cm-content .cm-line": {
25
+ paddingInline: 0,
26
+ },
27
+
28
+ "&.cm-draftly .cm-content .cm-widgetBuffer": {
29
+ display: "none !important",
30
+ },
31
+ });
32
+
33
+ import { HighlightStyle, syntaxHighlighting } from "@codemirror/language";
34
+ import { tags as t } from "@lezer/highlight";
35
+
36
+ /**
37
+ * Reset syntax highlighting for markdown elements
38
+ * Used to disable theme colors for markdown syntax
39
+ */
40
+ const markdownResetStyle = HighlightStyle.define([
41
+ {
42
+ tag: [
43
+ t.heading,
44
+ t.strong,
45
+ t.emphasis,
46
+ t.strikethrough,
47
+ t.link,
48
+ t.url,
49
+ t.quote,
50
+ t.list,
51
+ t.meta,
52
+ t.contentSeparator,
53
+ t.labelName,
54
+ ],
55
+ color: "inherit",
56
+ fontWeight: "inherit",
57
+ fontStyle: "inherit",
58
+ textDecoration: "none",
59
+ },
60
+ ]);
61
+
62
+ export const markdownResetExtension = syntaxHighlighting(markdownResetStyle, { fallback: false });