@diplodoc/tabs-extension 3.10.7 → 3.10.8-transform5.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/README.md CHANGED
@@ -261,3 +261,15 @@ 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 and 15. Its types are derived from the public
268
+ parser constructor, so consumers use the declarations of their installed parser.
269
+ Tokens are created by the active parser state; no private MarkdownIt module is
270
+ loaded at runtime.
271
+
272
+ TypeScript consumers require TypeScript 5.3 or newer for import resolution
273
+ attributes; the strict installed-package matrix was tested with TypeScript 6.0.3.
274
+ For MarkdownIt 15, native CommonJS declarations use an explicit import-mode type
275
+ query to avoid the upstream 15.0.3 CommonJS declaration shim issue.
@@ -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/lib/token';
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,6 @@
1
1
  import { type PluginOptions } from './transform';
2
2
  export * from './index';
3
- export declare function transform(options?: Partial<PluginOptions>): (md: import("markdown-it"), options?: {
3
+ export declare function transform(options?: Partial<PluginOptions>): (md: import("./markdown-it").MarkdownIt, options?: {
4
4
  output?: string;
5
5
  generateID?: import("@diplodoc/utils").IDGenerator;
6
6
  }) => void;
@@ -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 import_token.default("list_item_open", "", 0)
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,22 @@ var defaultFeatures = {
1305
1304
  }
1306
1305
  };
1307
1306
  var runsCounter = 0;
1308
- function transform({
1309
- runtimeJsPath = "_assets/tabs-extension.js",
1310
- runtimeCssPath = "_assets/tabs-extension.css",
1311
- containerClasses = "",
1312
- bundle = true,
1313
- features = defaultFeatures,
1314
- onBundle: onBundle2
1315
- } = {}) {
1316
- return function tabs(md, options) {
1317
- const { output = ".", generateID: externalGenerateID } = options || {};
1307
+ function transform(options = {}) {
1308
+ const {
1309
+ runtimeJsPath = "_assets/tabs-extension.js",
1310
+ runtimeCssPath = "_assets/tabs-extension.css",
1311
+ containerClasses = "",
1312
+ bundle = true,
1313
+ features = defaultFeatures,
1314
+ onBundle: onBundle2
1315
+ } = options;
1316
+ return function tabs(md, options2) {
1317
+ const { output = ".", generateID: externalGenerateID } = options2 || {};
1318
1318
  const generateID = externalGenerateID != null ? externalGenerateID : (0, import_utils6.createIDGeneratorByStrategy)("random");
1319
1319
  const plugin = (state) => {
1320
- const { env, tokens } = state;
1320
+ const { tokens } = state;
1321
+ const env = addHiddenProperty(state.env, "bundled", /* @__PURE__ */ new Set());
1321
1322
  const runId = String(++runsCounter);
1322
- addHiddenProperty(env, "bundled", /* @__PURE__ */ new Set());
1323
1323
  let i = 0;
1324
1324
  let tabsAreInserted = false;
1325
1325
  while (i < tokens.length) {
@@ -1333,7 +1333,7 @@ function transform({
1333
1333
  if (!features.enabledVariants[parsedProps.variant]) {
1334
1334
  parsedProps.variant = "regular" /* Regular */;
1335
1335
  }
1336
- const tabs2 = findTabs(state.tokens, i + 3, closeTokenIndex);
1336
+ const tabs2 = findTabs(state.tokens, i + 3, closeTokenIndex, state.Token);
1337
1337
  if (tabs2.length > 0) {
1338
1338
  const tabsTokens = generateTabsTokens(tabs2, state, {
1339
1339
  containerClasses,
@@ -1354,11 +1354,17 @@ function transform({
1354
1354
  }
1355
1355
  }
1356
1356
  if (tabsAreInserted) {
1357
- env.meta = env.meta || {};
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);
1357
+ const meta = env.meta || (env.meta = {});
1358
+ if (typeof meta !== "object" || meta === null) {
1359
+ throw new TypeError("Expected env.meta to be an object.");
1360
+ }
1361
+ if (!("script" in meta) || !meta.script) Object.assign(meta, { script: [] });
1362
+ if (!("style" in meta) || !meta.style) Object.assign(meta, { style: [] });
1363
+ if (!("script" in meta) || !Array.isArray(meta.script) || !("style" in meta) || !Array.isArray(meta.style)) {
1364
+ throw new TypeError("Expected runtime script and style arrays.");
1365
+ }
1366
+ meta.script.push(runtimeJsPath);
1367
+ meta.style.push(runtimeCssPath);
1362
1368
  if (bundle && onBundle2) {
1363
1369
  onBundle2({ runtimeJsPath, runtimeCssPath, output }, env.bundled);
1364
1370
  }