supamde 0.1.0 → 0.2.0

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.
package/README.md CHANGED
@@ -196,20 +196,21 @@ bottom:
196
196
 
197
197
  ## Options (core)
198
198
 
199
- | Option | Type | Default | Meaning |
200
- | -------------- | ---------------------- | ---------------- | -------------------------------------------------------------- |
201
- | `element` | `HTMLTextAreaElement` | — | **Required.** The textarea to replace. |
202
- | `lineWrapping` | `boolean` | `true` | Wrap lines instead of scrolling horizontally. |
203
- | `placeholder` | `string` | — | Placeholder text in the empty editor. |
204
- | `autofocus` | `boolean` | `false` | Focuses the editor after creation. |
205
- | `tabSize` | `number` | `2` | Tab width in columns. |
206
- | `indentUnit` | `number` | `2` | Indentation depth in spaces. |
207
- | `initialValue` | `string` | textarea content | Initial value (overrides the textarea). |
208
- | `extraKeys` | `KeyBinding[]` | `[]` | Custom CM6 key bindings; take precedence over defaults. |
209
- | `autosave` | `AutosaveOptions` | — | Autosave, see [Autosave](#autosave). |
210
- | `uploadImage` | `UploadImageOptions` | — | Image upload, see [Image upload](#image-upload). |
211
- | `locale` | `Locale` | `en` | UI language, see [Localization](#localization). |
212
- | `texts` | `Partial<LocaleTexts>` | — | Overrides individual UI texts; takes precedence over `locale`. |
199
+ | Option | Type | Default | Meaning |
200
+ | ---------------- | ---------------------- | ---------------- | ---------------------------------------------------------------------------- |
201
+ | `element` | `HTMLTextAreaElement` | — | **Required.** The textarea to replace. |
202
+ | `lineWrapping` | `boolean` | `true` | Wrap lines instead of scrolling horizontally. |
203
+ | `placeholder` | `string` | — | Placeholder text in the empty editor. |
204
+ | `autofocus` | `boolean` | `false` | Focuses the editor after creation. |
205
+ | `tabSize` | `number` | `2` | Tab width in columns. |
206
+ | `indentUnit` | `number` | `2` | Indentation depth in spaces. |
207
+ | `codeIndentUnit` | `number \| 'tab'` | `indentUnit` | Indentation inside code blocks: spaces, or `'tab'` for a real tab character. |
208
+ | `initialValue` | `string` | textarea content | Initial value (overrides the textarea). |
209
+ | `extraKeys` | `KeyBinding[]` | `[]` | Custom CM6 key bindings; take precedence over defaults. |
210
+ | `autosave` | `AutosaveOptions` | — | Autosave, see [Autosave](#autosave). |
211
+ | `uploadImage` | `UploadImageOptions` | — | Image upload, see [Image upload](#image-upload). |
212
+ | `locale` | `Locale` | `en` | UI language, see [Localization](#localization). |
213
+ | `texts` | `Partial<LocaleTexts>` | — | Overrides individual UI texts; takes precedence over `locale`. |
213
214
 
214
215
  ## Toolbar & status bar
215
216
 
@@ -1118,7 +1119,9 @@ clicking in the toolbar.
1118
1119
  `Tab` indents the current line by one `indentUnit`, `Shift-Tab` outdents it —
1119
1120
  regardless of where the cursor is in the line. With a selection, this applies
1120
1121
  to all touched lines. This is how lists are nested: `- item` becomes
1121
- ` - item`.
1122
+ ` - item`. Inside code blocks, `codeIndentUnit` is used instead (with `'tab'`, a
1123
+ real tab character is inserted); fence lines count as normal text. In a code block
1124
+ inside a blockquote, the indentation goes after the `>` so the quote stays intact.
1122
1125
 
1123
1126
  > **Note (accessibility):** `Tab` is always captured by the editor and does not
1124
1127
  > leave it. To leave the editor via keyboard, you currently have to use other
@@ -1223,4 +1226,4 @@ npx playwright install chromium
1223
1226
 
1224
1227
  ## License
1225
1228
 
1226
- MIT © Sven Deginther
1229
+ MIT © svenho
@@ -0,0 +1,38 @@
1
+ import { Facet, type EditorState, type Line } from '@codemirror/state';
2
+ import type { Tree } from '@lezer/common';
3
+ /**
4
+ * Einfüge-String für `Tab` in Code-Zeilen (`'\t'` oder Leerzeichen), gesetzt aus
5
+ * der Option `codeIndentUnit`. `null` = nicht gesetzt — dann gilt in Code-Zeilen
6
+ * dieselbe Einheit wie im Text (`indentUnit`).
7
+ */
8
+ export declare const codeIndent: Facet<string, string | null>;
9
+ /**
10
+ * Liegt die Zeile im Inhalt eines Code-Blocks? Zählt: jede Zeile eines
11
+ * eingerückten `CodeBlock` und die Inhaltszeilen eines `FencedCode`. Die Zaunzeilen
12
+ * selbst zählen als Text; ein ungeschlossener Fenced Block reicht bis Dokumentende.
13
+ *
14
+ * `tree` sollte bis `line.to` geparst sein (siehe `codeTreeUpTo`); ohne Angabe
15
+ * wird der aktuelle, ggf. unvollständige Baum genommen.
16
+ */
17
+ export declare function isCodeLine(state: EditorState, line: Line, tree?: Tree): boolean;
18
+ /**
19
+ * Syntaxbaum, der bis `upTo` geparst ist. Eine große Auswahl (z. B. Alles markieren)
20
+ * reicht über den Viewport hinaus, wo der Hintergrund-Parser noch nicht war —
21
+ * dort würden Code-Zeilen sonst als Text gelten. Gelingt das Nachparsen nicht
22
+ * innerhalb des Zeitbudgets, bleibt der vorhandene Baum (bestmöglich).
23
+ */
24
+ export declare function codeTreeUpTo(state: EditorState, upTo: number): Tree;
25
+ /** Wo in einer Code-Zeile die Einrückung beginnt (siehe `codeIndentAnchor`). */
26
+ export interface CodeIndentAnchor {
27
+ /** Doc-Offset, an dem eingefügt bzw. ausgerückt wird. */
28
+ at: number;
29
+ /** Fehlt hinter dem Zitatzeichen das Leerzeichen, das es „schluckt"? */
30
+ missingSpace: boolean;
31
+ }
32
+ /**
33
+ * Einrück-Position einer Code-Zeile. Ohne Zitat ist das der Zeilenanfang. In einem
34
+ * Zitat liegt sie hinter dem letzten `QuoteMark` der Zeile und einem direkt folgenden
35
+ * Leerzeichen — am Zeilenanfang würde das `>` ab 4 Spalten Einrückung kein
36
+ * Zitatzeichen mehr sein und Standard-Renderer beendeten Zitat und Code-Block.
37
+ */
38
+ export declare function codeIndentAnchor(state: EditorState, line: Line, tree: Tree): CodeIndentAnchor;
@@ -7,6 +7,11 @@ import type { SupaCommand } from './types';
7
7
  *
8
8
  * In Markdown ergibt sich die Listen-Verschachtelung genau aus dieser
9
9
  * Leerzeichen-Einrückung, deshalb braucht es keinen Listen-Sonderfall.
10
+ *
11
+ * Zeilen im Inhalt eines Code-Blocks nutzen stattdessen die Einheit aus dem
12
+ * `codeIndent`-Facet (Option `codeIndentUnit`, ggf. ein Tab-Zeichen) — pro Zeile
13
+ * entschieden, damit eine gemischte Auswahl jede Zeile passend einrückt. In
14
+ * Zitaten wird bei Code-Zeilen hinter dem Zitatzeichen eingefügt (`codeIndentAnchor`).
10
15
  */
11
16
  export declare const indentLines: SupaCommand;
12
17
  /**
@@ -14,5 +19,10 @@ export declare const indentLines: SupaCommand;
14
19
  * aus. Zeilen ohne führenden Whitespace bleiben unverändert — der Command gibt
15
20
  * dennoch `true` zurück, damit `Shift-Tab` die Taste konsumiert und den Fokus
16
21
  * nicht aus dem Editor bewegt.
22
+ *
23
+ * In Code-Zeilen gilt die Code-Einheit: bei Leerzeichen deren Anzahl, bei einem
24
+ * Tab-Zeichen bis zu `tabSize` Leerzeichen (ein führendes Tab entfernt
25
+ * `dedentWidth` ohnehin als Ganzes). In Zitaten wird hinter dem Zitatzeichen
26
+ * ausgerückt.
17
27
  */
18
28
  export declare const dedentLines: SupaCommand;
package/dist/options.d.ts CHANGED
@@ -19,6 +19,8 @@ export interface SupaMDEOptions {
19
19
  tabSize?: number;
20
20
  /** Einrücktiefe in Leerzeichen (Default: 2). */
21
21
  indentUnit?: number;
22
+ /** Einrücktiefe in Code-Blöcken: Leerzeichen-Anzahl oder 'tab' (Default: indentUnit). */
23
+ codeIndentUnit?: number | 'tab';
22
24
  /** Startwert; überschreibt den Textarea-Inhalt, falls gesetzt. */
23
25
  initialValue?: string;
24
26
  /** Eigene Tastenkürzel; haben Vorrang vor den SupaMDE-Defaults bei Konflikten. */
@@ -73,6 +75,7 @@ export interface ResolvedOptions {
73
75
  autofocus: boolean;
74
76
  tabSize: number;
75
77
  indentUnit: number;
78
+ codeIndentUnit: number | 'tab';
76
79
  extraKeys: KeyBinding[];
77
80
  editorMode: EditorMode;
78
81
  }