@diplodoc/transform 4.76.6 → 4.76.8
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 +13 -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 +15 -3
package/lib/plugins/code.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
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
5
|
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="false" data-tabindex="0">
|
|
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="false" data-tabindex="0">
|
|
7
7
|
<span class="g-button__icon">
|
|
8
8
|
<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
9
|
<svg class="yfm-code-icon yfm-wrapping-icon" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16">
|
|
@@ -125,6 +125,8 @@ const code = (md, opts) => {
|
|
|
125
125
|
md.renderer.rules.fence = function (tokens, idx, options, env, self) {
|
|
126
126
|
const token = tokens[idx];
|
|
127
127
|
const showLineNumbers = token.info.includes('showLineNumbers');
|
|
128
|
+
const wrapLines = token.info.includes('wrap');
|
|
129
|
+
const shouldWrap = wrapLines;
|
|
128
130
|
let superCode = superCodeRenderer === null || superCodeRenderer === void 0 ? void 0 : superCodeRenderer(tokens, idx, options, env, self);
|
|
129
131
|
if (superCode && showLineNumbers) {
|
|
130
132
|
// Extract the code content from the pre/code tags
|
|
@@ -137,10 +139,18 @@ const code = (md, opts) => {
|
|
|
137
139
|
superCode = superCode.replace(codeContent, escapedReplacement);
|
|
138
140
|
}
|
|
139
141
|
}
|
|
142
|
+
if (superCode && shouldWrap) {
|
|
143
|
+
superCode = superCode.replace(/<code([^>]*)>/, (_match, attrs) => {
|
|
144
|
+
if (attrs.includes('class=')) {
|
|
145
|
+
return `<code${attrs.replace(/class="([^"]*)"/, 'class="$1 wrap"')}>`;
|
|
146
|
+
}
|
|
147
|
+
return `<code class="wrap"${attrs}>`;
|
|
148
|
+
});
|
|
149
|
+
}
|
|
140
150
|
const superCodeWithTerms = superCode && (env === null || env === void 0 ? void 0 : env.terms)
|
|
141
151
|
? termReplace(superCode, env, md.utils.escapeRE, generateID)
|
|
142
152
|
: superCode;
|
|
143
|
-
return wrapInFloatingContainer(superCodeWithTerms, idx,
|
|
153
|
+
return wrapInFloatingContainer(superCodeWithTerms, idx, lineWrapping);
|
|
144
154
|
};
|
|
145
155
|
};
|
|
146
156
|
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,cAAc,GAAG,YAAY;QAC/B,CAAC,CAAC;;;;;;;;;kBASQ;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,CAAC;IAC/D,MAAM,GAAG,GAAG,IAAI,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IAErC,MAAM,QAAQ,GAAG,GAAG,CAAC,OAAO,CACxB,GAAG,EACH,CAAC,MAAc,EAAE,EAAU,EAAE,GAAW,EAAE,EAAU,EAAE,EAAE,CACpD,4CAA4C,EAAE,SAAS,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,CACzF,CAAC;IAEF,OAAO,QAAQ,IA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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,10 @@ 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
13
|
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="false" data-tabindex="0">
|
|
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="false" data-tabindex="0">
|
|
15
15
|
<span class="g-button__icon">
|
|
16
16
|
<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
17
|
<svg class="yfm-code-icon yfm-wrapping-icon" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16">
|
|
@@ -170,6 +170,9 @@ const code: MarkdownItPluginCb<CodeOptions> = (md, opts) => {
|
|
|
170
170
|
md.renderer.rules.fence = function (tokens, idx, options, env, self) {
|
|
171
171
|
const token = tokens[idx];
|
|
172
172
|
const showLineNumbers = token.info.includes('showLineNumbers');
|
|
173
|
+
const wrapLines = token.info.includes('wrap');
|
|
174
|
+
|
|
175
|
+
const shouldWrap = wrapLines;
|
|
173
176
|
|
|
174
177
|
let superCode = superCodeRenderer?.(tokens, idx, options, env, self);
|
|
175
178
|
|
|
@@ -185,12 +188,21 @@ const code: MarkdownItPluginCb<CodeOptions> = (md, opts) => {
|
|
|
185
188
|
}
|
|
186
189
|
}
|
|
187
190
|
|
|
191
|
+
if (superCode && shouldWrap) {
|
|
192
|
+
superCode = superCode.replace(/<code([^>]*)>/, (_match, attrs) => {
|
|
193
|
+
if (attrs.includes('class=')) {
|
|
194
|
+
return `<code${attrs.replace(/class="([^"]*)"/, 'class="$1 wrap"')}>`;
|
|
195
|
+
}
|
|
196
|
+
return `<code class="wrap"${attrs}>`;
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
188
200
|
const superCodeWithTerms =
|
|
189
201
|
superCode && env?.terms
|
|
190
202
|
? termReplace(superCode, env, md.utils.escapeRE, generateID)
|
|
191
203
|
: superCode;
|
|
192
204
|
|
|
193
|
-
return wrapInFloatingContainer(superCodeWithTerms, idx,
|
|
205
|
+
return wrapInFloatingContainer(superCodeWithTerms, idx, lineWrapping);
|
|
194
206
|
};
|
|
195
207
|
};
|
|
196
208
|
|