@diplodoc/transform 4.60.2 → 4.60.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.
Files changed (43) hide show
  1. package/dist/css/_yfm-only.css +6 -6
  2. package/dist/css/_yfm-only.css.map +3 -3
  3. package/dist/css/_yfm-only.min.css +1 -1
  4. package/dist/css/_yfm-only.min.css.map +3 -3
  5. package/dist/css/base.css +4 -2
  6. package/dist/css/base.css.map +3 -3
  7. package/dist/css/base.min.css +1 -1
  8. package/dist/css/base.min.css.map +3 -3
  9. package/dist/css/print.css.map +1 -1
  10. package/dist/css/yfm.css +11 -11
  11. package/dist/css/yfm.css.map +3 -3
  12. package/dist/css/yfm.min.css +1 -1
  13. package/dist/css/yfm.min.css.map +3 -3
  14. package/dist/js/base.js +5 -0
  15. package/dist/js/base.js.map +2 -2
  16. package/dist/js/base.min.js +1 -1
  17. package/dist/js/base.min.js.map +3 -3
  18. package/dist/js/yfm.js +22 -39
  19. package/dist/js/yfm.js.map +4 -4
  20. package/dist/js/yfm.min.js +1 -1
  21. package/dist/js/yfm.min.js.map +4 -4
  22. package/lib/plugins/inline-code/constant.d.ts +1 -1
  23. package/lib/plugins/inline-code/index.d.ts +1 -1
  24. package/lib/plugins/inline-code/index.js +4 -3
  25. package/lib/plugins/inline-code/index.js.map +1 -1
  26. package/lib/plugins/meta.d.ts +2 -2
  27. package/lib/plugins/meta.js +50 -5
  28. package/lib/plugins/meta.js.map +1 -1
  29. package/package.json +3 -3
  30. package/src/js/code.ts +4 -0
  31. package/src/js/inline-code/index.ts +5 -0
  32. package/src/scss/_code.scss +5 -2
  33. package/src/scss/_common.scss +12 -10
  34. package/src/scss/_inline-code.scss +9 -9
  35. package/src/scss/_note.scss +5 -3
  36. package/src/scss/_term.scss +9 -9
  37. package/src/scss/_yfm-only.scss +5 -5
  38. package/src/scss/base.scss +4 -4
  39. package/src/scss/print.scss +8 -8
  40. package/src/scss/yfm.scss +7 -6
  41. package/src/transform/plugins/inline-code/constant.ts +1 -1
  42. package/src/transform/plugins/inline-code/index.ts +5 -2
  43. package/src/transform/plugins/meta.ts +67 -3
package/src/js/code.ts CHANGED
@@ -8,6 +8,7 @@ function notifySuccess(svgButton: HTMLElement | null) {
8
8
  }
9
9
 
10
10
  const id = svgButton.getAttribute('data-animation');
11
+
11
12
  // @ts-expect-error
12
13
  const icon = svgButton.getRootNode().getElementById(`visibileAnimation-${id}`);
13
14
 
@@ -26,6 +27,7 @@ function buttonCopyFn(target: HTMLElement) {
26
27
  }
27
28
 
28
29
  const code = parent.querySelector<HTMLElement>('pre code');
30
+
29
31
  if (!code) {
30
32
  return;
31
33
  }
@@ -44,6 +46,8 @@ function buttonCopyFn(target: HTMLElement) {
44
46
 
45
47
  copyToClipboard(textContent).then(() => {
46
48
  notifySuccess(parent.querySelector('.yfm-clipboard-icon'));
49
+
50
+ setTimeout(() => target.blur(), 1500);
47
51
  });
48
52
  }
49
53
 
@@ -37,6 +37,11 @@ if (typeof document !== 'undefined') {
37
37
  document.addEventListener('keydown', (event) => {
38
38
  if (event.key === 'Enter' && document.activeElement) {
39
39
  const activeElement = document.activeElement as HTMLElement;
40
+ const classInlineCode = INLINE_CODE.replace('.', '');
41
+
42
+ if (!activeElement.classList.contains(classInlineCode)) {
43
+ return;
44
+ }
40
45
 
41
46
  const innerText = activeElement.innerText;
42
47
 
@@ -2,11 +2,14 @@
2
2
  &-clipboard {
3
3
  position: relative;
4
4
 
5
+ .yfm-clipboard-button {
6
+ min-width: 20px;
7
+ min-height: 20px;
8
+ }
9
+
5
10
  &:hover {
6
11
  .yfm-clipboard-button {
7
12
  opacity: 1;
8
- min-height: 20px;
9
- min-width: 20px;
10
13
  }
11
14
  }
12
15
 
@@ -1,8 +1,8 @@
1
1
  /* stylelint-disable declaration-no-important */
2
2
 
3
- @import 'private';
4
- @import 'brand';
5
- @import 'lists';
3
+ @use 'private';
4
+ @use 'brand';
5
+ @use 'lists';
6
6
 
7
7
  @mixin removeMarginForEdgeChildren {
8
8
  & > *:first-child {
@@ -15,8 +15,8 @@
15
15
  }
16
16
 
17
17
  .yfm {
18
- @include private-brand();
19
- @include brand();
18
+ @include private.private-brand();
19
+ @include brand.brand();
20
20
 
21
21
  font-family: var(--yfm-font-family-sans);
22
22
  font-size: 15px;
@@ -25,6 +25,13 @@
25
25
  color: var(--yfm-color-text);
26
26
  tab-size: var(--yfm-tab-size, inherit);
27
27
 
28
+ --yfm-font-family-monospace:
29
+ 'Menlo', 'Monaco', 'Consolas', 'Ubuntu Mono', 'Liberation Mono', 'DejaVu Sans Mono',
30
+ 'Courier New', 'Courier', monospace;
31
+ --yfm-font-family-sans:
32
+ 'Segoe UI', arial, helvetica, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji',
33
+ 'Segoe UI Symbol';
34
+
28
35
  * {
29
36
  box-sizing: border-box;
30
37
  }
@@ -413,9 +420,4 @@
413
420
  clip-path: inset(100%);
414
421
  user-select: none;
415
422
  }
416
-
417
- --yfm-font-family-monospace: 'Menlo', 'Monaco', 'Consolas', 'Ubuntu Mono', 'Liberation Mono',
418
- 'DejaVu Sans Mono', 'Courier New', 'Courier', monospace;
419
- --yfm-font-family-sans: 'Segoe UI', arial, helvetica, sans-serif, 'Apple Color Emoji',
420
- 'Segoe UI Emoji', 'Segoe UI Symbol';
421
423
  }
@@ -2,15 +2,6 @@
2
2
  position: absolute;
3
3
  z-index: 100;
4
4
 
5
- width: fit-content;
6
- max-width: 450px;
7
-
8
- @media screen and (max-width: 600px) {
9
- & {
10
- max-width: 80%;
11
- }
12
- }
13
-
14
5
  visibility: hidden;
15
6
  opacity: 0;
16
7
 
@@ -26,6 +17,15 @@
26
17
 
27
18
  box-shadow: 0 8px 20px var(--yfm-color-term-dfn-shadow);
28
19
  outline: none;
20
+ width: fit-content;
21
+
22
+ max-width: 450px;
23
+
24
+ @media screen and (max-width: 600px) {
25
+ & {
26
+ max-width: 80%;
27
+ }
28
+ }
29
29
 
30
30
  &::before {
31
31
  content: '';
@@ -1,3 +1,5 @@
1
+ @use 'sass:color';
2
+
1
3
  .yfm .yfm-note {
2
4
  max-width: 1296px;
3
5
  margin: 20px 0;
@@ -40,9 +42,9 @@
40
42
 
41
43
  @each $type, $color in $colors {
42
44
  &.#{$type} > :first-child::before {
43
- $r: red($color);
44
- $g: green($color);
45
- $b: blue($color);
45
+ $r: color.channel($color, 'red', $space: rgb);
46
+ $g: color.channel($color, 'green', $space: rgb);
47
+ $b: color.channel($color, 'blue', $space: rgb);
46
48
  $rgbColor: 'rgb(' + $r + ',' + $g + ',' + $b + ')';
47
49
  content: url('data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 16 16"%3E%3Ccircle cx="8" cy="8" r="8" fill="' + $rgbColor + '"/%3E%3Crect width="1" height="5" x="7.5" y="6.5" stroke="%23fff" rx=".5"/%3E%3Ccircle cx="8" cy="4" r="1" fill="%23fff"/%3E%3C/svg%3E');
48
50
  }
@@ -18,15 +18,6 @@
18
18
  position: absolute;
19
19
  z-index: 100;
20
20
 
21
- width: fit-content;
22
- max-width: 450px;
23
-
24
- @media screen and (max-width: 600px) {
25
- & {
26
- max-width: 80%;
27
- }
28
- }
29
-
30
21
  visibility: hidden;
31
22
  opacity: 0;
32
23
 
@@ -43,6 +34,15 @@
43
34
  box-shadow: 0 8px 20px var(--yfm-color-term-dfn-shadow);
44
35
  outline: none;
45
36
 
37
+ width: fit-content;
38
+ max-width: 450px;
39
+
40
+ @media screen and (max-width: 600px) {
41
+ & {
42
+ max-width: 80%;
43
+ }
44
+ }
45
+
46
46
  &::before {
47
47
  content: '';
48
48
  position: absolute;
@@ -6,8 +6,8 @@
6
6
  as the file is subject to changes without prior notice.
7
7
  */
8
8
 
9
- @import 'note';
10
- @import 'katex';
11
- @import 'table';
12
- @import 'term';
13
- @import 'inline-code';
9
+ @use 'note';
10
+ @use 'katex';
11
+ @use 'table';
12
+ @use 'term';
13
+ @use 'inline-code';
@@ -1,4 +1,4 @@
1
- @import 'common';
2
- @import 'anchor';
3
- @import 'highlight';
4
- @import 'code';
1
+ @use 'common';
2
+ @use 'anchor';
3
+ @use 'highlight';
4
+ @use 'code';
@@ -1,8 +1,8 @@
1
- @import 'print/code';
2
- @import 'print/common';
3
- @import 'print/cut';
4
- @import 'print/note';
5
- @import 'print/table';
6
- @import 'print/tabs';
7
- @import 'print/term';
8
- @import 'print/iframe';
1
+ @use 'print/code';
2
+ @use 'print/common';
3
+ @use 'print/cut';
4
+ @use 'print/note';
5
+ @use 'print/table';
6
+ @use 'print/tabs';
7
+ @use 'print/term';
8
+ @use 'print/iframe';
package/src/scss/yfm.scss CHANGED
@@ -1,6 +1,7 @@
1
- @import 'base';
2
- @import 'yfm-only';
3
- @import 'modal';
4
- @import '@diplodoc/cut-extension/runtime';
5
- @import '@diplodoc/file-extension/runtime';
6
- @import '@diplodoc/tabs-extension/runtime';
1
+ @use 'base';
2
+ @use 'yfm-only';
3
+ @use 'modal';
4
+
5
+ @forward '@diplodoc/cut-extension/runtime';
6
+ @forward '@diplodoc/file-extension/runtime';
7
+ @forward '@diplodoc/tabs-extension/runtime';
@@ -1,4 +1,4 @@
1
- import {Lang} from '../typings';
1
+ import type {Lang} from '../typings';
2
2
 
3
3
  export const LANG_TOKEN: Record<Lang, string> = {
4
4
  ru: 'Скопировано',
@@ -1,4 +1,7 @@
1
- import {MarkdownItPluginCb, StateCore} from '../../typings';
1
+ import type {MarkdownItPluginCb, StateCore} from '../../typings';
2
+
3
+ import {escapeHtml} from 'markdown-it/lib/common/utils';
4
+
2
5
  import {generateID} from '../utils';
3
6
 
4
7
  import {LANG_TOKEN, LANG_TOKEN_DESCRIPTION, LANG_TOKEN_LABEL} from './constant';
@@ -12,7 +15,7 @@ const inlineCode: MarkdownItPluginCb = (md, options) => {
12
15
  const description = LANG_TOKEN_DESCRIPTION[lang] ?? LANG_TOKEN_DESCRIPTION.en;
13
16
  const label = LANG_TOKEN_LABEL[lang] ?? LANG_TOKEN_LABEL.en;
14
17
 
15
- return `<code class="yfm-clipboard-inline-code" role="button" aria-label="${label}" aria-description="${description}" tabindex='0' id="${id}">${tokens[idx].content}</code>`;
18
+ return `<code class="yfm-clipboard-inline-code" role="button" aria-label="${label}" aria-description="${description}" tabindex='0' id="inline-code-id-${id}">${escapeHtml(tokens[idx].content)}</code>`;
16
19
  };
17
20
 
18
21
  md.core.ruler.after('inline', 'tooltip_code_inline', (state: StateCore) => {
@@ -1,6 +1,70 @@
1
1
  import type {MarkdownItPluginCb} from './typings';
2
2
 
3
- // @ts-expect-error
4
- import meta from 'markdown-it-meta';
3
+ import {load} from 'js-yaml';
5
4
 
6
- export = meta as MarkdownItPluginCb;
5
+ /* eslint-disable @typescript-eslint/no-explicit-any */
6
+
7
+ const SEP = '---';
8
+
9
+ const meta: MarkdownItPluginCb = (md) => {
10
+ const mdAny = md as any;
11
+ mdAny.meta = mdAny.meta || {};
12
+
13
+ const getLine = (state: any, line: number) =>
14
+ state.src.slice(state.bMarks[line], state.eMarks[line]);
15
+
16
+ md.block.ruler.before(
17
+ 'code',
18
+ 'meta',
19
+ (state, startLine, endLine) => {
20
+ if (startLine !== 0 || state.blkIndent !== 0) {
21
+ return false;
22
+ }
23
+ if (state.tShift[startLine] < 0) {
24
+ return false;
25
+ }
26
+ if (getLine(state, startLine).trim() !== SEP) {
27
+ return false;
28
+ }
29
+
30
+ let line = startLine + 1;
31
+ const lines: string[] = [];
32
+ let found = false;
33
+
34
+ while (line < endLine) {
35
+ const str = getLine(state, line);
36
+ if (str.trim() === SEP) {
37
+ found = true;
38
+ break;
39
+ }
40
+ if (state.tShift[line] < 0) {
41
+ return false;
42
+ }
43
+ lines.push(str);
44
+ line++;
45
+ }
46
+
47
+ if (!found) {
48
+ return false;
49
+ }
50
+
51
+ let data: unknown;
52
+ try {
53
+ data = load(lines.join('\n')) || {};
54
+ } catch {
55
+ return false;
56
+ }
57
+
58
+ if (typeof data !== 'object' || data === null || Array.isArray(data)) {
59
+ return false;
60
+ }
61
+
62
+ mdAny.meta = data as Record<string, unknown>;
63
+ state.line = line + 1;
64
+ return true;
65
+ },
66
+ {alt: []},
67
+ );
68
+ };
69
+
70
+ export = meta;