@forsakringskassan/docs-generator 2.29.3 → 2.30.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.
@@ -2,7 +2,7 @@ import { createRequire as $createRequire } from "node:module";
2
2
 
3
3
  const require = $createRequire(import.meta.url);
4
4
 
5
- import { d as dedent, H as HighlightJS, c as createTwoFilesPatch, M as MarkdownIt, a as deflist_plugin } from './vendor-COMHgwYY.mjs';
5
+ import { d as dedent, H as HighlightJS, c as createTwoFilesPatch, M as MarkdownIt, a as deflist_plugin } from './vendor-B6t9njJr.mjs';
6
6
  import path from 'node:path/posix';
7
7
  import path$1 from 'node:path';
8
8
  import 'crypto';
@@ -50,7 +50,7 @@ const replacements = {
50
50
  \u00F6: "o"
51
51
  };
52
52
  function findVersion(text) {
53
- const match = text.match(/(\d+)\.(\d+)\.(\d+) \(\d+-\d+-\d+\)/);
53
+ const match = /(\d+)\.(\d+)\.(\d+) \(\d+-\d+-\d+\)/.exec(text);
54
54
  if (match) {
55
55
  return [
56
56
  parseInt(match[1], 10),
@@ -261,10 +261,13 @@ function removeLinesInline(lines, { begin, end }) {
261
261
  function cutSnippets(code) {
262
262
  const lines = code.split(/\n/).map((it, index, lines2) => index < lines2.length - 1 ? `${it}
263
263
  ` : it);
264
- const directive = /(?:\/\* +--- +cut (?<js>above|below|begin|end) +--- +\*\/|<!---? +cut (?<html>above|below|begin|end) +---?>)/;
264
+ const directive = (
265
+ /* eslint-disable-next-line sonarjs/regex-complexity -- not to bad for a regexp */
266
+ /(?:\/\* +--- +cut (?<js>above|below|begin|end) +--- +\*\/|<!---? +cut (?<html>above|below|begin|end) +---?>)/
267
+ );
265
268
  let buffer = -1;
266
269
  lines.forEach((line, index) => {
267
- const match = line.match(directive);
270
+ const match = directive.exec(line);
268
271
  const { js, html } = match?.groups ?? { js: null, html: null };
269
272
  const instruction = js ?? html;
270
273
  if (!instruction) {
@@ -367,34 +370,37 @@ class SoftError extends Error {
367
370
  }
368
371
 
369
372
  function processInlineTags(tags, doc, docs, text, handleSoftError) {
370
- return text.replace(/{@(@?)([^{}]+)}/g, (_, escape, content) => {
371
- if (escape) {
372
- return `{@${content}}`;
373
- }
374
- const match = content.match(/^(\S+)($|\s[^]+)$/);
375
- if (!match) {
376
- return `{@${content}}`;
377
- }
378
- const [, name, text2] = match;
379
- const tag = tags.find((it) => it.name === name);
380
- if (!tag) {
381
- return handleSoftError(
382
- new SoftError(
383
- "ETAGMISSING",
384
- `No inline tag registered with the name "${name}"`
385
- )
386
- );
387
- }
388
- try {
389
- return tag.handler(doc, docs, text2.trim());
390
- } catch (err) {
391
- if (err instanceof SoftError) {
392
- return handleSoftError(err);
393
- } else {
394
- throw err;
373
+ return text.replace(
374
+ /{@(@?)([^{}]+)}/g,
375
+ (_, escape, content) => {
376
+ if (escape) {
377
+ return `{@${content}}`;
378
+ }
379
+ const match = /^(\S+)($|\s[^]+)$/.exec(content);
380
+ if (!match) {
381
+ return `{@${content}}`;
382
+ }
383
+ const [, name, text2] = match;
384
+ const tag = tags.find((it) => it.name === name);
385
+ if (!tag) {
386
+ return handleSoftError(
387
+ new SoftError(
388
+ "ETAGMISSING",
389
+ `No inline tag registered with the name "${name}"`
390
+ )
391
+ );
392
+ }
393
+ try {
394
+ return tag.handler(doc, docs, text2.trim());
395
+ } catch (err) {
396
+ if (err instanceof SoftError) {
397
+ return handleSoftError(err);
398
+ } else {
399
+ throw err;
400
+ }
395
401
  }
396
402
  }
397
- });
403
+ );
398
404
  }
399
405
 
400
406
  function getRelativeUrl(from, to) {
@@ -419,7 +425,7 @@ function getLinkTitle(doc, key, explicitTitle) {
419
425
  return explicitTitle.replace(/^[\\|]\s*/, "");
420
426
  }
421
427
  const { title, component } = doc.attributes;
422
- if (component && component.some((it) => it.name === key)) {
428
+ if (component?.some((it) => it.name === key)) {
423
429
  return `<code>${key}</code>`;
424
430
  } else {
425
431
  return title ?? doc.name;
@@ -429,14 +435,16 @@ const linkTag = {
429
435
  name: "link",
430
436
  description: "Create a link to another document",
431
437
  handler(doc, docs, content) {
432
- const match = content.match(/^([^\s#]+)(#\S+)?\s*(.+)?$/);
438
+ const match = /^([^\s#]+)(#\S+)?\s*(.+)?$/.exec(content);
433
439
  if (!match) {
434
440
  throw new SoftError(
435
441
  "ELINKFORMAT",
436
442
  `Failed to parse link "${content}"`
437
443
  );
438
444
  }
439
- const [, key, hash, explicitTitle] = match;
445
+ const key = match[1];
446
+ const hash = match[2];
447
+ const explicitTitle = match[3];
440
448
  if (key.startsWith("http://") || key.startsWith("https://")) {
441
449
  return `<a href="${key}${hash ?? ""}">${explicitTitle ?? key}</a>`;
442
450
  }
@@ -635,7 +643,7 @@ function codePreview(options) {
635
643
  tags: rawTags
636
644
  });
637
645
  const { tags } = example;
638
- const hashContent = `${map?.[0]}:${map?.[1]}:${info}:${rawContent}`;
646
+ const hashContent = `${String(map?.[0])}:${String(map?.[1])}:${info}:${rawContent}`;
639
647
  const fingerprint = getFingerprint(hashContent);
640
648
  const transformedCode = transformCode(example.source, example.language);
641
649
  const highlightedCode = replaceAtLink(
@@ -724,7 +732,10 @@ function codePreview(options) {
724
732
  const toggleFullscreen = showFullscreen ? (
725
733
  /* HTML */
726
734
  `
727
- <a href="${standalonePath}" class="code-preview__fullscreen">
735
+ <a
736
+ href="${standalonePath ?? ""}"
737
+ class="code-preview__fullscreen"
738
+ >
728
739
  <i class="icon icon--fullscreen"></i>
729
740
  Helsk\xE4rm
730
741
  </a>
@@ -770,20 +781,20 @@ function headingLevel(options) {
770
781
  const title = getTokensText(tokens[idx + 1]?.children ?? []);
771
782
  let id = generateId(title);
772
783
  if (ids.has(id)) {
773
- id += `--${counter++}`;
784
+ id += `--${String(counter++)}`;
774
785
  }
775
786
  ids.add(id);
776
787
  return tag.replace(/h(\d)/, (_, n) => {
777
788
  const level = parseInt(n, 10) + offset;
778
789
  env.currentHeading = level;
779
- return `<h${level} id="${id}"><a class="header-anchor" href="#${id}">`;
790
+ return `<h${String(level)} id="${id}"><a class="header-anchor" href="#${id}">`;
780
791
  });
781
792
  };
782
793
  md.renderer.rules.heading_close = function(tokens, idx) {
783
794
  const { tag } = tokens[idx];
784
795
  return tag.replace(/h(\d)/, (_, n) => {
785
796
  const level = parseInt(n, 10) + offset;
786
- return `</a></h${level}>`;
797
+ return `</a></h${String(level)}>`;
787
798
  });
788
799
  };
789
800
  };
@@ -890,7 +901,7 @@ function detailsContainer(context, options) {
890
901
  if (customTitle.length > 0) {
891
902
  return customTitle.join(" ");
892
903
  } else {
893
- return options.title["details"] || "Details";
904
+ return options.title.details ?? "Details";
894
905
  }
895
906
  }
896
907
  return (tokens, index) => {
@@ -1017,7 +1028,7 @@ function containerParser(md, options) {
1017
1028
  len = state.sCount[startLine];
1018
1029
  state.line = nextLine + (haveEndMarker ? 1 : 0);
1019
1030
  const token = state.push(`doc_${kind}`, "div", 0);
1020
- token.info = info?.trim();
1031
+ token.info = info.trim();
1021
1032
  token.content = state.getLines(startLine + 1, nextLine, len, true);
1022
1033
  token.markup = markup;
1023
1034
  token.map = [startLine, state.line];
@@ -1169,4 +1180,4 @@ function createMarkdownRenderer(options) {
1169
1180
  }
1170
1181
 
1171
1182
  export { SoftError as S, getFingerprint as a, getOutputFilePath as b, createMarkdownRenderer as c, htmlencode as d, exampleWorkerUrl as e, findTag as f, generateId as g, hasTag as h, isDocumentPage as i, generateExample as j, normalizePath as n, parseInfostring as p };
1172
- //# sourceMappingURL=create-markdown-renderer-Bqm7kdpQ.mjs.map
1183
+ //# sourceMappingURL=create-markdown-renderer-D5LtM0yF.mjs.map