svelte-streamdown 2.3.1 → 2.3.3

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,24 @@
1
+ import type { Extension, GenericToken } from './index.js';
2
+ export declare const markedDl: Extension;
3
+ export declare const markedDt: Extension;
4
+ export type DescriptionListToken = {
5
+ type: 'descriptionList';
6
+ raw: string;
7
+ text: string;
8
+ tokens: DescriptionToken[];
9
+ };
10
+ export type DescriptionToken = {
11
+ type: 'description';
12
+ raw: string;
13
+ tokens: [DescriptionTermToken, DescriptionDetailToken];
14
+ };
15
+ export type DescriptionTermToken = {
16
+ type: 'descriptionTerm';
17
+ raw: string;
18
+ tokens: GenericToken[];
19
+ };
20
+ export type DescriptionDetailToken = {
21
+ type: 'descriptionDetail';
22
+ raw: string;
23
+ tokens: GenericToken[];
24
+ };
@@ -0,0 +1,45 @@
1
+ export const markedDl = {
2
+ name: 'descriptionList',
3
+ level: 'block', // Is this a block-level or inline-level tokenizer?
4
+ tokenizer(src) {
5
+ const rule = /^(?:[ \t]*:[^:\n]+:[ \t]?[^\n]*(?:\n|$))+/;
6
+ const match = rule.exec(src);
7
+ if (match) {
8
+ const token = {
9
+ type: 'descriptionList',
10
+ raw: match[0],
11
+ text: match[0].trim(),
12
+ tokens: this.lexer.inlineTokens(match[0].trim()).filter((t) => t.type === 'description')
13
+ };
14
+ return token;
15
+ }
16
+ }
17
+ };
18
+ export const markedDt = {
19
+ name: 'description',
20
+ level: 'inline',
21
+ tokenizer(src) {
22
+ const rule = /^\s*:([^:\n]+):([^:\n]*)(?:\n|$)/;
23
+ const match = rule.exec(src);
24
+ if (match) {
25
+ const term = match[1].trim();
26
+ const detail = match[2].trim();
27
+ return {
28
+ type: 'description',
29
+ raw: match[0],
30
+ tokens: [
31
+ {
32
+ type: 'descriptionTerm',
33
+ raw: term,
34
+ tokens: this.lexer.inlineTokens(term)
35
+ },
36
+ {
37
+ type: 'descriptionDetail',
38
+ raw: detail,
39
+ tokens: this.lexer.inlineTokens(detail)
40
+ }
41
+ ]
42
+ };
43
+ }
44
+ }
45
+ };
@@ -1,12 +1,5 @@
1
- import type { TokenizerExtensionFunction } from 'marked';
2
- import { type StreamdownToken } from './index.js';
3
- export declare function markedFootnote(): {
4
- extensions: {
5
- name: string;
6
- level: 'block' | 'inline';
7
- tokenizer: TokenizerExtensionFunction;
8
- }[];
9
- };
1
+ import { type StreamdownToken, type Extension } from './index.js';
2
+ export declare function markedFootnote(): Extension[];
10
3
  /**
11
4
  * Represents a single footnote.
12
5
  */
@@ -26,69 +26,66 @@ export function markedFootnote() {
26
26
  return streamdown.footnotes;
27
27
  }
28
28
  };
29
- return {
30
- extensions: [
31
- {
32
- name: 'footnote',
33
- level: 'block',
34
- tokenizer(src) {
35
- const maps = ensureMaps(this);
36
- const match = /^\[\^([^\]\n]+)\]:(?:[ \t]+|[\n]*?|$)([^\n]*?(?:\n|$)(?:\n*?[ ]{4,}[^\n]*)*)/.exec(src);
37
- if (match) {
38
- const [raw, label, text = ''] = match;
39
- let content = text.split('\n').reduce((acc, curr) => {
40
- return acc + '\n' + curr.replace(/^(?:[ ]{4}|[\t])/, '');
41
- }, '');
42
- const contentLastLine = content.trimEnd().split('\n').pop();
43
- content +=
44
- // add lines after list, blockquote, codefence, and table
45
- contentLastLine &&
46
- /^[ \t]*?[>\-*][ ]|[`]{3,}$|^[ \t]*?[|].+[|]$/.test(contentLastLine)
47
- ? '\n\n'
48
- : '';
49
- const lines = content.split('\n');
50
- const token = {
29
+ return [
30
+ {
31
+ name: 'footnote',
32
+ level: 'block',
33
+ tokenizer(src) {
34
+ const maps = ensureMaps(this);
35
+ const match = /^\[\^([^\]\n]+)\]:(?:[ \t]+|[\n]*?|$)([^\n]*?(?:\n|$)(?:\n*?[ ]{4,}[^\n]*)*)/.exec(src);
36
+ if (match) {
37
+ const [raw, label, text = ''] = match;
38
+ let content = text.split('\n').reduce((acc, curr) => {
39
+ return acc + '\n' + curr.replace(/^(?:[ ]{4}|[\t])/, '');
40
+ }, '');
41
+ const contentLastLine = content.trimEnd().split('\n').pop();
42
+ content +=
43
+ // add lines after list, blockquote, codefence, and table
44
+ contentLastLine && /^[ \t]*?[>\-*][ ]|[`]{3,}$|^[ \t]*?[|].+[|]$/.test(contentLastLine)
45
+ ? '\n\n'
46
+ : '';
47
+ const lines = content.split('\n');
48
+ const token = {
49
+ type: 'footnote',
50
+ raw,
51
+ label,
52
+ lines,
53
+ tokens: []
54
+ };
55
+ maps.footnotes.set(label, token);
56
+ const ref = maps.refs.get(label);
57
+ if (ref) {
58
+ ref.content = token;
59
+ }
60
+ return token;
61
+ }
62
+ }
63
+ },
64
+ {
65
+ name: 'footnoteRef',
66
+ level: 'inline',
67
+ tokenizer(src) {
68
+ const maps = ensureMaps(this);
69
+ const match = /^\[\^([^\]\n]+)\]/.exec(src);
70
+ if (match) {
71
+ const [raw, label] = match;
72
+ const footnote = maps.footnotes.get(label);
73
+ const token = {
74
+ type: 'footnoteRef',
75
+ raw,
76
+ label,
77
+ content: footnote || {
51
78
  type: 'footnote',
52
79
  raw,
53
80
  label,
54
- lines,
81
+ lines: [],
55
82
  tokens: []
56
- };
57
- maps.footnotes.set(label, token);
58
- const ref = maps.refs.get(label);
59
- if (ref) {
60
- ref.content = token;
61
83
  }
62
- return token;
63
- }
64
- }
65
- },
66
- {
67
- name: 'footnoteRef',
68
- level: 'inline',
69
- tokenizer(src) {
70
- const maps = ensureMaps(this);
71
- const match = /^\[\^([^\]\n]+)\]/.exec(src);
72
- if (match) {
73
- const [raw, label] = match;
74
- const footnote = maps.footnotes.get(label);
75
- const token = {
76
- type: 'footnoteRef',
77
- raw,
78
- label,
79
- content: footnote || {
80
- type: 'footnote',
81
- raw,
82
- label,
83
- lines: [],
84
- tokens: []
85
- }
86
- };
87
- maps.refs.set(label, token);
88
- return token;
89
- }
84
+ };
85
+ maps.refs.set(label, token);
86
+ return token;
90
87
  }
91
88
  }
92
- ]
93
- };
89
+ }
90
+ ];
94
91
  }
@@ -1,12 +1,6 @@
1
- import type { TokenizerExtensionFunction } from 'marked';
1
+ import type { Extension } from './index.js';
2
2
  export interface HrToken {
3
3
  type: 'hr';
4
4
  raw: string;
5
5
  }
6
- export declare function markedHr(): {
7
- extensions: Array<{
8
- name: string;
9
- level: 'block';
10
- tokenizer: TokenizerExtensionFunction;
11
- }>;
12
- };
6
+ export declare const markedHr: Extension;
@@ -1,24 +1,18 @@
1
- export function markedHr() {
2
- return {
3
- extensions: [
4
- {
5
- name: 'hr',
6
- level: 'block',
7
- tokenizer(src) {
8
- // Match horizontal rules according to CommonMark spec:
9
- // 3 or more matching -, _, or * characters, with optional spaces between
10
- // Must be at start of string and match entire line
11
- const match = src.match(/^[ \t]*(-[ \t]*-[ \t]*-+|_[ \t]*_[ \t]*_+|\*[ \t]*\*[ \t]*\*+)[ \t]*(?:\n|$)/);
12
- if (match) {
13
- const raw = match[0].replace(/\n$/, ''); // Remove trailing newline from raw
14
- return {
15
- type: 'hr',
16
- raw: raw
17
- };
18
- }
19
- return undefined;
20
- }
21
- }
22
- ]
23
- };
24
- }
1
+ export const markedHr = {
2
+ name: 'hr',
3
+ level: 'block',
4
+ tokenizer(src) {
5
+ // Match horizontal rules according to CommonMark spec:
6
+ // 3 or more matching -, _, or * characters, with optional spaces between
7
+ // Must be at start of string and match entire line
8
+ const match = src.match(/^[ \t]*(-[ \t]*-[ \t]*-+|_[ \t]*_[ \t]*_+|\*[ \t]*\*[ \t]*\*+)[ \t]*(?:\n|$)/);
9
+ if (match) {
10
+ const raw = match[0].replace(/\n$/, ''); // Remove trailing newline from raw
11
+ return {
12
+ type: 'hr',
13
+ raw: raw
14
+ };
15
+ }
16
+ return undefined;
17
+ }
18
+ };
@@ -1,17 +1,11 @@
1
- import type { TokenizerExtensionFunction } from 'marked';
1
+ import type { Extension, GenericToken } from './index.js';
2
2
  export declare function letterToInt(letter: string): number;
3
3
  export declare function romanToInt(roman: string): number;
4
4
  export declare const romanUpper = "(?:C|XC|L?X{0,3}(?:IX|IV|V?I{0,3}))";
5
5
  export declare const romanLower = "(?:c|xc|l?x{0,3}(?:ix|iv|v?i{0,3}))";
6
6
  export declare const bulletPattern = "(?:[*+-]|(?:\\d{1,9}|[a-zA-Z]|(?:C|XC|L?X{0,3}(?:IX|IV|V?I{0,3}))|(?:c|xc|l?x{0,3}(?:ix|iv|v?i{0,3})))[.)])";
7
7
  export declare const rule = "^( {0,3}(?:[*+-]|(?:\\d{1,9}|[a-zA-Z]|(?:C|XC|L?X{0,3}(?:IX|IV|V?I{0,3}))|(?:c|xc|l?x{0,3}(?:ix|iv|v?i{0,3})))[.)]))([ \\t][^\\n]*|[ \\t])?(?:\\n|$)";
8
- export declare function markedList(): {
9
- extensions: Array<{
10
- name: string;
11
- level: 'block' | 'inline';
12
- tokenizer: TokenizerExtensionFunction;
13
- }>;
14
- };
8
+ export declare const markedList: Extension;
15
9
  export interface ListToken {
16
10
  type: 'list';
17
11
  raw: string;
@@ -33,5 +27,5 @@ export interface ListItemToken {
33
27
  text: string;
34
28
  value: number | null;
35
29
  skipped: boolean;
36
- tokens: unknown[];
30
+ tokens: GenericToken[];
37
31
  }