@diplodoc/transform 4.58.0 → 4.59.0

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 (64) hide show
  1. package/dist/css/_yfm-only.css +57 -0
  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 +10 -0
  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 +67 -0
  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/_yfm-only.js.map +2 -2
  15. package/dist/js/_yfm-only.min.js.map +2 -2
  16. package/dist/js/base.js +233 -18
  17. package/dist/js/base.js.map +3 -3
  18. package/dist/js/base.min.js +1 -1
  19. package/dist/js/base.min.js.map +4 -4
  20. package/dist/js/yfm.js +213 -18
  21. package/dist/js/yfm.js.map +4 -4
  22. package/dist/js/yfm.min.js +1 -1
  23. package/dist/js/yfm.min.js.map +4 -4
  24. package/lib/frontmatter.js +1 -1
  25. package/lib/index.js.map +1 -1
  26. package/lib/plugins/changelog/index.js +2 -1
  27. package/lib/plugins/changelog/index.js.map +1 -1
  28. package/lib/plugins/images/collect.js +1 -1
  29. package/lib/plugins/images/collect.js.map +1 -1
  30. package/lib/plugins/images/index.js +3 -3
  31. package/lib/plugins/images/index.js.map +1 -1
  32. package/lib/plugins/inline-code/constant.d.ts +4 -0
  33. package/lib/plugins/inline-code/constant.js +58 -0
  34. package/lib/plugins/inline-code/constant.js.map +1 -0
  35. package/lib/plugins/inline-code/index.d.ts +3 -0
  36. package/lib/plugins/inline-code/index.js +45 -0
  37. package/lib/plugins/inline-code/index.js.map +1 -0
  38. package/lib/plugins.js +2 -0
  39. package/lib/plugins.js.map +1 -1
  40. package/lib/utils.d.ts +1 -0
  41. package/lib/utils.js +11 -1
  42. package/lib/utils.js.map +1 -1
  43. package/package.json +1 -1
  44. package/src/js/base.ts +1 -0
  45. package/src/js/code.ts +32 -26
  46. package/src/js/inline-code/constant.ts +3 -0
  47. package/src/js/inline-code/index.ts +76 -0
  48. package/src/js/inline-code/utils.ts +190 -0
  49. package/src/js/term/utils.ts +1 -1
  50. package/src/scss/_code.scss +9 -0
  51. package/src/scss/_inline-code.scss +59 -0
  52. package/src/scss/_table.scss +12 -0
  53. package/src/scss/_yfm-only.scss +1 -0
  54. package/src/scss/brand.scss +1 -0
  55. package/src/scss/private.scss +2 -0
  56. package/src/transform/frontmatter.ts +1 -1
  57. package/src/transform/index.ts +0 -1
  58. package/src/transform/plugins/changelog/index.ts +3 -1
  59. package/src/transform/plugins/images/collect.ts +2 -2
  60. package/src/transform/plugins/images/index.ts +4 -4
  61. package/src/transform/plugins/inline-code/constant.ts +58 -0
  62. package/src/transform/plugins/inline-code/index.ts +58 -0
  63. package/src/transform/plugins.ts +2 -0
  64. package/src/transform/utils.ts +10 -0
@@ -6,11 +6,13 @@
6
6
  --yfm-color-table-private: #333;
7
7
  --yfm-color-border-private: rgba(0, 0, 0, 0.07);
8
8
  --yfm-color-table-row-background-private: rgba(0, 0, 0, 0.02);
9
+ --yfm-color-table-row-header-background-primary: rgba(247, 247, 247, 1);
9
10
  --yfm-color-accent-private: #027bf3;
10
11
 
11
12
  --yfm-color-inline-code-private: rgba(59, 96, 128, 1);
12
13
  --yfm-color-inline-code-background-private: rgba(107, 132, 153, 0.12);
13
14
  --yfm-color-code-background-private: rgba(107, 132, 153, 0.12);
15
+ --yfm-color-code-background-hovered-private: rgba(107, 132, 153, 0.2);
14
16
 
15
17
  --yfm-color-hljs-background-private: rgba(107, 132, 153, 0.12);
16
18
  --yfm-color-hljs-subst-private: #444;
@@ -23,7 +23,7 @@ const escapeLiquid = (content: string): string =>
23
23
 
24
24
  /**
25
25
  * Inverse of a workaround defined above.
26
- * @see `escapeLiquidSubstitutionSyntax`
26
+ * @see `escapeLiquid`
27
27
  * @param escapedContent Input string with `{}` escaped with backslashes
28
28
  * @returns Unescaped string
29
29
  */
@@ -47,7 +47,6 @@ function transform(originInput: string, options: OptionsType = {}): OutputType |
47
47
  if (options.tokens === true) {
48
48
  return tokens;
49
49
  }
50
-
51
50
  return emitResult(compile(tokens), env);
52
51
  } catch (error) {
53
52
  handleError(error, options.path);
@@ -6,6 +6,8 @@ import type {MarkdownItPluginCb} from '../typings';
6
6
  import {bold} from 'chalk';
7
7
  import yaml from 'js-yaml';
8
8
 
9
+ import {getSrcTokenAttr} from '../../utils';
10
+
9
11
  interface Options {
10
12
  extractChangelogs?: boolean;
11
13
  }
@@ -85,7 +87,7 @@ function parseBody(tokens: Token[], state: StateCore) {
85
87
  alt = md.renderer.renderInlineAsText(imageToken.children, md.options, env);
86
88
  }
87
89
  image = {
88
- src: imageToken.attrGet('src'),
90
+ src: getSrcTokenAttr(imageToken),
89
91
  alt,
90
92
  ratio,
91
93
  };
@@ -3,7 +3,7 @@ import type {MarkdownItPluginOpts} from '../typings';
3
3
  import MarkdownIt from 'markdown-it';
4
4
  import {relative} from 'path';
5
5
 
6
- import {isLocalUrl} from '../../utils';
6
+ import {getSrcTokenAttr, isLocalUrl} from '../../utils';
7
7
  import {resolveRelativePath} from '../../utilsFS';
8
8
  import deflist from '../deflist';
9
9
  import imsize from '../imsize';
@@ -33,7 +33,7 @@ const collect = (input: string, options: Options) => {
33
33
  return;
34
34
  }
35
35
 
36
- const src = childToken.attrGet('src') || '';
36
+ const src = getSrcTokenAttr(childToken);
37
37
 
38
38
  if (!isLocalUrl(src)) {
39
39
  return;
@@ -8,7 +8,7 @@ import {optimize} from 'svgo';
8
8
  import {readFileSync} from 'fs';
9
9
 
10
10
  import {isFileExists, resolveRelativePath} from '../../utilsFS';
11
- import {isExternalHref, isLocalUrl} from '../../utils';
11
+ import {getSrcTokenAttr, isExternalHref, isLocalUrl} from '../../utils';
12
12
 
13
13
  interface ImageOpts extends MarkdownItPluginOpts {
14
14
  assetsPublicPath: string;
@@ -20,7 +20,7 @@ function replaceImageSrc(
20
20
  state: StateCore,
21
21
  {assetsPublicPath = sep, root = '', path: optsPath, log}: ImageOpts,
22
22
  ) {
23
- const src = token.attrGet('src') || '';
23
+ const src = getSrcTokenAttr(token);
24
24
  const currentPath = state.env.path || optsPath;
25
25
 
26
26
  if (!isLocalUrl(src)) {
@@ -57,7 +57,7 @@ function convertSvg(
57
57
  {path: optsPath, log, notFoundCb, root}: SVGOpts,
58
58
  ) {
59
59
  const currentPath = state.env.path || optsPath;
60
- const path = resolveRelativePath(currentPath, token.attrGet('src') || '');
60
+ const path = resolveRelativePath(currentPath, getSrcTokenAttr(token));
61
61
 
62
62
  try {
63
63
  const raw = readFileSync(path).toString();
@@ -114,7 +114,7 @@ const index: MarkdownItPluginCb<Opts> = (md, opts) => {
114
114
  return;
115
115
  }
116
116
 
117
- const imgSrc = childrenTokens[j].attrGet('src') || '';
117
+ const imgSrc = getSrcTokenAttr(childrenTokens[j]);
118
118
  const shouldInlineSvg = opts.inlineSvg !== false && !isExternalHref(imgSrc);
119
119
 
120
120
  if (imgSrc.endsWith('.svg') && shouldInlineSvg) {
@@ -0,0 +1,58 @@
1
+ import {Lang} from '../typings';
2
+
3
+ export const LANG_TOKEN: Record<Lang, string> = {
4
+ ru: 'Скопировано',
5
+ en: 'Copied',
6
+ ar: 'تم النسخ',
7
+ cs: 'Zkopírováno',
8
+ fr: 'Copié',
9
+ es: 'Copiado',
10
+ he: 'הועתק',
11
+ bg: 'Копирано',
12
+ et: 'Kopeeritud',
13
+ el: 'Αντιγράφηκε',
14
+ pt: 'Copiado',
15
+ zh: '已复制',
16
+ 'zh-tw': '已複製',
17
+ kk: 'Көшірілді',
18
+ tr: 'Kopyalandı',
19
+ uz: 'Nusxalandi',
20
+ };
21
+
22
+ export const LANG_TOKEN_DESCRIPTION: Record<Lang, string> = {
23
+ ru: 'Чтобы скопировать текст внутри блока нажмите на блок',
24
+ en: 'To copy the text inside the block, click on the block',
25
+ ar: 'لنسخ النص داخل المربع، انقر على المربع',
26
+ cs: 'Chcete-li zkopírovat text uvnitř bloku, klikněte na blok',
27
+ fr: "Pour copier le texte à l'intérieur du bloc, cliquez sur le bloc",
28
+ es: 'Para copiar el texto dentro del bloque, haga clic en el bloque',
29
+ he: 'כדי להעתיק את הטקסט בתוך הבלוק, לחץ על הבלוק',
30
+ bg: 'За да копирате текста във блока, кликнете върху блока',
31
+ et: 'Teksti kopeerimiseks plokis klõpsake plokil',
32
+ el: 'Για να αντιγράψετε το κείμενο μέσα στο μπλοκ, κάντε κλικ στο μπλοκ',
33
+ pt: 'Para copiar o texto dentro do bloco, clique no bloco',
34
+ zh: '要复制块内的文本,请点击该块',
35
+ 'zh-tw': '要複製區塊內的文字,請點擊該區塊',
36
+ kk: 'Блок ішіндегі мәтінді көшіру үшін блокты басыңыз',
37
+ tr: 'Blok içindeki metni kopyalamak için bloğa tıklayın',
38
+ uz: 'Blok ichidagi matnni nusxalash uchun blokni bosing',
39
+ };
40
+
41
+ export const LANG_TOKEN_LABEL: Record<Lang, string> = {
42
+ ru: 'Блок кода',
43
+ en: 'Code block',
44
+ ar: 'كتلة التعليمات البرمجية',
45
+ cs: 'Blok kódu',
46
+ fr: 'Bloc de code',
47
+ es: 'Bloque de código',
48
+ he: 'בלוק קוד',
49
+ bg: 'Блок с код',
50
+ et: 'Koodiplokk',
51
+ el: 'Μπλοκ κώδικα',
52
+ pt: 'Bloco de código',
53
+ zh: '代码块',
54
+ 'zh-tw': '代碼區塊',
55
+ kk: 'Код блогы',
56
+ tr: 'Kod bloğu',
57
+ uz: 'Kod bloki',
58
+ };
@@ -0,0 +1,58 @@
1
+ import {MarkdownItPluginCb, StateCore} from '../../typings';
2
+ import {generateID} from '../utils';
3
+
4
+ import {LANG_TOKEN, LANG_TOKEN_DESCRIPTION, LANG_TOKEN_LABEL} from './constant';
5
+
6
+ const inlineCode: MarkdownItPluginCb = (md, options) => {
7
+ const lang = options.lang;
8
+
9
+ md.renderer.rules.code_inline = function (tokens, idx) {
10
+ const id = generateID();
11
+
12
+ const description = LANG_TOKEN_DESCRIPTION[lang] ?? LANG_TOKEN_DESCRIPTION.en;
13
+ const label = LANG_TOKEN_LABEL[lang] ?? LANG_TOKEN_LABEL.en;
14
+
15
+ return `<code class="yfm-clipboard-inline-code" role="button" aria-label="${label}" aria-description="${description}" tabindex='0' id="${id}">${tokens[idx].content}</code>`;
16
+ };
17
+
18
+ md.core.ruler.after('inline', 'tooltip_code_inline', (state: StateCore) => {
19
+ const tokens = state.tokens;
20
+
21
+ for (let i = 0; i !== tokens.length; i++) {
22
+ const token = tokens[i];
23
+
24
+ if (token.type !== 'inline') {
25
+ continue;
26
+ }
27
+
28
+ if (!token.children || token.children.every((e) => e.type !== 'code_inline')) {
29
+ continue;
30
+ }
31
+
32
+ const child = token.children.find((e) => e.type === 'code_inline');
33
+
34
+ if (!child) {
35
+ return;
36
+ }
37
+
38
+ const dialog = new state.Token('tooltip_open', 'div', 1);
39
+ dialog.attrSet('class', 'yfm inline_code_tooltip');
40
+ dialog.attrSet('id', `tooltip_inline_clipboard_dialog`);
41
+ dialog.attrSet('role', 'dialog');
42
+ dialog.attrSet('aria-live', 'polite');
43
+ dialog.attrSet('aria-modal', 'true');
44
+
45
+ tokens.push(dialog);
46
+
47
+ const text = new state.Token('text', '', 0);
48
+ text.content = LANG_TOKEN[lang] ?? LANG_TOKEN.en;
49
+ tokens.push(text);
50
+
51
+ const closeDialog = new state.Token('tooltip_close', 'div', -1);
52
+ tokens.push(closeDialog);
53
+ break;
54
+ }
55
+ });
56
+ };
57
+
58
+ export = inlineCode;
@@ -15,6 +15,7 @@ import file from './plugins/file';
15
15
  import imsize from './plugins/imsize';
16
16
  import term from './plugins/term';
17
17
  import blockAnchor from './plugins/block-anchor';
18
+ import inlineCode from './plugins/inline-code';
18
19
 
19
20
  const defaultPlugins = [
20
21
  meta,
@@ -32,6 +33,7 @@ const defaultPlugins = [
32
33
  imsize,
33
34
  term,
34
35
  blockAnchor,
36
+ inlineCode,
35
37
  ] as MarkdownItPluginCb[];
36
38
 
37
39
  export = defaultPlugins;
@@ -92,6 +92,16 @@ export function getHrefTokenAttr(token: Token) {
92
92
  return href;
93
93
  }
94
94
 
95
+ export function getSrcTokenAttr(token: Token) {
96
+ let src = token.attrGet('src') || '';
97
+ try {
98
+ // decodeURI can throw an error https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError
99
+ src = decodeURI(src);
100
+ } catch (e) {}
101
+
102
+ return src;
103
+ }
104
+
95
105
  export const PAGE_LINK_REGEXP = /\.(md|ya?ml)$/i;
96
106
 
97
107
  export function defaultTransformLink(href: string) {