mdq-cli 0.1.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.
@@ -0,0 +1,118 @@
1
+ import { type Token } from 'marked';
2
+ import { MarkdownEditor } from './edit.js';
3
+ export { MarkdownEditor };
4
+ export declare class MarkdownQuery {
5
+ private source;
6
+ private matches;
7
+ constructor(source: string, matches?: MatchedRange[]);
8
+ query(selector: string, matcher?: Matcher): MarkdownQuery;
9
+ section(matcher?: Matcher, options?: SelectorOptions): MarkdownQuery;
10
+ heading(matcher?: Matcher, options?: SelectorOptions): MarkdownQuery;
11
+ paragraph(matcher?: Matcher): MarkdownQuery;
12
+ table(matcher?: Matcher): MarkdownQuery;
13
+ list(matcher?: Matcher): MarkdownQuery;
14
+ item(matcher?: Matcher): MarkdownQuery;
15
+ code(matcher?: Matcher): MarkdownQuery;
16
+ blockquote(matcher?: Matcher): MarkdownQuery;
17
+ comment(matcher?: Matcher): MarkdownQuery;
18
+ html(matcher?: Matcher): MarkdownQuery;
19
+ hr(): MarkdownQuery;
20
+ text(): string;
21
+ nodes(): NodeInfo[];
22
+ rows(): Record<string, string>[];
23
+ entries(): Record<string, string>;
24
+ frontmatter(): Record<string, unknown>;
25
+ count(): number;
26
+ exists(): boolean;
27
+ at(index: number): MarkdownQuery;
28
+ slice(from?: number, to?: number): MarkdownQuery;
29
+ first(): MarkdownQuery;
30
+ last(): MarkdownQuery;
31
+ each(): MarkdownQuery[];
32
+ preceding(): MarkdownQuery;
33
+ following(): MarkdownQuery;
34
+ replace(content: Markdown): MarkdownQuery;
35
+ replaceEach(replacer: (match: MarkdownQuery, index: number) => Markdown): MarkdownQuery;
36
+ remove(): MarkdownQuery;
37
+ insertBefore(markdown: Markdown): MarkdownQuery;
38
+ insertAfter(markdown: Markdown): MarkdownQuery;
39
+ prepend(markdown: Markdown): MarkdownQuery;
40
+ append(markdown: Markdown): MarkdownQuery;
41
+ addRow(row: Record<string, string>): MarkdownQuery;
42
+ addItem(text: string): MarkdownQuery;
43
+ setEntry(key: string, value: string | null): MarkdownQuery;
44
+ setFrontmatter(key: string, value: unknown): MarkdownQuery;
45
+ toString(): string;
46
+ valueOf(): string;
47
+ /** Compatibility aliases. Each delegates to the canonical name above; prefer those. */
48
+ get(): string;
49
+ meta(): NodeInfo[];
50
+ toJson(): Record<string, string>[];
51
+ keyValue(): Record<string, string>;
52
+ setKeyValue(key: string, value: string | null): MarkdownQuery;
53
+ before(): MarkdownQuery;
54
+ after(): MarkdownQuery;
55
+ private editor;
56
+ private run;
57
+ private sectionsOf;
58
+ private itemsOf;
59
+ private expandSections;
60
+ private narrow;
61
+ private filterByText;
62
+ private matchText;
63
+ private valueMatcher;
64
+ private tokenText;
65
+ private isComment;
66
+ private insertAll;
67
+ private containerStart;
68
+ private containerEnd;
69
+ }
70
+ export declare class MdqError extends Error {
71
+ }
72
+ export declare class MdqSelectorError extends MdqError {
73
+ index: number;
74
+ constructor(message: string, index: number);
75
+ }
76
+ export declare class MdqOperationError extends MdqError {
77
+ constructor(message: string);
78
+ }
79
+ export declare function mdq(source: Markdown): MarkdownQuery;
80
+ export declare function parseQuery(input: string): QuerySegment[];
81
+ export declare function buildTokenIndex(source: string): MatchedRange[];
82
+ export type Markdown = string | MarkdownQuery;
83
+ export type Matcher = string | RegExp | ((text: string) => boolean);
84
+ export type SelectorType = 'comment' | 'html' | 'section' | 'section1' | 'section2' | 'section3' | 'section4' | 'section5' | 'section6' | 'table' | 'heading' | 'paragraph' | 'list' | 'item' | 'code' | 'blockquote' | 'hr' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
85
+ export interface SelectorOptions {
86
+ depth?: 1 | 2 | 3 | 4 | 5 | 6;
87
+ }
88
+ export interface TextMatcher {
89
+ mode: 'exact' | 'contains' | 'regex' | 'predicate';
90
+ value: string;
91
+ negated: boolean;
92
+ flags?: string;
93
+ predicate?: (text: string) => boolean;
94
+ }
95
+ export interface QuerySegment {
96
+ selector: SelectorType;
97
+ textMatch?: TextMatcher;
98
+ index: number | null;
99
+ slice: {
100
+ from?: number;
101
+ to?: number;
102
+ } | null;
103
+ }
104
+ export interface MatchedRange {
105
+ token: Token;
106
+ start: number;
107
+ length: number;
108
+ trailing?: {
109
+ start: number;
110
+ length: number;
111
+ };
112
+ innerTokens?: MatchedRange[];
113
+ }
114
+ export interface NodeInfo {
115
+ type: string;
116
+ depth: number | null;
117
+ text: string;
118
+ }