@diplodoc/transform 4.70.4 → 4.72.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/_yfm-only.css +4 -4
- package/dist/css/_yfm-only.css.map +3 -3
- package/dist/css/_yfm-only.min.css +1 -1
- package/dist/css/_yfm-only.min.css.map +3 -3
- package/dist/css/base.css.map +1 -1
- package/dist/css/base.min.css.map +1 -1
- package/dist/css/print.css.map +1 -1
- package/dist/css/yfm.css +4 -4
- 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/base.js +396 -215
- package/dist/js/base.js.map +4 -4
- package/dist/js/base.min.js +1 -6
- package/dist/js/base.min.js.map +4 -4
- package/dist/js/yfm.js +429 -228
- package/dist/js/yfm.js.map +4 -4
- package/dist/js/yfm.min.js +1 -6
- package/dist/js/yfm.min.js.map +4 -4
- package/dist/scss/{_inline-code.scss → _tooltip.scss} +1 -1
- package/dist/scss/_yfm-only.scss +1 -1
- package/lib/plugins/anchors/index.js +1 -1
- package/lib/plugins/anchors/index.js.map +1 -1
- package/lib/plugins/images/index.js +7 -0
- package/lib/plugins/images/index.js.map +1 -1
- package/lib/plugins/term/termDefinitions.js +54 -27
- package/lib/plugins/term/termDefinitions.js.map +1 -1
- package/lib/typings.d.ts +10 -0
- package/package.json +2 -2
- package/src/js/anchor.ts +27 -3
- package/src/js/{inline-code/constant.ts → constant.ts} +1 -9
- package/src/js/inline-code/index.ts +24 -42
- package/src/js/tooltip/constant.ts +25 -0
- package/src/js/tooltip/index.ts +2 -0
- package/src/js/tooltip/tooltip.ts +263 -0
- package/src/js/tooltip/types.ts +59 -0
- package/src/js/tooltip/utils.ts +247 -0
- package/src/scss/{_inline-code.scss → _tooltip.scss} +1 -1
- package/src/scss/_yfm-only.scss +1 -1
- package/src/transform/plugins/anchors/index.ts +1 -1
- package/src/transform/plugins/images/index.ts +8 -0
- package/src/transform/plugins/term/termDefinitions.ts +71 -33
- package/src/transform/typings.ts +10 -0
- package/src/js/inline-code/utils.ts +0 -217
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
type Prettify<T> = {
|
|
2
|
+
[K in keyof T]: T[K];
|
|
3
|
+
} & {};
|
|
4
|
+
|
|
5
|
+
export interface ElementRect {
|
|
6
|
+
readonly top: number;
|
|
7
|
+
readonly left: number;
|
|
8
|
+
readonly right: number;
|
|
9
|
+
readonly bottom: number;
|
|
10
|
+
readonly width: number;
|
|
11
|
+
readonly height: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface Coords {
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface OffsetValues {
|
|
20
|
+
mainAxis?: number;
|
|
21
|
+
crossAxis?: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type Alignment = 'start' | 'end';
|
|
25
|
+
|
|
26
|
+
export type Side = 'top' | 'right' | 'bottom' | 'left';
|
|
27
|
+
|
|
28
|
+
export type AlignedPlacement = `${Side}-${Alignment}`;
|
|
29
|
+
|
|
30
|
+
export type Placement = Prettify<Side | AlignedPlacement>;
|
|
31
|
+
|
|
32
|
+
export type SideObject = {[key in Side]: number};
|
|
33
|
+
|
|
34
|
+
export interface TooltipContextElements {
|
|
35
|
+
reference: HTMLElement;
|
|
36
|
+
tooltip: HTMLElement;
|
|
37
|
+
offsetParent: HTMLElement;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface TooltipContext {
|
|
41
|
+
isRtl: boolean;
|
|
42
|
+
viewport: ElementRect;
|
|
43
|
+
reference: ElementRect;
|
|
44
|
+
tooltip: ElementRect;
|
|
45
|
+
elements: TooltipContextElements;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface TooltipElementOptions {
|
|
49
|
+
text: string;
|
|
50
|
+
className?: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface TooltipOptions {
|
|
54
|
+
closeDelay?: number;
|
|
55
|
+
additionalClassName?: string;
|
|
56
|
+
placement?: Placement;
|
|
57
|
+
offset?: OffsetValues;
|
|
58
|
+
flip?: boolean;
|
|
59
|
+
}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Alignment,
|
|
3
|
+
Coords,
|
|
4
|
+
ElementRect,
|
|
5
|
+
OffsetValues,
|
|
6
|
+
Placement,
|
|
7
|
+
Side,
|
|
8
|
+
SideObject,
|
|
9
|
+
} from './types';
|
|
10
|
+
|
|
11
|
+
import {DEFAULT_SIDE_OBJECT, OPPOSITE_SIDES} from './constant';
|
|
12
|
+
|
|
13
|
+
function isVerticalSide(side: Side): boolean {
|
|
14
|
+
return side === 'top' || side === 'bottom';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function createSideObject(value: Partial<SideObject> | number = 0): SideObject {
|
|
18
|
+
if (typeof value === 'number') {
|
|
19
|
+
return {top: value, bottom: value, left: value, right: value};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return {...DEFAULT_SIDE_OBJECT, ...value};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function parsePlacement(placement: Placement): {side: Side; alignment?: Alignment} {
|
|
26
|
+
const [side, alignment] = placement.split('-') as [Side, Alignment | undefined];
|
|
27
|
+
|
|
28
|
+
return {side, alignment};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function getOppositeSide(side: Side): Side {
|
|
32
|
+
return OPPOSITE_SIDES[side];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function flipPlacement(placement: Placement): Placement {
|
|
36
|
+
const {side, alignment} = parsePlacement(placement);
|
|
37
|
+
const opposite = getOppositeSide(side);
|
|
38
|
+
|
|
39
|
+
return (alignment ? `${opposite}-${alignment}` : opposite) as Placement;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function getOverflow(tooltip: ElementRect, coords: Coords, viewport: ElementRect): SideObject {
|
|
43
|
+
const rect = updateRect(tooltip, {top: coords.y, left: coords.x});
|
|
44
|
+
|
|
45
|
+
return detectOverflow(viewport, rect, 5);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function shouldFlip(overflow: SideObject, flippedOverflow: SideObject, side: Side): boolean {
|
|
49
|
+
const opposite = getOppositeSide(side);
|
|
50
|
+
|
|
51
|
+
return overflow[side] > 0 && flippedOverflow[opposite] < overflow[side];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function computePosition(
|
|
55
|
+
reference: ElementRect,
|
|
56
|
+
tooltip: ElementRect,
|
|
57
|
+
viewport: ElementRect,
|
|
58
|
+
placement: Placement,
|
|
59
|
+
offset: OffsetValues,
|
|
60
|
+
isRtl: boolean,
|
|
61
|
+
flip = true,
|
|
62
|
+
): {coords: Coords; placement: Placement} {
|
|
63
|
+
const coords = computeCoordsFromPlacement(reference, tooltip, offset, placement, isRtl);
|
|
64
|
+
|
|
65
|
+
if (!flip) {
|
|
66
|
+
return {coords, placement};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const overflow = getOverflow(tooltip, coords, viewport);
|
|
70
|
+
const {side} = parsePlacement(placement);
|
|
71
|
+
|
|
72
|
+
if (overflow[side] <= 0) {
|
|
73
|
+
return {coords, placement};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const flipped = flipPlacement(placement);
|
|
77
|
+
const flippedCoords = computeCoordsFromPlacement(reference, tooltip, offset, flipped, isRtl);
|
|
78
|
+
const flippedOverflow = getOverflow(tooltip, flippedCoords, viewport);
|
|
79
|
+
|
|
80
|
+
if (shouldFlip(overflow, flippedOverflow, side)) {
|
|
81
|
+
return {coords: flippedCoords, placement: flipped};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return {coords, placement};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function generateId() {
|
|
88
|
+
const random = Math.random().toString(36).substring(2, 6);
|
|
89
|
+
const now = Date.now().toString(36);
|
|
90
|
+
|
|
91
|
+
return `${random}${now}`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function createRect(
|
|
95
|
+
params: Pick<ElementRect, 'top' | 'left' | 'width' | 'height'>,
|
|
96
|
+
): ElementRect {
|
|
97
|
+
return {
|
|
98
|
+
...params,
|
|
99
|
+
right: params.left + params.width,
|
|
100
|
+
bottom: params.top + params.height,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function updateRect(rect: ElementRect, params: Partial<ElementRect>): ElementRect {
|
|
105
|
+
return createRect({
|
|
106
|
+
top: params.top ?? rect.top,
|
|
107
|
+
left: params.left ?? rect.left,
|
|
108
|
+
width: params.width ?? rect.width,
|
|
109
|
+
height: params.height ?? rect.height,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function getViewportRect(): ElementRect {
|
|
114
|
+
const {documentElement, body} = document;
|
|
115
|
+
|
|
116
|
+
const scrollTop = window.scrollY || documentElement.scrollTop || body.scrollTop;
|
|
117
|
+
const scrollLeft = window.scrollX || documentElement.scrollLeft || body.scrollLeft;
|
|
118
|
+
|
|
119
|
+
const clientTop = documentElement.clientTop || body.clientTop || 0;
|
|
120
|
+
const clientLeft = documentElement.clientLeft || body.clientLeft || 0;
|
|
121
|
+
|
|
122
|
+
return createRect({
|
|
123
|
+
top: Math.round(scrollTop - clientTop),
|
|
124
|
+
left: Math.round(scrollLeft - clientLeft),
|
|
125
|
+
width: document.body.clientWidth,
|
|
126
|
+
height: document.body.clientHeight,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function getElementRect(element: HTMLElement): ElementRect {
|
|
131
|
+
const viewport = getViewportRect();
|
|
132
|
+
const box = element.getBoundingClientRect();
|
|
133
|
+
|
|
134
|
+
return createRect({
|
|
135
|
+
top: Math.round(box.top + viewport.top),
|
|
136
|
+
left: Math.round(box.left + viewport.left),
|
|
137
|
+
width: box.width,
|
|
138
|
+
height: box.height,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function computeAxisOffset(offset: OffsetValues, side: Side, isRtl?: boolean): Coords {
|
|
143
|
+
const {mainAxis = 0, crossAxis = 0} = offset;
|
|
144
|
+
|
|
145
|
+
const isVertical = isVerticalSide(side);
|
|
146
|
+
const mainDirection = side === 'top' || side === 'left' ? -1 : 1;
|
|
147
|
+
const crossDirection = isRtl && isVertical ? -1 : 1;
|
|
148
|
+
|
|
149
|
+
const mainOffset = mainAxis * mainDirection;
|
|
150
|
+
const crossOffset = crossAxis * crossDirection;
|
|
151
|
+
|
|
152
|
+
if (isVertical) {
|
|
153
|
+
return {x: crossOffset, y: mainOffset};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return {x: mainOffset, y: crossOffset};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function computeCoordsFromPlacement(
|
|
160
|
+
reference: ElementRect,
|
|
161
|
+
tooltip: ElementRect,
|
|
162
|
+
offset: OffsetValues,
|
|
163
|
+
placement: Placement,
|
|
164
|
+
isRtl: boolean,
|
|
165
|
+
) {
|
|
166
|
+
const {side, alignment} = parsePlacement(placement);
|
|
167
|
+
const isVertical = isVerticalSide(side);
|
|
168
|
+
const alignmentAxis = isVertical ? 'x' : 'y';
|
|
169
|
+
const alignLength = alignmentAxis === 'y' ? 'height' : 'width';
|
|
170
|
+
|
|
171
|
+
const centerX = reference.left + reference.width / 2 - tooltip.width / 2;
|
|
172
|
+
const centerY = reference.top + reference.height / 2 - tooltip.height / 2;
|
|
173
|
+
const alignmentOffset = reference[alignLength] / 2 - tooltip[alignLength] / 2;
|
|
174
|
+
|
|
175
|
+
const coords: Coords = {x: reference.left, y: reference.top};
|
|
176
|
+
|
|
177
|
+
switch (side) {
|
|
178
|
+
case 'top': {
|
|
179
|
+
coords.x = centerX;
|
|
180
|
+
coords.y = reference.top - tooltip.height;
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
case 'bottom': {
|
|
185
|
+
coords.x = centerX;
|
|
186
|
+
coords.y = reference.top + reference.height;
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
case 'right': {
|
|
191
|
+
coords.x = reference.left + reference.width;
|
|
192
|
+
coords.y = centerY;
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
case 'left': {
|
|
197
|
+
coords.x = reference.left - tooltip.width;
|
|
198
|
+
coords.y = centerY;
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
switch (alignment) {
|
|
204
|
+
case 'start': {
|
|
205
|
+
coords[alignmentAxis] -= alignmentOffset * (isRtl && isVertical ? -1 : 1);
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
case 'end': {
|
|
210
|
+
coords[alignmentAxis] += alignmentOffset * (isRtl && isVertical ? -1 : 1);
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const axisOffset = computeAxisOffset(offset, side, isRtl);
|
|
216
|
+
|
|
217
|
+
coords.x += axisOffset.x;
|
|
218
|
+
coords.y += axisOffset.y;
|
|
219
|
+
|
|
220
|
+
return coords;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export function convertToRelativeToOffsetParentRect(rect: ElementRect, offsetParent: HTMLElement) {
|
|
224
|
+
const offsetRect = getElementRect(offsetParent);
|
|
225
|
+
|
|
226
|
+
return createRect({
|
|
227
|
+
top: rect.top - offsetRect.top + offsetParent.offsetTop,
|
|
228
|
+
left: rect.left - offsetRect.left + offsetParent.offsetLeft,
|
|
229
|
+
width: rect.width,
|
|
230
|
+
height: rect.height,
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export function detectOverflow(
|
|
235
|
+
boundary: ElementRect,
|
|
236
|
+
element: ElementRect,
|
|
237
|
+
padding: Partial<SideObject> | number = 0,
|
|
238
|
+
): SideObject {
|
|
239
|
+
const {top, bottom, left, right} = createSideObject(padding);
|
|
240
|
+
|
|
241
|
+
return {
|
|
242
|
+
top: boundary.top - element.top + top,
|
|
243
|
+
bottom: element.bottom - boundary.bottom + bottom,
|
|
244
|
+
left: boundary.left - element.left + left,
|
|
245
|
+
right: element.right - boundary.right + right,
|
|
246
|
+
};
|
|
247
|
+
}
|
package/src/scss/_yfm-only.scss
CHANGED
|
@@ -46,7 +46,7 @@ function createAnchorLinkTokens(
|
|
|
46
46
|
open.attrSet('id', id);
|
|
47
47
|
}
|
|
48
48
|
open.attrSet('href', href + '#' + id);
|
|
49
|
-
open.attrSet('class', 'yfm-anchor');
|
|
49
|
+
open.attrSet('class', 'yfm-anchor yfm-clipboard-anchor');
|
|
50
50
|
open.attrSet('aria-hidden', 'true');
|
|
51
51
|
|
|
52
52
|
// SEO: render invisible heading title because link must have text content.
|
|
@@ -147,6 +147,7 @@ const index: MarkdownItPluginCb<Opts> = (md, opts) => {
|
|
|
147
147
|
const imageOpts = {
|
|
148
148
|
width: image.attrGet('width'),
|
|
149
149
|
height: image.attrGet('height'),
|
|
150
|
+
title: image.attrGet('title'),
|
|
150
151
|
};
|
|
151
152
|
|
|
152
153
|
const from = state.env.path || opts.path;
|
|
@@ -225,6 +226,13 @@ function replaceSvgContent(content: string | null, options: ImageOptions) {
|
|
|
225
226
|
content = content.replace(/.*?<svg([^>]*)>/, `<svg${svgRoot}>`);
|
|
226
227
|
}
|
|
227
228
|
|
|
229
|
+
// title
|
|
230
|
+
const hasTitle = /<title>.*?<\/title>/i.test(content);
|
|
231
|
+
if (!hasTitle && options.title) {
|
|
232
|
+
// Insert title tag after the opening svg tag
|
|
233
|
+
content = content.replace(/(<svg[^>]*>)/, `$1<title>${options.title}</title>`);
|
|
234
|
+
}
|
|
235
|
+
|
|
228
236
|
// randomize ids
|
|
229
237
|
content = optimize(content, {
|
|
230
238
|
plugins: [
|
|
@@ -6,24 +6,38 @@ import {BASIC_TERM_REGEXP} from './constants';
|
|
|
6
6
|
|
|
7
7
|
const INCLUDE_LINE_RE = /^{%\s*include\s/;
|
|
8
8
|
const NEW_LINE_RE = /^(\r\n|\r|\n)/;
|
|
9
|
-
const TERM_DEF_RE = /^\[\*(\
|
|
9
|
+
const TERM_DEF_RE = /^\[\*([^[\]]+)\]:/;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param state - markdown-it block state
|
|
13
|
+
* @param line - line number to read
|
|
14
|
+
* @returns raw source text of the given line
|
|
15
|
+
*/
|
|
16
|
+
function getNextLineContent(state: StateBlock, line: number): string {
|
|
17
|
+
const start = state.bMarks[line];
|
|
18
|
+
const end = state.eMarks[line];
|
|
19
|
+
|
|
20
|
+
return start === end ? state.src[start] : state.src.slice(start, end);
|
|
21
|
+
}
|
|
10
22
|
|
|
11
23
|
/**
|
|
12
24
|
* Checks whether the first non-blank line after {@link fromLine} is an
|
|
13
25
|
* `{% include %}` directive. Used to allow blank-line gaps between
|
|
14
26
|
* consecutive includes inside a single term definition.
|
|
15
27
|
*
|
|
16
|
-
* @param
|
|
17
|
-
* @param
|
|
18
|
-
* @param
|
|
19
|
-
* @returns
|
|
28
|
+
* @param state - markdown-it block state
|
|
29
|
+
* @param fromLine - line number from which to start searching
|
|
30
|
+
* @param endLine - last line number to search within
|
|
31
|
+
* @returns true if the first non-blank line is an include directive
|
|
20
32
|
*/
|
|
21
33
|
function hasIncludeAfterBlanks(state: StateBlock, fromLine: number, endLine: number): boolean {
|
|
22
34
|
for (let line = fromLine + 1; line <= endLine; line++) {
|
|
23
35
|
const start = state.bMarks[line];
|
|
24
36
|
const end = state.eMarks[line];
|
|
25
37
|
|
|
26
|
-
if (start === end)
|
|
38
|
+
if (start === end) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
27
41
|
|
|
28
42
|
const content = state.src.slice(start, end);
|
|
29
43
|
return INCLUDE_LINE_RE.test(content.trimStart());
|
|
@@ -31,7 +45,51 @@ function hasIncludeAfterBlanks(state: StateBlock, fromLine: number, endLine: num
|
|
|
31
45
|
return false;
|
|
32
46
|
}
|
|
33
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Scans forward from {@link startLine} to find where the current term
|
|
50
|
+
* definition ends.
|
|
51
|
+
*
|
|
52
|
+
* When `multilineTermDefinitions` is enabled, the definition continues
|
|
53
|
+
* past blank lines and stops only at the next `[*key]:` or end of block.
|
|
54
|
+
* Otherwise blank lines terminate the definition unless followed by an
|
|
55
|
+
* `{% include %}` directive (legacy behaviour).
|
|
56
|
+
*
|
|
57
|
+
* @param state - markdown-it block state
|
|
58
|
+
* @param startLine - line where the current definition starts
|
|
59
|
+
* @param endLine - last line of the block
|
|
60
|
+
* @param multiline - whether multiline mode is enabled
|
|
61
|
+
* @returns line number where the definition ends
|
|
62
|
+
*/
|
|
63
|
+
function findDefinitionEnd(
|
|
64
|
+
state: StateBlock,
|
|
65
|
+
startLine: number,
|
|
66
|
+
endLine: number,
|
|
67
|
+
multiline: boolean,
|
|
68
|
+
): number {
|
|
69
|
+
let currentLine = startLine;
|
|
70
|
+
|
|
71
|
+
for (; currentLine < endLine; currentLine++) {
|
|
72
|
+
const nextLine = getNextLineContent(state, currentLine + 1);
|
|
73
|
+
|
|
74
|
+
if (TERM_DEF_RE.test(nextLine)) {
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (!multiline && NEW_LINE_RE.test(nextLine)) {
|
|
79
|
+
if (!hasIncludeAfterBlanks(state, currentLine + 1, endLine)) {
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
state.line = currentLine + 1;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return currentLine;
|
|
88
|
+
}
|
|
89
|
+
|
|
34
90
|
export function termDefinitions(md: MarkdownIt, options: MarkdownItPluginOpts) {
|
|
91
|
+
const multiline = options.multilineTermDefinitions === true;
|
|
92
|
+
|
|
35
93
|
return (state: StateBlock, startLine: number, endLine: number, silent: boolean) => {
|
|
36
94
|
let ch;
|
|
37
95
|
let labelEnd;
|
|
@@ -63,33 +121,7 @@ export function termDefinitions(md: MarkdownIt, options: MarkdownItPluginOpts) {
|
|
|
63
121
|
}
|
|
64
122
|
}
|
|
65
123
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
// Allow multiline term definition.
|
|
69
|
-
// Blank lines normally terminate the definition, but we look ahead
|
|
70
|
-
// past them: if the next non-blank line is an {% include %} directive,
|
|
71
|
-
// we keep scanning so that multiple includes can be part of one term.
|
|
72
|
-
for (; currentLine < endLine; currentLine++) {
|
|
73
|
-
const nextLineStart = state.bMarks[currentLine + 1];
|
|
74
|
-
const nextLineEnd = state.eMarks[currentLine + 1];
|
|
75
|
-
|
|
76
|
-
const nextLine =
|
|
77
|
-
nextLineStart === nextLineEnd
|
|
78
|
-
? state.src[nextLineStart]
|
|
79
|
-
: state.src.slice(nextLineStart, nextLineEnd);
|
|
80
|
-
|
|
81
|
-
if (TERM_DEF_RE.test(nextLine)) {
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (NEW_LINE_RE.test(nextLine)) {
|
|
86
|
-
if (!hasIncludeAfterBlanks(state, currentLine + 1, endLine)) {
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
state.line = currentLine + 1;
|
|
92
|
-
}
|
|
124
|
+
const currentLine = findDefinitionEnd(state, startLine, endLine, multiline);
|
|
93
125
|
|
|
94
126
|
max = state.eMarks[currentLine];
|
|
95
127
|
|
|
@@ -165,6 +197,8 @@ function processTermDefinition(
|
|
|
165
197
|
state.env.terms[':' + label] = title;
|
|
166
198
|
}
|
|
167
199
|
|
|
200
|
+
const fromInclude = Array.isArray(state.env.includes) && state.env.includes.length > 0;
|
|
201
|
+
|
|
168
202
|
token = new state.Token('dfn_open', 'dfn', 1);
|
|
169
203
|
token.attrSet('class', 'yfm yfm-term_dfn');
|
|
170
204
|
token.attrSet('id', ':' + label + '_element');
|
|
@@ -172,6 +206,10 @@ function processTermDefinition(
|
|
|
172
206
|
token.attrSet('aria-live', 'polite');
|
|
173
207
|
token.attrSet('aria-modal', 'true');
|
|
174
208
|
|
|
209
|
+
if (fromInclude) {
|
|
210
|
+
token.attrSet('from-include', 'true');
|
|
211
|
+
}
|
|
212
|
+
|
|
175
213
|
state.tokens.push(token);
|
|
176
214
|
|
|
177
215
|
const titleTokens = md.parse(title, state.env);
|
package/src/transform/typings.ts
CHANGED
|
@@ -144,6 +144,15 @@ export interface MarkdownItPluginOpts {
|
|
|
144
144
|
enabled: boolean;
|
|
145
145
|
maxFileSize: number;
|
|
146
146
|
};
|
|
147
|
+
/**
|
|
148
|
+
* When true, term definitions continue past blank lines until the next
|
|
149
|
+
* `[*key]:` or end of block. Designed for documents where all term
|
|
150
|
+
* definitions are placed at the end of the file.
|
|
151
|
+
*
|
|
152
|
+
* When false (default), a blank line terminates the definition unless
|
|
153
|
+
* the next non-blank line is an `{% include %}` directive.
|
|
154
|
+
*/
|
|
155
|
+
multilineTermDefinitions?: boolean;
|
|
147
156
|
}
|
|
148
157
|
|
|
149
158
|
export type MarkdownItPluginCb<T extends {} = {}> = {
|
|
@@ -174,4 +183,5 @@ export type CssWhiteList = {[property: string]: boolean};
|
|
|
174
183
|
export type ImageOptions = {
|
|
175
184
|
width: string | undefined | null;
|
|
176
185
|
height: string | undefined | null;
|
|
186
|
+
title: string | undefined | null;
|
|
177
187
|
};
|