@diplodoc/transform 4.1.0 → 4.2.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.
@@ -0,0 +1,62 @@
1
+ const Selector = {
2
+ WRAPPED_TABLE: '.pdf .yfm-table-container table',
3
+ TABLE: '.pdf table',
4
+ };
5
+ const Padding = {
6
+ BOTTOM: 20,
7
+ };
8
+
9
+ function resizeElement(element: HTMLElement) {
10
+ const availableWidth = element.parentElement?.offsetWidth;
11
+ const contentWidth = (element.firstElementChild as HTMLElement).offsetWidth;
12
+
13
+ if (!availableWidth) {
14
+ return;
15
+ }
16
+
17
+ const needScale = contentWidth > availableWidth;
18
+
19
+ if (needScale) {
20
+ const scale = availableWidth / contentWidth;
21
+
22
+ element.style.transform = `scale(${scale})`;
23
+ }
24
+
25
+ element.parentElement.style.height = `${
26
+ element.getBoundingClientRect().height + Padding.BOTTOM
27
+ }px`;
28
+ }
29
+
30
+ function resizeElements() {
31
+ document.querySelectorAll(Selector.WRAPPED_TABLE).forEach((element) => {
32
+ resizeElement(element as HTMLElement);
33
+ });
34
+ }
35
+
36
+ function wrapTables() {
37
+ const tables = document.querySelectorAll(Selector.TABLE);
38
+
39
+ for (let i = 0; i < tables.length; i++) {
40
+ const table = tables[i];
41
+
42
+ const parent = table.parentNode;
43
+
44
+ if (!parent) {
45
+ continue;
46
+ }
47
+
48
+ const wrapper = document.createElement('div');
49
+ parent.insertBefore(wrapper, table);
50
+ wrapper.appendChild(table);
51
+ wrapper.classList.add('yfm-table-container');
52
+ }
53
+ }
54
+
55
+ if (typeof document !== 'undefined') {
56
+ window.addEventListener('load', () => {
57
+ wrapTables();
58
+ resizeElements();
59
+ });
60
+ }
61
+
62
+ export {};
@@ -22,15 +22,15 @@
22
22
  }
23
23
 
24
24
  &-content {
25
- height: 0;
25
+ display: none;
26
26
  overflow: hidden;
27
27
  transition: height 0.3s ease-in-out;
28
28
  }
29
29
 
30
30
  &.open {
31
31
  > #{$class}-content {
32
+ display: revert;
32
33
  padding: 5px 0 15px 30px;
33
- height: auto;
34
34
  }
35
35
 
36
36
  > #{$class}-title:before {
@@ -0,0 +1,9 @@
1
+ @media print {
2
+ .yfm {
3
+ .yfm-clipboard {
4
+ & > pre > code {
5
+ white-space: pre-wrap;
6
+ }
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,13 @@
1
+ @media print {
2
+ .yfm {
3
+ .yfm-page__delimeter {
4
+ display: none;
5
+ }
6
+
7
+ h1, h2 {
8
+ &[data-original-article] {
9
+ page-break-before: always;
10
+ }
11
+ }
12
+ }
13
+ }
@@ -0,0 +1,18 @@
1
+ @media print {
2
+ .yfm {
3
+ .yfm-cut {
4
+ &-title {
5
+ padding-left: 0;
6
+
7
+ &:before {
8
+ display: none;
9
+ }
10
+ }
11
+
12
+ &-content {
13
+ height: auto;
14
+ padding: 5px 0 15px 30px;
15
+ }
16
+ }
17
+ }
18
+ }
@@ -0,0 +1,7 @@
1
+ @media print {
2
+ .yfm {
3
+ .yfm-note {
4
+ page-break-inside: avoid;
5
+ }
6
+ }
7
+ }
@@ -0,0 +1,24 @@
1
+ .yfm {
2
+ .yfm-table-container {
3
+ position: relative;
4
+
5
+ & > table {
6
+ overflow: initial;
7
+ position: absolute;
8
+ top: 0;
9
+ left: 0;
10
+ max-width: initial;
11
+ transform-origin: top left;
12
+
13
+ thead {
14
+ display: table-row-group;
15
+ }
16
+
17
+ th, td {
18
+ page-break-inside: avoid;
19
+ white-space: pre-wrap;
20
+ text-overflow: initial;
21
+ }
22
+ }
23
+ }
24
+ }
@@ -0,0 +1,20 @@
1
+ @media print {
2
+ .yfm {
3
+ .yfm-tab {
4
+ &-list {
5
+ display: none;
6
+ }
7
+
8
+ &-panel:before {
9
+ content: attr(data-title);
10
+ margin-bottom: -1px;
11
+ margin-right: 20px;
12
+ border-bottom: 2px solid transparent;
13
+ line-height: 33px;
14
+ font-weight: 700;
15
+ outline: 0;
16
+ cursor: pointer;
17
+ }
18
+ }
19
+ }
20
+ }
@@ -0,0 +1,6 @@
1
+ @import 'print/code';
2
+ @import 'print/common';
3
+ @import 'print/cut';
4
+ @import 'print/note';
5
+ @import 'print/table';
6
+ @import 'print/tabs';
package/src/scss/yfm.scss CHANGED
@@ -3,7 +3,6 @@
3
3
  @import 'anchor';
4
4
  @import 'highlight';
5
5
  @import 'code';
6
- @import 'print';
7
6
  @import 'cut';
8
7
  @import 'file';
9
8
  @import 'term';
@@ -43,7 +43,7 @@ function transform(originInput: string, options: OptionsType = {}) {
43
43
 
44
44
  export = transform;
45
45
 
46
- // eslint-disable-next-line @typescript-eslint/no-namespace -- backward compatibility
46
+ // eslint-disable-next-line @typescript-eslint/no-namespace, no-redeclare -- backward compatibility
47
47
  namespace transform {
48
48
  export type Options = OptionsType;
49
49
  export type Output = OutputType;
@@ -87,6 +87,12 @@ const index: MarkdownItPluginCb<Opts> = (md, opts) => {
87
87
 
88
88
  while (j < childrenTokens.length) {
89
89
  if (childrenTokens[j].type === 'image') {
90
+ const didPatch = childrenTokens[j].attrGet('yfm_patched') || false;
91
+
92
+ if (didPatch) {
93
+ return;
94
+ }
95
+
90
96
  const imgSrc = childrenTokens[j].attrGet('src') || '';
91
97
 
92
98
  if (imgSrc.endsWith('.svg') && !isExternalHref(imgSrc)) {
@@ -94,6 +100,8 @@ const index: MarkdownItPluginCb<Opts> = (md, opts) => {
94
100
  } else {
95
101
  replaceImageSrc(childrenTokens[j], state, opts);
96
102
  }
103
+
104
+ childrenTokens[j].attrSet('yfm_patched', '1');
97
105
  }
98
106
 
99
107
  j++;
@@ -5,6 +5,7 @@
5
5
  // Process @[osf](guid)
6
6
 
7
7
  import type MarkdownIt from 'markdown-it';
8
+ // eslint-disable-next-line no-duplicate-imports
8
9
  import type {PluginWithOptions} from 'markdown-it';
9
10
  import type ParserInline from 'markdown-it/lib/parser_inline';
10
11
  import type Renderer from 'markdown-it/lib/renderer';
@@ -81,6 +82,7 @@ function tokenizeVideo(md: MarkdownIt, options: VideoFullOptions): Renderer.Rend
81
82
  }
82
83
 
83
84
  const EMBED_REGEX = /@\[([a-zA-Z].+)]\([\s]*(.*?)[\s]*[)]/im;
85
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
84
86
  function videoEmbed(md: MarkdownIt, _options: VideoFullOptions): ParserInline.RuleInline {
85
87
  return (state, silent) => {
86
88
  const theState = state;
@@ -98,7 +98,7 @@ function yfmlint(opts: Options) {
98
98
 
99
99
  export = yfmlint;
100
100
 
101
- // eslint-disable-next-line @typescript-eslint/no-namespace
101
+ // eslint-disable-next-line @typescript-eslint/no-namespace, no-redeclare
102
102
  namespace yfmlint {
103
103
  export interface LintMarkdownFunctionOptions {
104
104
  input: string;
@@ -1,38 +0,0 @@
1
- # Changelog @diplodoc/transform@4.0.0
2
-
3
- ## It's major update of @doc-tools/transform@3.11.0 with security changes.
4
-
5
- ### New term's linter
6
-
7
- The main feature of term is generating a hidden content, that will be show on click. Terms plugins creates MarkadownIt tokens at place, where term was defined and it can brake our `@doc-tools/docs` navigation. Now `@diplodoc/transform` has new yfmlint rule: `no-term-definition-in-content`. There are several restrictions: - You can't define content between term-def - All term-def should be placed at the end of file.
8
-
9
- ### Enabling `needToSanitizeHtml` by default
10
-
11
- The sanitizer includes default options with safe, allowed tags, and attributes. However, by default, both the `style` tag and the `style` attribute are also allowed. The values will be processed by the [cssfilter](https://github.com/leizongmin/js-css-filter) module to prevent XSS attacks. The cssfilter module includes a default CSS whitelist.
12
-
13
- You can override the options for sanitizer like this:
14
-
15
- ```javascript
16
- const transform = require('@doc-tools/transform');
17
- const {defaultOptions} = require('@doc-tools/transform/lib/sanitize');
18
-
19
- const sanitizeOptions = Object.assign({}, defaultOptions);
20
-
21
- // Allow css property
22
- sanitizeOptions.cssWhiteList['position'] = true;
23
-
24
- // Disallow css property
25
- delete sanitizeOptions.cssWhiteList['color'];
26
-
27
- // Disable `style` tag
28
- sanitizeOptions.allowedTags = sanitizeOptions.allowedTags.filter((tag) => tag !== 'style');
29
-
30
- // Disable `style` attribute
31
- sanitizeOptions.allowedAttributes['*'] = sanitizeOptions.allowedAttributes['*'].filter(
32
- (attr) => attr !== 'style',
33
- );
34
-
35
- const {
36
- result: {html},
37
- } = transform(content, {sanitizeOptions});
38
- ```