shelving 1.51.3 → 1.51.4
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/markup/rules.d.ts +3 -3
- package/markup/rules.js +18 -14
- package/package.json +1 -1
package/markup/rules.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ export declare const FENCED_CODE_RULE: MarkupRule;
|
|
|
38
38
|
export declare const PARAGRAPH_RULE: MarkupRule;
|
|
39
39
|
/**
|
|
40
40
|
* Markdown-style link.
|
|
41
|
-
* - Link in standard Markdown format, e.g. `[http://google.com/maps
|
|
41
|
+
* - Link in standard Markdown format, e.g. `[Google Maps](http://google.com/maps)`
|
|
42
42
|
* - If no title is specified a cleaned up version of the URL will be used, e.g. `google.com/maps`
|
|
43
43
|
* - Does not need space before/after the link.
|
|
44
44
|
* - If link is not valid (using `new URL(url)` then unparsed text will be returned.
|
|
@@ -46,11 +46,11 @@ export declare const PARAGRAPH_RULE: MarkupRule;
|
|
|
46
46
|
*/
|
|
47
47
|
export declare const LINK_RULE: MarkupRule;
|
|
48
48
|
/**
|
|
49
|
-
* Autolinked URL starts with `http:` or `https:` and matches an unlimited number of non-space characters.
|
|
49
|
+
* Autolinked URL starts with `http:` or `https:` or `mailto:` (any scheme in `options.schemes`) and matches an unlimited number of non-space characters.
|
|
50
50
|
* - If followed by space and then text in `()` round or `[]` square brackets that will be used as the title, e.g. `http://google.com/maps (Google Maps)` or `http://google.com/maps [Google Maps]` (this syntax is from Todoist and maybe other things too).
|
|
51
51
|
* - If no title is specified a cleaned up version of the URL will be used, e.g. `google.com/maps`
|
|
52
52
|
* - If link is not valid (using `new URL(url)` then unparsed text will be returned.
|
|
53
|
-
* - For security only schemes that appear in
|
|
53
|
+
* - For security only schemes that appear in `options.schemes` will match (defaults to `http:` and `https:`).
|
|
54
54
|
*/
|
|
55
55
|
export declare const AUTOLINK_RULE: MarkupRule;
|
|
56
56
|
/**
|
package/markup/rules.js
CHANGED
|
@@ -127,58 +127,62 @@ export const PARAGRAPH_RULE = {
|
|
|
127
127
|
};
|
|
128
128
|
/**
|
|
129
129
|
* Markdown-style link.
|
|
130
|
-
* - Link in standard Markdown format, e.g. `[http://google.com/maps
|
|
130
|
+
* - Link in standard Markdown format, e.g. `[Google Maps](http://google.com/maps)`
|
|
131
131
|
* - If no title is specified a cleaned up version of the URL will be used, e.g. `google.com/maps`
|
|
132
132
|
* - Does not need space before/after the link.
|
|
133
133
|
* - If link is not valid (using `new URL(url)` then unparsed text will be returned.
|
|
134
134
|
* - For security only `http://` or `https://` links will work (if invalid the unparsed text will be returned).
|
|
135
135
|
*/
|
|
136
136
|
export const LINK_RULE = {
|
|
137
|
-
// Custom matcher to check the URL against the allowed schemes.
|
|
138
137
|
regexp: /\[([^\]]*?)\]\(([^)]*?)\)/,
|
|
138
|
+
// Custom matcher to check the URL against the allowed schemes.
|
|
139
139
|
match: (content, { schemes, url: base }) => {
|
|
140
140
|
const matches = content.match(LINK_RULE.regexp);
|
|
141
|
-
if (matches
|
|
141
|
+
if (matches) {
|
|
142
142
|
const [, title = "", href = ""] = matches;
|
|
143
143
|
const url = toURL(href, base);
|
|
144
144
|
if (url && url.protocol && schemes.includes(url.protocol)) {
|
|
145
145
|
matches[1] = title.trim();
|
|
146
|
-
matches[2] = url.href;
|
|
146
|
+
matches[2] = url.href;
|
|
147
147
|
return matches;
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
},
|
|
151
|
-
render: ([, title
|
|
152
|
-
type:
|
|
151
|
+
render: ([, title, href = ""], { rel }) => ({
|
|
152
|
+
type: "a",
|
|
153
153
|
key: null,
|
|
154
|
-
props: { children: title || formatUrl(href), href
|
|
154
|
+
props: { children: title || formatUrl(href), href, rel },
|
|
155
155
|
}),
|
|
156
156
|
contexts: ["inline", "list"],
|
|
157
157
|
childContext: "link",
|
|
158
158
|
};
|
|
159
159
|
/**
|
|
160
|
-
* Autolinked URL starts with `http:` or `https:` and matches an unlimited number of non-space characters.
|
|
160
|
+
* Autolinked URL starts with `http:` or `https:` or `mailto:` (any scheme in `options.schemes`) and matches an unlimited number of non-space characters.
|
|
161
161
|
* - If followed by space and then text in `()` round or `[]` square brackets that will be used as the title, e.g. `http://google.com/maps (Google Maps)` or `http://google.com/maps [Google Maps]` (this syntax is from Todoist and maybe other things too).
|
|
162
162
|
* - If no title is specified a cleaned up version of the URL will be used, e.g. `google.com/maps`
|
|
163
163
|
* - If link is not valid (using `new URL(url)` then unparsed text will be returned.
|
|
164
|
-
* - For security only schemes that appear in
|
|
164
|
+
* - For security only schemes that appear in `options.schemes` will match (defaults to `http:` and `https:`).
|
|
165
165
|
*/
|
|
166
166
|
export const AUTOLINK_RULE = {
|
|
167
|
+
regexp: /([a-z]+:\S+)(?: +(?:\(([^)]*?)\)|\[([^\]]*?)\]))?/,
|
|
167
168
|
// Custom matcher to check the URL against the allowed schemes.
|
|
168
|
-
regexp: /([a-zA-Z][a-zA-Z0-9-]*[a-zA-Z0-9]:\S+)(?: +(?:\(([^)]*?)\)|\[([^\]]*?)\]))?/,
|
|
169
169
|
match: (content, { schemes, url: base }) => {
|
|
170
170
|
const matches = content.match(AUTOLINK_RULE.regexp);
|
|
171
171
|
if (matches && typeof matches.index === "number") {
|
|
172
|
-
const [, href = "",
|
|
172
|
+
const [, href = "", roundTitle = "", squareTitle = ""] = matches;
|
|
173
173
|
const url = toURL(href, base);
|
|
174
174
|
if (url && url.protocol && schemes.includes(url.protocol)) {
|
|
175
|
-
matches[1] =
|
|
176
|
-
matches[2] =
|
|
175
|
+
matches[1] = url.href;
|
|
176
|
+
matches[2] = (roundTitle || squareTitle).trim();
|
|
177
177
|
return matches;
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
},
|
|
181
|
-
render:
|
|
181
|
+
render: ([, href = "", title], { rel }) => ({
|
|
182
|
+
type: "a",
|
|
183
|
+
key: null,
|
|
184
|
+
props: { children: title || formatUrl(href), href, rel },
|
|
185
|
+
}),
|
|
182
186
|
contexts: ["inline", "list"],
|
|
183
187
|
childContext: "link",
|
|
184
188
|
};
|