@diplodoc/transform 4.76.6 → 4.76.7
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/dist/js/base.js +4 -2
- package/dist/js/base.js.map +2 -2
- package/dist/js/base.min.js +1 -1
- package/dist/js/base.min.js.map +3 -3
- package/dist/js/yfm.js +4 -2
- package/dist/js/yfm.js.map +2 -2
- package/dist/js/yfm.min.js +1 -1
- package/dist/js/yfm.min.js.map +3 -3
- package/lib/plugins/code.js +15 -3
- package/lib/plugins/code.js.map +1 -1
- package/package.json +1 -1
- package/src/js/code.ts +5 -2
- package/src/transform/plugins/code.ts +17 -3
package/lib/plugins/code.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* eslint-disable max-len */
|
|
3
3
|
const utils_1 = require("./utils");
|
|
4
|
-
const wrapInFloatingContainer = (element, id,
|
|
4
|
+
const wrapInFloatingContainer = (element, id, lineWrapping) => {
|
|
5
|
+
const activeClass = lineWrapping ? ' g-button_selected' : '';
|
|
6
|
+
const ariaPressed = lineWrapping ? 'true' : 'false';
|
|
5
7
|
const wrappingButton = lineWrapping
|
|
6
|
-
? `<button role="button" class="g-button g-button_view_flat g-button_size_m g-button_pin_round-round g-md-viewer-code-button yfm-code-button yfm-wrapping-button" tabindex="-1" type="button" aria-label="Toggle line wrapping"aria-pressed="
|
|
8
|
+
? `<button role="button" class="g-button g-button_view_flat g-button_size_m g-button_pin_round-round g-md-viewer-code-button yfm-code-button yfm-wrapping-button${activeClass}" tabindex="-1" type="button" aria-label="Toggle line wrapping" aria-pressed="${ariaPressed}" data-tabindex="0">
|
|
7
9
|
<span class="g-button__icon">
|
|
8
10
|
<span class="g-button__icon-inner"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" class="g-icon" fill="currentColor" stroke="none" aria-hidden="true">
|
|
9
11
|
<svg class="yfm-code-icon yfm-wrapping-icon" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16">
|
|
@@ -125,6 +127,8 @@ const code = (md, opts) => {
|
|
|
125
127
|
md.renderer.rules.fence = function (tokens, idx, options, env, self) {
|
|
126
128
|
const token = tokens[idx];
|
|
127
129
|
const showLineNumbers = token.info.includes('showLineNumbers');
|
|
130
|
+
const wrapLines = token.info.includes('wrap');
|
|
131
|
+
const shouldWrap = lineWrapping || wrapLines;
|
|
128
132
|
let superCode = superCodeRenderer === null || superCodeRenderer === void 0 ? void 0 : superCodeRenderer(tokens, idx, options, env, self);
|
|
129
133
|
if (superCode && showLineNumbers) {
|
|
130
134
|
// Extract the code content from the pre/code tags
|
|
@@ -137,10 +141,18 @@ const code = (md, opts) => {
|
|
|
137
141
|
superCode = superCode.replace(codeContent, escapedReplacement);
|
|
138
142
|
}
|
|
139
143
|
}
|
|
144
|
+
if (superCode && shouldWrap) {
|
|
145
|
+
superCode = superCode.replace(/<code([^>]*)>/, (_match, attrs) => {
|
|
146
|
+
if (attrs.includes('class=')) {
|
|
147
|
+
return `<code${attrs.replace(/class="([^"]*)"/, 'class="$1 wrap"')}>`;
|
|
148
|
+
}
|
|
149
|
+
return `<code class="wrap"${attrs}>`;
|
|
150
|
+
});
|
|
151
|
+
}
|
|
140
152
|
const superCodeWithTerms = superCode && (env === null || env === void 0 ? void 0 : env.terms)
|
|
141
153
|
? termReplace(superCode, env, md.utils.escapeRE, generateID)
|
|
142
154
|
: superCode;
|
|
143
|
-
return wrapInFloatingContainer(superCodeWithTerms, idx,
|
|
155
|
+
return wrapInFloatingContainer(superCodeWithTerms, idx, lineWrapping);
|
|
144
156
|
};
|
|
145
157
|
};
|
|
146
158
|
module.exports = code;
|
package/lib/plugins/code.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code.js","sourceRoot":"","sources":["../../src/transform/plugins/code.ts"],"names":[],"mappings":";AAAA,4BAA4B;AAK5B,mCAAuD;AAEvD,MAAM,uBAAuB,GAAG,CAC5B,OAA2B,EAC3B,EAAU,EACV,
|
|
1
|
+
{"version":3,"file":"code.js","sourceRoot":"","sources":["../../src/transform/plugins/code.ts"],"names":[],"mappings":";AAAA,4BAA4B;AAK5B,mCAAuD;AAEvD,MAAM,uBAAuB,GAAG,CAC5B,OAA2B,EAC3B,EAAU,EACV,YAAqB,EACvB,EAAE;IACA,MAAM,WAAW,GAAG,YAAY,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE,CAAC;IAC7D,MAAM,WAAW,GAAG,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;IACpD,MAAM,cAAc,GAAG,YAAY;QAC/B,CAAC,CAAC,gKAAgK,WAAW,iFAAiF,WAAW;;;;;;;;;kBAS/P;QACV,CAAC,CAAC,EAAE,CAAC;IAET,OAAO;;UAED,OAAO;;cAEH,cAAc;;;;2HAI+F,EAAE;;;;;;;;;;;;;oDAazE,EAAE;;;;;;;;;gDASN,EAAE;;;;;uDAKK,EAAE;;;;;;;;;;CAUxD,CAAC;AACF,CAAC,CAAC;AAQF,SAAS,WAAW,CAChB,GAAW,EACX,GAAY,EACZ,MAA+B,EAC/B,UAAuB;IAEvB,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC;SAClC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SACxB,GAAG,CAAC,MAAM,CAAC;SACX,IAAI,CAAC,GAAG,CAAC,CAAC;IACf,MAAM,OAAO,GAAG,yBAAyB,GAAG,QAAQ,GAAG,OAAO,C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G,CAAC;YACzC,CAAC,CAAC,CAAC;QACP,CAAC;QAED,MAAM,kBAAkB,GACpB,SAAS,KAAI,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,KAAK,CAAA;YACnB,CAAC,CAAC,WAAW,CAAC,SAAS,EAAE,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE,UAAU,CAAC;YAC5D,CAAC,CAAC,SAAS,CAAC;QAEpB,OAAO,uBAAuB,CAAC,kBAAkB,EAAE,GAAG,EAAE,YAAY,CAAC,CAAC;IAC1E,CAAC,CAAC;AACN,CAAC,CAAC;AAEF,iBAAS,IAAI,CAAC"}
|
package/package.json
CHANGED
package/src/js/code.ts
CHANGED
|
@@ -3,6 +3,7 @@ import {copyToClipboard, getEventTarget, isCustom} from './utils';
|
|
|
3
3
|
const COPY_BUTTON_SELECTOR = '.yfm-clipboard-button';
|
|
4
4
|
const WRAP_BUTTON_SELECTOR = '.yfm-wrapping-button';
|
|
5
5
|
const FLOATING_CONTAINER_SELECTOR = '.yfm-code-floating-container';
|
|
6
|
+
const SELECTED_WRAP_BUTTON = 'g-button_selected';
|
|
6
7
|
|
|
7
8
|
function notifySuccess(svgButton: HTMLElement | null) {
|
|
8
9
|
if (!svgButton) {
|
|
@@ -56,8 +57,10 @@ function buttonWrapFn(target: HTMLElement) {
|
|
|
56
57
|
if (!button || !container || !code) {
|
|
57
58
|
return;
|
|
58
59
|
}
|
|
59
|
-
code.classList.toggle('wrap');
|
|
60
|
-
|
|
60
|
+
const hasWrap = code.classList.toggle('wrap');
|
|
61
|
+
|
|
62
|
+
button.classList.toggle(SELECTED_WRAP_BUTTON, hasWrap);
|
|
63
|
+
button.setAttribute('aria-pressed', String(hasWrap));
|
|
61
64
|
|
|
62
65
|
setTimeout(() => target.blur(), 500);
|
|
63
66
|
}
|
|
@@ -8,10 +8,12 @@ import {generateID as globalGenerateID} from './utils';
|
|
|
8
8
|
const wrapInFloatingContainer = (
|
|
9
9
|
element: string | undefined,
|
|
10
10
|
id: number,
|
|
11
|
-
|
|
11
|
+
lineWrapping: boolean,
|
|
12
12
|
) => {
|
|
13
|
+
const activeClass = lineWrapping ? ' g-button_selected' : '';
|
|
14
|
+
const ariaPressed = lineWrapping ? 'true' : 'false';
|
|
13
15
|
const wrappingButton = lineWrapping
|
|
14
|
-
? `<button role="button" class="g-button g-button_view_flat g-button_size_m g-button_pin_round-round g-md-viewer-code-button yfm-code-button yfm-wrapping-button" tabindex="-1" type="button" aria-label="Toggle line wrapping"aria-pressed="
|
|
16
|
+
? `<button role="button" class="g-button g-button_view_flat g-button_size_m g-button_pin_round-round g-md-viewer-code-button yfm-code-button yfm-wrapping-button${activeClass}" tabindex="-1" type="button" aria-label="Toggle line wrapping" aria-pressed="${ariaPressed}" data-tabindex="0">
|
|
15
17
|
<span class="g-button__icon">
|
|
16
18
|
<span class="g-button__icon-inner"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" class="g-icon" fill="currentColor" stroke="none" aria-hidden="true">
|
|
17
19
|
<svg class="yfm-code-icon yfm-wrapping-icon" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16">
|
|
@@ -170,6 +172,9 @@ const code: MarkdownItPluginCb<CodeOptions> = (md, opts) => {
|
|
|
170
172
|
md.renderer.rules.fence = function (tokens, idx, options, env, self) {
|
|
171
173
|
const token = tokens[idx];
|
|
172
174
|
const showLineNumbers = token.info.includes('showLineNumbers');
|
|
175
|
+
const wrapLines = token.info.includes('wrap');
|
|
176
|
+
|
|
177
|
+
const shouldWrap = lineWrapping || wrapLines;
|
|
173
178
|
|
|
174
179
|
let superCode = superCodeRenderer?.(tokens, idx, options, env, self);
|
|
175
180
|
|
|
@@ -185,12 +190,21 @@ const code: MarkdownItPluginCb<CodeOptions> = (md, opts) => {
|
|
|
185
190
|
}
|
|
186
191
|
}
|
|
187
192
|
|
|
193
|
+
if (superCode && shouldWrap) {
|
|
194
|
+
superCode = superCode.replace(/<code([^>]*)>/, (_match, attrs) => {
|
|
195
|
+
if (attrs.includes('class=')) {
|
|
196
|
+
return `<code${attrs.replace(/class="([^"]*)"/, 'class="$1 wrap"')}>`;
|
|
197
|
+
}
|
|
198
|
+
return `<code class="wrap"${attrs}>`;
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
188
202
|
const superCodeWithTerms =
|
|
189
203
|
superCode && env?.terms
|
|
190
204
|
? termReplace(superCode, env, md.utils.escapeRE, generateID)
|
|
191
205
|
: superCode;
|
|
192
206
|
|
|
193
|
-
return wrapInFloatingContainer(superCodeWithTerms, idx,
|
|
207
|
+
return wrapInFloatingContainer(superCodeWithTerms, idx, lineWrapping);
|
|
194
208
|
};
|
|
195
209
|
};
|
|
196
210
|
|