@diplodoc/tabs-extension 3.10.7 → 3.10.8-transform5.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.
- package/README.md +10 -0
- package/build/plugin/find.d.ts +3 -2
- package/build/plugin/generate.d.ts +1 -2
- package/build/plugin/index-node.d.ts +2 -5
- package/build/plugin/index-node.js +30 -21
- package/build/plugin/index-node.js.map +3 -3
- package/build/plugin/index.d.ts +2 -0
- package/build/plugin/index.js +30 -21
- package/build/plugin/index.js.map +3 -3
- package/build/plugin/markdown-it.d.ts +28 -0
- package/build/plugin/transform.d.ts +9 -4
- package/build/plugin/types.d.ts +1 -1
- package/build/plugin/utils/tabs.d.ts +1 -1
- package/build/plugin/variants/types.d.ts +1 -2
- package/build/runtime/index.js +1 -1
- package/package.json +8 -4
package/README.md
CHANGED
|
@@ -261,3 +261,13 @@ export const App: React.FC = () => {
|
|
|
261
261
|
## For contributors
|
|
262
262
|
|
|
263
263
|
Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.
|
|
264
|
+
|
|
265
|
+
## MarkdownIt compatibility
|
|
266
|
+
|
|
267
|
+
The plugin supports MarkdownIt 13, 14 and 15. Its plugin callback describes the
|
|
268
|
+
core rule and token capabilities it uses, so different supported parser versions
|
|
269
|
+
can coexist in a TypeScript application. Tokens are created by the active parser
|
|
270
|
+
state; no private MarkdownIt module is loaded at runtime.
|
|
271
|
+
|
|
272
|
+
The installed-package compatibility tests use TypeScript 6.0.3 with NodeNext
|
|
273
|
+
module resolution and `skipLibCheck: false`, including CommonJS and ESM hosts.
|
package/build/plugin/find.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import type { StateCore, Token } from './markdown-it';
|
|
1
2
|
/**
|
|
2
3
|
* Parsing of `{% list tabs %}` blocks: locate open/close tags, parse props, and extract tab items
|
|
3
4
|
* from the list tokens between them.
|
|
4
5
|
*/
|
|
5
6
|
import type { RuntimeTab, TabsProps } from './types';
|
|
6
7
|
import type { IDGenerator } from '@diplodoc/utils';
|
|
7
|
-
import Token from 'markdown-it/lib/token';
|
|
8
8
|
/**
|
|
9
9
|
* Parse `{% list tabs group=... %}` content into variant and group id.
|
|
10
10
|
* @param content - Raw tag content after "list tabs"
|
|
@@ -31,7 +31,8 @@ export declare function tryToFindTabs(tokens: Token[], index: number): Result;
|
|
|
31
31
|
* @param tokens - Full token list
|
|
32
32
|
* @param idx - Index after list open
|
|
33
33
|
* @param closeTokenIdx - Index of {% endlist %} paragraph
|
|
34
|
+
* @param TokenConstructor - Token constructor from the current MarkdownIt state
|
|
34
35
|
* @returns Array of RuntimeTab
|
|
35
36
|
*/
|
|
36
|
-
export declare function findTabs(tokens: Token[], idx: number, closeTokenIdx: number): RuntimeTab[];
|
|
37
|
+
export declare function findTabs(tokens: Token[], idx: number, closeTokenIdx: number, TokenConstructor: StateCore['Token']): RuntimeTab[];
|
|
37
38
|
export {};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type Token from 'markdown-it
|
|
2
|
-
import type StateCore from 'markdown-it/lib/rules_core/state_core';
|
|
1
|
+
import type { StateCore, Token } from './markdown-it';
|
|
3
2
|
import type { RuntimeTab } from './types';
|
|
4
3
|
import type { TabsGenerationProps } from './variants/types';
|
|
5
4
|
/**
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { type PluginOptions } from './transform';
|
|
1
|
+
import { type PluginOptions, type TabsPlugin } from './transform';
|
|
2
2
|
export * from './index';
|
|
3
|
-
export declare function transform(options?: Partial<PluginOptions>):
|
|
4
|
-
output?: string;
|
|
5
|
-
generateID?: import("@diplodoc/utils").IDGenerator;
|
|
6
|
-
}) => void;
|
|
3
|
+
export declare function transform(options?: Partial<PluginOptions>): TabsPlugin;
|
|
@@ -1136,7 +1136,6 @@ function generateTabsTokens(tabs, state, props2) {
|
|
|
1136
1136
|
}
|
|
1137
1137
|
|
|
1138
1138
|
// src/plugin/find.ts
|
|
1139
|
-
var import_token = __toESM(require("markdown-it/lib/token"));
|
|
1140
1139
|
function findCloseTokenIndex(tokens, idx) {
|
|
1141
1140
|
let level = 0;
|
|
1142
1141
|
let i = idx;
|
|
@@ -1235,14 +1234,14 @@ function tryToFindTabs(tokens, index) {
|
|
|
1235
1234
|
extraTokensAfterClose
|
|
1236
1235
|
};
|
|
1237
1236
|
}
|
|
1238
|
-
function findTabs(tokens, idx, closeTokenIdx) {
|
|
1237
|
+
function findTabs(tokens, idx, closeTokenIdx, TokenConstructor) {
|
|
1239
1238
|
const tabs = [];
|
|
1240
1239
|
let i = idx;
|
|
1241
1240
|
let nestedLevel = -1;
|
|
1242
1241
|
let pending = {
|
|
1243
1242
|
name: "",
|
|
1244
1243
|
tokens: [],
|
|
1245
|
-
listItem: new
|
|
1244
|
+
listItem: new TokenConstructor("list_item_open", "", 0)
|
|
1246
1245
|
};
|
|
1247
1246
|
while (i < tokens.length) {
|
|
1248
1247
|
const token = tokens[i];
|
|
@@ -1305,21 +1304,35 @@ var defaultFeatures = {
|
|
|
1305
1304
|
}
|
|
1306
1305
|
};
|
|
1307
1306
|
var runsCounter = 0;
|
|
1308
|
-
function
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1307
|
+
function appendRuntimeMeta(env, runtimeJsPath, runtimeCssPath) {
|
|
1308
|
+
const meta = env.meta || (env.meta = {});
|
|
1309
|
+
if (typeof meta !== "object" || meta === null) {
|
|
1310
|
+
throw new TypeError("Expected env.meta to be an object.");
|
|
1311
|
+
}
|
|
1312
|
+
if (!("script" in meta) || !meta.script) Object.assign(meta, { script: [] });
|
|
1313
|
+
if (!("style" in meta) || !meta.style) Object.assign(meta, { style: [] });
|
|
1314
|
+
if (!("script" in meta) || !Array.isArray(meta.script) || !("style" in meta) || !Array.isArray(meta.style)) {
|
|
1315
|
+
throw new TypeError("Expected runtime script and style arrays.");
|
|
1316
|
+
}
|
|
1317
|
+
meta.script.push(runtimeJsPath);
|
|
1318
|
+
meta.style.push(runtimeCssPath);
|
|
1319
|
+
}
|
|
1320
|
+
function transform(options = {}) {
|
|
1321
|
+
const {
|
|
1322
|
+
runtimeJsPath = "_assets/tabs-extension.js",
|
|
1323
|
+
runtimeCssPath = "_assets/tabs-extension.css",
|
|
1324
|
+
containerClasses = "",
|
|
1325
|
+
bundle = true,
|
|
1326
|
+
features = defaultFeatures,
|
|
1327
|
+
onBundle: onBundle2
|
|
1328
|
+
} = options;
|
|
1329
|
+
return function tabs(md, options2) {
|
|
1330
|
+
const { output = ".", generateID: externalGenerateID } = options2 || {};
|
|
1318
1331
|
const generateID = externalGenerateID != null ? externalGenerateID : (0, import_utils6.createIDGeneratorByStrategy)("random");
|
|
1319
1332
|
const plugin = (state) => {
|
|
1320
|
-
const {
|
|
1333
|
+
const { tokens } = state;
|
|
1334
|
+
const env = addHiddenProperty(state.env, "bundled", /* @__PURE__ */ new Set());
|
|
1321
1335
|
const runId = String(++runsCounter);
|
|
1322
|
-
addHiddenProperty(env, "bundled", /* @__PURE__ */ new Set());
|
|
1323
1336
|
let i = 0;
|
|
1324
1337
|
let tabsAreInserted = false;
|
|
1325
1338
|
while (i < tokens.length) {
|
|
@@ -1333,7 +1346,7 @@ function transform({
|
|
|
1333
1346
|
if (!features.enabledVariants[parsedProps.variant]) {
|
|
1334
1347
|
parsedProps.variant = "regular" /* Regular */;
|
|
1335
1348
|
}
|
|
1336
|
-
const tabs2 = findTabs(state.tokens, i + 3, closeTokenIndex);
|
|
1349
|
+
const tabs2 = findTabs(state.tokens, i + 3, closeTokenIndex, state.Token);
|
|
1337
1350
|
if (tabs2.length > 0) {
|
|
1338
1351
|
const tabsTokens = generateTabsTokens(tabs2, state, {
|
|
1339
1352
|
containerClasses,
|
|
@@ -1354,11 +1367,7 @@ function transform({
|
|
|
1354
1367
|
}
|
|
1355
1368
|
}
|
|
1356
1369
|
if (tabsAreInserted) {
|
|
1357
|
-
env
|
|
1358
|
-
env.meta.script = env.meta.script || [];
|
|
1359
|
-
env.meta.style = env.meta.style || [];
|
|
1360
|
-
env.meta.script.push(runtimeJsPath);
|
|
1361
|
-
env.meta.style.push(runtimeCssPath);
|
|
1370
|
+
appendRuntimeMeta(env, runtimeJsPath, runtimeCssPath);
|
|
1362
1371
|
if (bundle && onBundle2) {
|
|
1363
1372
|
onBundle2({ runtimeJsPath, runtimeCssPath, output }, env.bundled);
|
|
1364
1373
|
}
|