Automerge backed Markdown editor for the Atmosphere
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041// src/editor/quote-syntax.ts/** * Shared syntactic primitives for Obsidian-style blockquotes and callouts. * * Keeping the regexes in one place guarantees that the decoration extension * and the keybinding helper agree on what constitutes a quote line. Previously * each module declared its own `QUOTE_LINE_RE`; drifting them out of sync is * a silent class of bug (the editor styles a line as a callout but Enter * behaves as if it isn't, or vice versa). */
/** * Matches a quote line. * * Capture groups: * 1 = the full quote prefix (all leading whitespace and `>` markers with * whitespace between them, including any trailing whitespace that * separates the prefix from content). * 2 = the content after the prefix (may be empty). * * Notes on `(?:>\s*)+`: * - `\s*` is greedy, so for `"> > foo"` the prefix is `"> > "` (depth 2, * trailing space absorbed). For `">>> foo"` the prefix is `">>> "`. * - At least one `>` is required; plain-text lines do not match. * - Tab characters after a `>` are whitespace and get absorbed into the * prefix. Tab-indented `>` (e.g., `"\t> foo"`) still matches, but the * decoration extension intentionally does not style those lines because * `@lezer/markdown` treats tab-indented content as a code block; the * keybinding mirrors that via the code-context check in * `editing-keybindings.ts`. */export const QUOTE_LINE_RE = /^(\s*(?:>\s*)+)(.*)$/
/** * Count the number of `>` markers in a prefix captured by `QUOTE_LINE_RE`. * A depth of 1 is `"> "`, 2 is `"> > "`, and so on. */export function countQuoteDepth(prefix: string): number { return (prefix.match(/>/g) ?? []).length}