@diplodoc/transform 4.64.2 → 4.65.1
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/dist/css/_yfm-only.css.map +1 -1
- package/dist/css/_yfm-only.min.css.map +1 -1
- package/dist/css/base.css.map +1 -1
- package/dist/css/base.min.css.map +1 -1
- package/dist/css/print.css.map +1 -1
- package/dist/css/yfm.css.map +1 -1
- package/dist/css/yfm.min.css.map +1 -1
- package/lib/md.js +6 -2
- package/lib/md.js.map +1 -1
- package/lib/plugins/images/index.d.ts +13 -3
- package/lib/plugins/images/index.js +70 -49
- package/lib/plugins/images/index.js.map +1 -1
- package/lib/typings.d.ts +11 -1
- package/lib/utils.d.ts +8 -0
- package/lib/utils.js +28 -2
- package/lib/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/transform/md.ts +5 -0
- package/src/transform/plugins/images/index.ts +114 -65
- package/src/transform/typings.ts +17 -1
- package/src/transform/utils.ts +38 -1
package/src/transform/utils.ts
CHANGED
|
@@ -74,7 +74,7 @@ export function headingInfo(tokens: Token[], idx: number) {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
export function isExternalHref(href: string) {
|
|
77
|
-
return
|
|
77
|
+
return /^(\w{1,10}:)?\/\//.test(href) || /^([+\w]{1,10}:)/.test(href);
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
export function transformLinkToOriginalArticle(opts: {root: string; currentPath: string}) {
|
|
@@ -113,3 +113,40 @@ export function defaultTransformLink(href: string) {
|
|
|
113
113
|
|
|
114
114
|
return href;
|
|
115
115
|
}
|
|
116
|
+
|
|
117
|
+
type TokenWalker = (
|
|
118
|
+
token: Token,
|
|
119
|
+
state: {commented: boolean; index: number},
|
|
120
|
+
) => void | undefined | {skip: number};
|
|
121
|
+
|
|
122
|
+
export function filterTokens(tokens: Token[], type: string, handler: TokenWalker) {
|
|
123
|
+
let commented = false;
|
|
124
|
+
|
|
125
|
+
if (!tokens || !tokens.length) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
for (let index = 0; index < tokens.length; index++) {
|
|
130
|
+
const token = tokens[index];
|
|
131
|
+
|
|
132
|
+
if (token.type === 'html_block') {
|
|
133
|
+
const commentStart = token.content.match('<!--');
|
|
134
|
+
const commentEnd = token.content.match('-->');
|
|
135
|
+
|
|
136
|
+
if (commentStart && !commentEnd) {
|
|
137
|
+
commented = true;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (!commentStart && commentEnd) {
|
|
141
|
+
commented = false;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (token.type === type) {
|
|
146
|
+
const result = handler(token, {commented, index});
|
|
147
|
+
if (result?.skip) {
|
|
148
|
+
index += result?.skip - 1;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|