@diplodoc/transform 4.1.0 → 4.2.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.
- package/dist/css/print.css +70 -0
- package/dist/css/print.css.map +7 -0
- package/dist/css/yfm.css +0 -18
- package/dist/css/yfm.css.map +3 -3
- package/dist/css/yfm.min.css +1 -1
- package/dist/css/yfm.min.css.map +3 -3
- package/dist/js/print.js +51 -0
- package/dist/js/print.js.map +7 -0
- package/lib/plugins/images/index.js +5 -0
- package/lib/plugins/images/index.js.map +1 -1
- package/lib/plugins/video/index.js +1 -0
- package/lib/plugins/video/index.js.map +1 -1
- package/package.json +8 -8
- package/src/js/print/index.ts +1 -0
- package/src/js/print/table.ts +62 -0
- package/src/scss/print/code.scss +9 -0
- package/src/scss/print/common.scss +13 -0
- package/src/scss/print/cut.scss +18 -0
- package/src/scss/print/note.scss +7 -0
- package/src/scss/print/table.scss +24 -0
- package/src/scss/print/tabs.scss +20 -0
- package/src/scss/print.scss +6 -0
- package/src/scss/yfm.scss +0 -1
- package/src/transform/index.ts +1 -1
- package/src/transform/plugins/images/index.ts +8 -0
- package/src/transform/plugins/video/index.ts +2 -0
- package/src/transform/yfmlint/index.ts +1 -1
- package/CHANGELOG.diplodoc.md +0 -38
- package/CHANGELOG.md +0 -412
- package/src/scss/_print.scss +0 -20
|
@@ -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 {};
|
|
@@ -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
|
+
}
|
package/src/scss/yfm.scss
CHANGED
package/src/transform/index.ts
CHANGED
|
@@ -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;
|
package/CHANGELOG.diplodoc.md
DELETED
|
@@ -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
|
-
```
|