@diplodoc/tabs-extension 3.10.8-transform5.3 → 3.10.8-transform5.4
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/README.md +19 -0
- package/build/plugin/find.d.ts +2 -1
- package/build/plugin/index-node.js +59 -6
- package/build/plugin/index-node.js.map +2 -2
- package/build/plugin/index.d.ts +2 -1
- package/build/plugin/index.js +59 -6
- package/build/plugin/index.js.map +2 -2
- package/build/plugin/transform.d.ts +16 -0
- package/build/plugin/utils/tabs.d.ts +18 -0
- package/build/runtime/index.js +1 -1
- package/package.json +1 -1
package/build/plugin/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** Tabs extension: MarkdownIt plugin that transforms `{% list tabs %}` into tab HTML. */
|
|
2
2
|
export { transform } from './transform';
|
|
3
|
-
export type { PluginOptions, TabsPlugin, TabsDirectivePlugin, TransformOptions } from './transform';
|
|
3
|
+
export type { PluginOptions, TabsPlugin, TabsDirectivePlugin, TransformOptions, TabsItemSource, } from './transform';
|
|
4
|
+
export type { TabNameMarkers, TabSourceSpan } from './utils/tabs';
|
|
4
5
|
export type { MarkdownIt, StateCore, Token } from './markdown-it';
|
|
5
6
|
export type { TabsDirectiveDiagnostic } from './directive';
|
|
6
7
|
export { recognizeTabsBoundary } from './find';
|
package/build/plugin/index.js
CHANGED
|
@@ -1578,8 +1578,14 @@ function createTabKey(value) {
|
|
|
1578
1578
|
// src/plugin/utils/tabs.ts
|
|
1579
1579
|
var CUSTOM_ID_REGEXP = /\[?{ ?#(\S+) ?}]?/;
|
|
1580
1580
|
var sluggersStorage = /* @__PURE__ */ new Map();
|
|
1581
|
+
function findCustomAnchor(name) {
|
|
1582
|
+
return name.match(CUSTOM_ID_REGEXP);
|
|
1583
|
+
}
|
|
1584
|
+
function findSelected(name) {
|
|
1585
|
+
return name.indexOf(ACTIVE_TAB_TEXT);
|
|
1586
|
+
}
|
|
1581
1587
|
function parseName(name) {
|
|
1582
|
-
const parts = name
|
|
1588
|
+
const parts = findCustomAnchor(name);
|
|
1583
1589
|
let customAnchor = null;
|
|
1584
1590
|
let pure = name;
|
|
1585
1591
|
if (parts) {
|
|
@@ -1589,7 +1595,7 @@ function parseName(name) {
|
|
|
1589
1595
|
pure = name;
|
|
1590
1596
|
customAnchor = null;
|
|
1591
1597
|
}
|
|
1592
|
-
if (pure
|
|
1598
|
+
if (findSelected(pure) !== -1) {
|
|
1593
1599
|
pure = pure.replace(ACTIVE_TAB_TEXT, "");
|
|
1594
1600
|
}
|
|
1595
1601
|
return {
|
|
@@ -1607,7 +1613,30 @@ function getTabId(tab, { runId }) {
|
|
|
1607
1613
|
}
|
|
1608
1614
|
function isTabSelected(tab) {
|
|
1609
1615
|
const { name } = tab;
|
|
1610
|
-
return name
|
|
1616
|
+
return findSelected(name) !== -1;
|
|
1617
|
+
}
|
|
1618
|
+
function span(start, end) {
|
|
1619
|
+
return Object.freeze([start, end]);
|
|
1620
|
+
}
|
|
1621
|
+
function observeTabName(name) {
|
|
1622
|
+
var _a;
|
|
1623
|
+
const anchor = findCustomAnchor(name);
|
|
1624
|
+
const anchorStart = (_a = anchor == null ? void 0 : anchor.index) != null ? _a : -1;
|
|
1625
|
+
const anchorEnd = anchor ? anchorStart + anchor[0].length : -1;
|
|
1626
|
+
const withoutAnchor = anchor ? name.slice(0, anchorStart) + name.slice(anchorEnd) : name;
|
|
1627
|
+
const active = findSelected(name);
|
|
1628
|
+
const display = findSelected(withoutAnchor);
|
|
1629
|
+
const length = ACTIVE_TAB_TEXT.length;
|
|
1630
|
+
if (anchor && display !== -1 && display < anchorStart && display + length > anchorStart) {
|
|
1631
|
+
return Object.freeze({ kind: "unsupported", reason: "discontinuous-display-marker" });
|
|
1632
|
+
}
|
|
1633
|
+
const displayStart = anchor && display >= anchorStart ? display + anchor[0].length : display;
|
|
1634
|
+
const markers = Object.freeze({
|
|
1635
|
+
customAnchor: anchor ? span(anchorStart, anchorEnd) : null,
|
|
1636
|
+
selectedForActivation: active === -1 ? null : span(active, active + length),
|
|
1637
|
+
selectedForDisplay: display === -1 ? null : span(displayStart, displayStart + length)
|
|
1638
|
+
});
|
|
1639
|
+
return Object.freeze({ kind: "ok", markers });
|
|
1611
1640
|
}
|
|
1612
1641
|
function getTabKey(tab) {
|
|
1613
1642
|
return createTabKey(getRawId(tab));
|
|
@@ -2184,7 +2213,7 @@ function tryToFindTabs(tokens, index) {
|
|
|
2184
2213
|
extraTokensAfterClose
|
|
2185
2214
|
};
|
|
2186
2215
|
}
|
|
2187
|
-
function findTabs(tokens, idx, closeTokenIdx, TokenConstructor, end) {
|
|
2216
|
+
function findTabs(tokens, idx, closeTokenIdx, TokenConstructor, end, titleTokens) {
|
|
2188
2217
|
const tabs = [];
|
|
2189
2218
|
let i = idx;
|
|
2190
2219
|
let nestedLevel = -1;
|
|
@@ -2233,6 +2262,7 @@ function findTabs(tokens, idx, closeTokenIdx, TokenConstructor, end) {
|
|
|
2233
2262
|
}
|
|
2234
2263
|
if (!pending.name && tokens[i + 1].type === "inline") {
|
|
2235
2264
|
pending.name = tokens[i + 1].content;
|
|
2265
|
+
titleTokens == null ? void 0 : titleTokens.set(pending, tokens[i + 1]);
|
|
2236
2266
|
i += 2;
|
|
2237
2267
|
} else {
|
|
2238
2268
|
pending.tokens.push(token);
|
|
@@ -2311,6 +2341,9 @@ function validateTabsMarkers(tokens, markers) {
|
|
|
2311
2341
|
}
|
|
2312
2342
|
|
|
2313
2343
|
// src/plugin/transform.ts
|
|
2344
|
+
function copyMap(map) {
|
|
2345
|
+
return map ? Object.freeze([map[0], map[1]]) : null;
|
|
2346
|
+
}
|
|
2314
2347
|
var defaultFeatures = {
|
|
2315
2348
|
enabledVariants: {
|
|
2316
2349
|
regular: true,
|
|
@@ -2370,7 +2403,8 @@ function transform(options = {}) {
|
|
|
2370
2403
|
features = defaultFeatures,
|
|
2371
2404
|
onBundle,
|
|
2372
2405
|
directiveSyntax = "disabled",
|
|
2373
|
-
onDiagnostic
|
|
2406
|
+
onDiagnostic,
|
|
2407
|
+
onItemSource
|
|
2374
2408
|
} = options;
|
|
2375
2409
|
function installCore(md, options2, markers, legacy) {
|
|
2376
2410
|
const { output = ".", generateID: externalGenerateID } = options2 || {};
|
|
@@ -2389,14 +2423,33 @@ function transform(options = {}) {
|
|
|
2389
2423
|
continue;
|
|
2390
2424
|
}
|
|
2391
2425
|
const variant = features.enabledVariants[match.variant] ? match.variant : "regular" /* Regular */;
|
|
2426
|
+
const titleTokens = onItemSource ? /* @__PURE__ */ new WeakMap() : void 0;
|
|
2392
2427
|
const tabs = findTabs(
|
|
2393
2428
|
state.tokens,
|
|
2394
2429
|
match.bodyStart,
|
|
2395
2430
|
match.close,
|
|
2396
2431
|
state.Token,
|
|
2397
|
-
match.end
|
|
2432
|
+
match.end,
|
|
2433
|
+
titleTokens
|
|
2398
2434
|
);
|
|
2399
2435
|
if (tabs.length > 0) {
|
|
2436
|
+
if (onItemSource && titleTokens) {
|
|
2437
|
+
const openMap = tokens[i].map;
|
|
2438
|
+
const closeMap = tokens[match.close].map;
|
|
2439
|
+
const containerMap = openMap && closeMap && openMap[0] <= closeMap[1] ? copyMap([openMap[0], closeMap[1]]) : null;
|
|
2440
|
+
for (const tab of tabs) {
|
|
2441
|
+
const title = titleTokens.get(tab);
|
|
2442
|
+
const source = title ? observeTabName(tab.name) : { kind: "unsupported", reason: "missing-title" };
|
|
2443
|
+
onItemSource(
|
|
2444
|
+
Object.freeze({
|
|
2445
|
+
rawName: tab.name,
|
|
2446
|
+
inlineMap: title ? copyMap(title.map) : null,
|
|
2447
|
+
containerMap,
|
|
2448
|
+
...source
|
|
2449
|
+
})
|
|
2450
|
+
);
|
|
2451
|
+
}
|
|
2452
|
+
}
|
|
2400
2453
|
const tabsTokens = generateTabsTokens(tabs, state, {
|
|
2401
2454
|
containerClasses,
|
|
2402
2455
|
tabsGroup: match.group,
|