@diplodoc/transform 4.8.1 → 4.9.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.map +1 -1
- package/dist/css/yfm.css +14 -0
- 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/lib/plugins/changelog/collect.js +18 -14
- package/lib/plugins/changelog/collect.js.map +1 -1
- package/lib/plugins/changelog/index.js +5 -2
- package/lib/plugins/changelog/index.js.map +1 -1
- package/lib/plugins/notes.js +5 -2
- package/lib/plugins/notes.js.map +1 -1
- package/package.json +1 -1
- package/src/scss/_common.scss +2 -0
- package/src/scss/_cut.scss +12 -0
- package/src/transform/plugins/changelog/collect.ts +19 -14
- package/src/transform/plugins/changelog/index.ts +8 -4
- package/src/transform/plugins/notes.ts +7 -2
|
@@ -6,7 +6,7 @@ import imsize from '../imsize';
|
|
|
6
6
|
import {MarkdownItPluginOpts} from '../typings';
|
|
7
7
|
|
|
8
8
|
const BLOCK_START = '{% changelog %}';
|
|
9
|
-
const BLOCK_END = '{% endchangelog %}
|
|
9
|
+
const BLOCK_END = '{% endchangelog %}';
|
|
10
10
|
|
|
11
11
|
function parseChangelogs(str: string, path?: string) {
|
|
12
12
|
const {parse, compile, env} = initMarkdownit({
|
|
@@ -28,33 +28,38 @@ type Options = Pick<MarkdownItPluginOpts, 'path' | 'log'> & {
|
|
|
28
28
|
const collect = (input: string, {path: filepath, log, changelogs, extractChangelogs}: Options) => {
|
|
29
29
|
let result = input;
|
|
30
30
|
let lastPos = 0;
|
|
31
|
-
const
|
|
31
|
+
const rawChangelogs = [];
|
|
32
32
|
|
|
33
33
|
// eslint-disable-next-line no-constant-condition
|
|
34
34
|
while (true) {
|
|
35
|
-
const
|
|
36
|
-
lastPos =
|
|
37
|
-
if (
|
|
35
|
+
const startPos = result.indexOf(BLOCK_START, lastPos);
|
|
36
|
+
lastPos = startPos;
|
|
37
|
+
if (startPos === -1) {
|
|
38
38
|
break;
|
|
39
39
|
}
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
|
|
41
|
+
const endBlockPos = result.indexOf(BLOCK_END, startPos + BLOCK_START.length);
|
|
42
|
+
if (endBlockPos === -1) {
|
|
42
43
|
log.error(`Changelog block must be closed${filepath ? ` in ${bold(filepath)}` : ''}`);
|
|
43
44
|
break;
|
|
44
45
|
}
|
|
46
|
+
let endPos = endBlockPos + BLOCK_END.length;
|
|
47
|
+
if (result[endPos + 1] === '\n') {
|
|
48
|
+
endPos += 1;
|
|
49
|
+
}
|
|
45
50
|
|
|
46
|
-
const
|
|
51
|
+
const changelog = result.slice(startPos, endPos);
|
|
47
52
|
|
|
48
|
-
|
|
53
|
+
rawChangelogs.push(changelog);
|
|
49
54
|
|
|
50
|
-
result = result.slice(0,
|
|
55
|
+
result = result.slice(0, startPos) + result.slice(endPos);
|
|
51
56
|
}
|
|
52
57
|
|
|
53
|
-
if (
|
|
54
|
-
const parsedChangelogs = parseChangelogs(
|
|
55
|
-
if (parsedChangelogs.length !==
|
|
58
|
+
if (rawChangelogs.length && changelogs && extractChangelogs) {
|
|
59
|
+
const parsedChangelogs = parseChangelogs(rawChangelogs.join('\n\n'), filepath);
|
|
60
|
+
if (parsedChangelogs.length !== rawChangelogs.length) {
|
|
56
61
|
log.error(
|
|
57
|
-
`Parsed
|
|
62
|
+
`Parsed changelogs less than expected${filepath ? ` in ${bold(filepath)}` : ''}`,
|
|
58
63
|
);
|
|
59
64
|
}
|
|
60
65
|
changelogs.push(...parsedChangelogs);
|
|
@@ -55,10 +55,10 @@ function parseBody(tokens: Token[], state: StateCore) {
|
|
|
55
55
|
throw new Error('Metadata tag not found');
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
let metadata:
|
|
58
|
+
let metadata: Record<string, unknown> = {};
|
|
59
59
|
const rawMetadata = yaml.load(metadataToken.content, {
|
|
60
60
|
schema: yaml.JSON_SCHEMA,
|
|
61
|
-
})
|
|
61
|
+
}) as Record<string, unknown>;
|
|
62
62
|
if (rawMetadata && typeof rawMetadata === 'object') {
|
|
63
63
|
metadata = rawMetadata;
|
|
64
64
|
}
|
|
@@ -93,6 +93,10 @@ function parseBody(tokens: Token[], state: StateCore) {
|
|
|
93
93
|
|
|
94
94
|
const description = md.renderer.render(tokens, md.options, env);
|
|
95
95
|
|
|
96
|
+
if (typeof metadata.storyId === 'number') {
|
|
97
|
+
metadata.storyId = String(metadata.storyId);
|
|
98
|
+
}
|
|
99
|
+
|
|
96
100
|
return {
|
|
97
101
|
...metadata,
|
|
98
102
|
title,
|
|
@@ -135,13 +139,13 @@ const changelog: MarkdownItPluginCb<Options> = function (md, {extractChangelogs,
|
|
|
135
139
|
content.splice(-3);
|
|
136
140
|
|
|
137
141
|
try {
|
|
138
|
-
const
|
|
142
|
+
const changelogLocal = parseBody(content, state);
|
|
139
143
|
|
|
140
144
|
if (!env.changelogs) {
|
|
141
145
|
env.changelogs = [];
|
|
142
146
|
}
|
|
143
147
|
|
|
144
|
-
env.changelogs.push(
|
|
148
|
+
env.changelogs.push(changelogLocal);
|
|
145
149
|
} catch (err) {
|
|
146
150
|
log.error(`Changelog error: ${(err as Error).message} in ${bold(path)}`);
|
|
147
151
|
continue;
|
|
@@ -58,7 +58,10 @@ function matchWrongNotes(tokens: Token[], i: number) {
|
|
|
58
58
|
|
|
59
59
|
const findCloseTokenIdx = closeTokenFactory('Note', matchOpenToken, matchCloseToken);
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
const notes: MarkdownItPluginCb = (md, {lang, notesAutotitle, path: optPath, log}) => {
|
|
63
|
+
notesAutotitle = typeof notesAutotitle === 'boolean' ? notesAutotitle : true;
|
|
64
|
+
|
|
62
65
|
const plugin = (state: StateCore) => {
|
|
63
66
|
const {tokens, env} = state;
|
|
64
67
|
const path = env.path || optPath;
|
|
@@ -99,7 +102,9 @@ const notes: MarkdownItPluginCb = (md, {lang, path: optPath, log}) => {
|
|
|
99
102
|
titleOpen.block = true;
|
|
100
103
|
titleClose.block = true;
|
|
101
104
|
|
|
102
|
-
|
|
105
|
+
const autotitle = notesAutotitle ? getTitle(type, lang) : '';
|
|
106
|
+
|
|
107
|
+
titleInline.content = match[2] === undefined ? autotitle : match[2];
|
|
103
108
|
titleInline.children = [];
|
|
104
109
|
|
|
105
110
|
const contentOpen = new state.Token('yfm_note_content_open', 'div', 1);
|