@diplodoc/tabs-extension 3.10.8-transform5.2 → 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.
@@ -582,9 +582,918 @@ var require_slugify = __commonJS({
582
582
  }
583
583
  });
584
584
 
585
+ // node_modules/@diplodoc/directive/build/index.js
586
+ var require_build = __commonJS({
587
+ "node_modules/@diplodoc/directive/build/index.js"(exports2, module2) {
588
+ "use strict";
589
+ var __create2 = Object.create;
590
+ var __defProp2 = Object.defineProperty;
591
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
592
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
593
+ var __getProtoOf2 = Object.getPrototypeOf;
594
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
595
+ var __commonJS2 = (cb, mod) => function __require() {
596
+ return mod || (0, cb[__getOwnPropNames2(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
597
+ };
598
+ var __export2 = (target, all) => {
599
+ for (var name in all)
600
+ __defProp2(target, name, { get: all[name], enumerable: true });
601
+ };
602
+ var __copyProps2 = (to, from, except, desc) => {
603
+ if (from && typeof from === "object" || typeof from === "function") {
604
+ for (let key of __getOwnPropNames2(from))
605
+ if (!__hasOwnProp2.call(to, key) && key !== except)
606
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
607
+ }
608
+ return to;
609
+ };
610
+ var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
611
+ // If the importer is in node compatibility mode or this is not an ESM
612
+ // file that has been converted to a CommonJS file using a Babel-
613
+ // compatible transform (i.e. "__esModule" has not been set), then set
614
+ // "default" to the CommonJS "module.exports" for node compatibility.
615
+ isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target,
616
+ mod
617
+ ));
618
+ var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
619
+ var require_markdown_it_directive = __commonJS2({
620
+ "node_modules/markdown-it-directive/index.js"(exports22, module22) {
621
+ "use strict";
622
+ function isBlank(code) {
623
+ switch (code) {
624
+ case 9:
625
+ case 32:
626
+ case 10:
627
+ return true;
628
+ }
629
+ return false;
630
+ }
631
+ function skipBlanks(src, pos, max) {
632
+ for (; pos < max && isBlank(src.charCodeAt(pos)); ++pos) ;
633
+ return pos;
634
+ }
635
+ function skipBlanksBack(src, pos, min) {
636
+ for (; min < pos && isBlank(src.charCodeAt(pos - 1)); --pos) ;
637
+ return pos;
638
+ }
639
+ var DIRECTIVE_NAME_RE = /^[a-z][a-z0-9\-_]*/i;
640
+ var normalizeDirectiveName = (s) => s.toLowerCase().replace("_", "-");
641
+ function parseDirectiveName(src, pos, max) {
642
+ const oldPos = pos;
643
+ const rst = src.slice(pos, max).match(DIRECTIVE_NAME_RE);
644
+ if (rst === null) return null;
645
+ pos += rst[0].length;
646
+ return { pos, name: normalizeDirectiveName(src.slice(oldPos, pos)) };
647
+ }
648
+ function parseLinkDestinationLabel(md, src, pos, max) {
649
+ if (pos >= max) return null;
650
+ if (src.charCodeAt(pos) !== 40) return null;
651
+ const dests = [];
652
+ ++pos, pos = skipBlanks(src, pos, max);
653
+ for (; pos < max; pos = skipBlanks(src, pos, max)) {
654
+ if (src.charCodeAt(pos) === 41) {
655
+ ++pos;
656
+ return { pos, dests };
657
+ }
658
+ const c = src.charCodeAt(pos);
659
+ if (c === 34 || c === 39 || c === 40) {
660
+ const rst = md.helpers.parseLinkTitle(src, pos, max);
661
+ if (!rst.ok) return null;
662
+ pos = rst.pos;
663
+ dests.push(["string", rst.str]);
664
+ } else {
665
+ const rst = md.helpers.parseLinkDestination(src, pos, max);
666
+ if (!rst.ok) return null;
667
+ pos = rst.pos;
668
+ dests.push(["link", rst.str]);
669
+ }
670
+ if (pos >= max) return null;
671
+ const charBetween = src.charCodeAt(pos);
672
+ if (!isBlank(charBetween) && charBetween !== 41) return null;
673
+ }
674
+ return null;
675
+ }
676
+ var ATTR_NAME_RE = /^[a-z][a-z0-9\-_]*/;
677
+ function parseAttrName(src, pos, max) {
678
+ const oldPos = pos;
679
+ const rst = src.slice(pos, max).match(ATTR_NAME_RE);
680
+ if (rst === null) return null;
681
+ pos += rst[0].length;
682
+ return { pos, name: src.slice(oldPos, pos) };
683
+ }
684
+ var UNSURROUNDED_STRING_RE = /^[a-z0-9\-_]+/i;
685
+ function parseUnsurroundedName(src, pos, max) {
686
+ const oldPos = pos;
687
+ const rst = src.slice(pos, max).match(UNSURROUNDED_STRING_RE);
688
+ if (rst === null) return null;
689
+ pos += rst[0].length;
690
+ return { pos, name: src.slice(oldPos, pos) };
691
+ }
692
+ function parseAttrLabel(md, src, pos, max) {
693
+ if (pos >= max) return null;
694
+ if (src.charCodeAt(pos) !== 123) return null;
695
+ const attrs = /* @__PURE__ */ Object.create(null);
696
+ ++pos, pos = skipBlanks(src, pos, max);
697
+ for (; pos < max; pos = skipBlanks(src, pos, max)) {
698
+ if (src.charCodeAt(pos) === 125) {
699
+ ++pos;
700
+ for (const key in attrs) {
701
+ if (attrs[key].length === 1) attrs[key] = attrs[key][0];
702
+ }
703
+ return { pos, attrs: { ...attrs } };
704
+ }
705
+ const c = src.charCodeAt(pos);
706
+ if (c === 35) {
707
+ ++pos;
708
+ const rst = parseUnsurroundedName(src, pos, max);
709
+ if (rst === null) return null;
710
+ pos = rst.pos;
711
+ const key = "id", value = rst.name;
712
+ if (typeof attrs[key] === "undefined") {
713
+ attrs[key] = [value];
714
+ } else {
715
+ attrs[key].push(value);
716
+ }
717
+ } else if (c === 46) {
718
+ ++pos;
719
+ const rst = parseUnsurroundedName(src, pos, max);
720
+ if (rst === null) return null;
721
+ pos = rst.pos;
722
+ const key = "class", value = rst.name;
723
+ if (typeof attrs[key] === "undefined") {
724
+ attrs[key] = [value];
725
+ } else {
726
+ attrs[key].push(value);
727
+ }
728
+ } else {
729
+ let rst = parseAttrName(src, pos, max);
730
+ if (rst === null) return null;
731
+ const key = rst.name;
732
+ pos = rst.pos, pos = skipBlanks(src, pos, max);
733
+ if (pos >= max) return null;
734
+ if (src.charCodeAt(pos) !== 61) return null;
735
+ ++pos, pos = skipBlanks(src, pos, max);
736
+ if (pos >= max) return null;
737
+ let value;
738
+ const c2 = src.charCodeAt(pos);
739
+ if (c2 === 34 || c2 === 39) {
740
+ rst = md.helpers.parseLinkTitle(src, pos, max);
741
+ if (!rst.ok) return null;
742
+ value = rst.str;
743
+ pos = rst.pos;
744
+ } else {
745
+ rst = parseUnsurroundedName(src, pos, max);
746
+ if (rst === null) return null;
747
+ value = rst.name;
748
+ pos = rst.pos;
749
+ }
750
+ if (typeof attrs[key] === "undefined") {
751
+ attrs[key] = [value];
752
+ } else {
753
+ attrs[key].push(value);
754
+ }
755
+ }
756
+ if (pos >= max) return null;
757
+ const charBetween = src.charCodeAt(pos);
758
+ if (!isBlank(charBetween) && charBetween !== 125) return null;
759
+ }
760
+ return null;
761
+ }
762
+ function parseDirective(state, src, pos, max, allowSpaceBetween) {
763
+ const md = state.md;
764
+ const nameResult = parseDirectiveName(src, pos, max);
765
+ if (nameResult === null) return null;
766
+ const name = nameResult.name;
767
+ pos = nameResult.pos;
768
+ if (allowSpaceBetween) pos = skipBlanks(src, pos, max);
769
+ const labelStart = pos, labelEnd = md.helpers.parseLinkLabel(state, labelStart);
770
+ let content;
771
+ let contentStart, contentEnd;
772
+ if (labelEnd >= 0) {
773
+ content = src.slice(pos + 1, labelEnd);
774
+ pos = labelEnd + 1;
775
+ contentStart = labelStart + 1;
776
+ contentEnd = labelEnd;
777
+ }
778
+ if (allowSpaceBetween) pos = skipBlanks(src, pos, max);
779
+ const destsStart = pos;
780
+ const destsResult = parseLinkDestinationLabel(md, src, destsStart, max);
781
+ let dests;
782
+ if (destsResult !== null) {
783
+ dests = destsResult.dests;
784
+ pos = destsResult.pos;
785
+ } else if (typeof state.env.references !== "undefined") {
786
+ const destsEnd = md.helpers.parseLinkLabel(state, destsStart);
787
+ if (destsEnd >= 0) {
788
+ const refText = src.slice(destsStart + 1, destsEnd);
789
+ const ref = state.env.references[md.utils.normalizeReference(refText)];
790
+ if (ref) {
791
+ dests = [["link", ref.href], ["string", ref.title]];
792
+ pos = destsEnd + 1;
793
+ }
794
+ } else if (content !== void 0) {
795
+ const ref = state.env.references[md.utils.normalizeReference(content)];
796
+ if (ref) {
797
+ dests = [["link", ref.href], ["string", ref.title]];
798
+ }
799
+ }
800
+ }
801
+ if (allowSpaceBetween) pos = skipBlanks(src, pos, max);
802
+ const attrsResult = parseAttrLabel(md, src, pos, max);
803
+ let attrs;
804
+ if (attrsResult !== null) {
805
+ attrs = attrsResult.attrs;
806
+ pos = attrsResult.pos;
807
+ }
808
+ if (allowSpaceBetween) pos = skipBlanks(src, pos, max);
809
+ return { directiveName: name, content, dests, attrs, contentStart, contentEnd, pos };
810
+ }
811
+ function inlineDirectiveRule(state, silent) {
812
+ const md = state.md, src = state.src;
813
+ const max = state.posMax;
814
+ let pos = state.pos;
815
+ if (src.charCodeAt(pos) !== 58) return false;
816
+ ++pos;
817
+ const rst = parseDirective(state, src, pos, max, false);
818
+ if (rst === null) return false;
819
+ const { directiveName, content, dests, attrs, contentStart, contentEnd } = rst;
820
+ const handler = md.inlineDirectives[directiveName];
821
+ if (typeof handler === "undefined") return false;
822
+ pos = rst.pos;
823
+ if (!silent) {
824
+ const isValidContent = handler({
825
+ state,
826
+ content,
827
+ dests,
828
+ attrs,
829
+ contentStart,
830
+ contentEnd,
831
+ directiveStart: state.pos,
832
+ directiveEnd: pos
833
+ });
834
+ if (isValidContent === false) return false;
835
+ }
836
+ state.pos = pos;
837
+ return true;
838
+ }
839
+ function findNextLine(src, startLine, endLine, state) {
840
+ let line = startLine + 1;
841
+ let level = 1;
842
+ for (; line < endLine && level !== 0; ++line) {
843
+ const max = state.eMarks[line];
844
+ let pos = state.bMarks[line] + state.tShift[line];
845
+ let pos2 = state.skipChars(pos, 58);
846
+ let colonsCount = pos2 - pos;
847
+ if (colonsCount >= 3) {
848
+ pos2 = skipBlanks(src, pos2, max);
849
+ if (pos2 === max) {
850
+ --level;
851
+ continue;
852
+ }
853
+ }
854
+ if (colonsCount >= 3 && pos2 < max) {
855
+ ++level;
856
+ }
857
+ }
858
+ if (level !== 0) return -1;
859
+ return line;
860
+ }
861
+ function blockDirectiveRule(state, startLine, endLine, silent) {
862
+ const md = state.md, src = state.src;
863
+ const max = state.eMarks[startLine];
864
+ let pos = state.bMarks[startLine] + state.tShift[startLine];
865
+ if (pos + 3 > max || src.charCodeAt(pos) !== 58 || src.charCodeAt(pos + 1) !== 58) {
866
+ return false;
867
+ }
868
+ pos += 2;
869
+ let oneLine = false;
870
+ if (src.charCodeAt(pos) !== 58) {
871
+ oneLine = true;
872
+ } else {
873
+ pos = state.skipChars(
874
+ pos,
875
+ 58
876
+ /* : */
877
+ );
878
+ }
879
+ pos = skipBlanks(src, pos, max);
880
+ const inlineState = new md.inline.State(src, md, state.env, []);
881
+ const rst = parseDirective(inlineState, src, pos, max, true);
882
+ if (rst === null) return false;
883
+ const { directiveName, content: inlineContent, dests, attrs, contentStart: inlineContentStart, contentEnd: inlineContentEnd } = rst;
884
+ const handler = md.blockDirectives[directiveName];
885
+ if (typeof handler === "undefined") return false;
886
+ pos = rst.pos;
887
+ const contentTitleStart = pos;
888
+ let posEnd = skipBlanksBack(src, max, pos);
889
+ let tmp = state.skipCharsBack(posEnd, 58, pos);
890
+ if (posEnd - tmp > 1) posEnd = tmp;
891
+ const contentTitleEnd = skipBlanksBack(src, posEnd, pos);
892
+ const contentTitle = src.slice(contentTitleStart, contentTitleEnd);
893
+ if (oneLine) {
894
+ if (!silent) {
895
+ const isValidContent = handler({
896
+ state,
897
+ contentTitle,
898
+ inlineContent,
899
+ dests,
900
+ attrs,
901
+ contentTitleStart,
902
+ contentTitleEnd,
903
+ inlineContentStart,
904
+ inlineContentEnd,
905
+ directiveStartLine: startLine,
906
+ directiveEndLine: startLine + 1
907
+ });
908
+ if (isValidContent === false) return false;
909
+ }
910
+ state.line = startLine + 1;
911
+ return true;
912
+ }
913
+ const nextLine = findNextLine(src, startLine, endLine, state);
914
+ if (nextLine === -1) return false;
915
+ const content = state.getLines(startLine + 1, nextLine - 1, state.sCount[startLine], true);
916
+ if (!silent) {
917
+ const isValidContent = handler({
918
+ state,
919
+ content,
920
+ contentTitle,
921
+ inlineContent,
922
+ dests,
923
+ attrs,
924
+ contentStartLine: startLine + 1,
925
+ contentEndLine: nextLine - 1,
926
+ contentTitleStart,
927
+ contentTitleEnd,
928
+ inlineContentStart,
929
+ inlineContentEnd,
930
+ directiveStartLine: startLine,
931
+ directiveEndLine: nextLine
932
+ });
933
+ if (isValidContent === false) return false;
934
+ }
935
+ state.line = nextLine;
936
+ return true;
937
+ }
938
+ function load(md) {
939
+ if (md.inlineDirectives) return;
940
+ md.inlineDirectives = {};
941
+ md.blockDirectives = {};
942
+ md.inline.ruler.push("inline_directive", inlineDirectiveRule);
943
+ md.block.ruler.before("heading", "block_directive", blockDirectiveRule);
944
+ }
945
+ module22.exports = load;
946
+ }
947
+ });
948
+ var index_exports = {};
949
+ __export2(index_exports, {
950
+ createBlockInlineToken: () => createBlockInlineToken,
951
+ directiveParser: () => directiveParser2,
952
+ disableBlockDirectives: () => disableBlockDirectives,
953
+ disableInlineDirectives: () => disableInlineDirectives,
954
+ enableBlockDirectives: () => enableBlockDirectives,
955
+ enableInlineDirectives: () => enableInlineDirectives,
956
+ registerContainerDirective: () => registerContainerDirective2,
957
+ registerInlineDirective: () => registerInlineDirective,
958
+ registerLeafBlockDirective: () => registerLeafBlockDirective,
959
+ tokenizeBlockContent: () => tokenizeBlockContent2,
960
+ tokenizeInlineContent: () => tokenizeInlineContent
961
+ });
962
+ module2.exports = __toCommonJS2(index_exports);
963
+ var import_markdown_it_directive = __toESM2(require_markdown_it_directive());
964
+ function isRecord(value) {
965
+ return typeof value === "object" && value !== null;
966
+ }
967
+ function registry(host, key, create = false) {
968
+ let value = Reflect.get(host, key);
969
+ if (value === void 0 && create) {
970
+ value = {};
971
+ if (!Reflect.set(host, key, value)) {
972
+ throw new TypeError("Cannot create directive handler registry");
973
+ }
974
+ }
975
+ if (!isRecord(value)) {
976
+ throw new TypeError("Directive parser must be installed before registering directives");
977
+ }
978
+ return value;
979
+ }
980
+ function lookupHandler(host, key, name) {
981
+ const table = Reflect.get(host, key);
982
+ if (table === void 0) return void 0;
983
+ return registry(host, key)[name];
984
+ }
985
+ function assertHostState(state, Constructor) {
986
+ if (!(state instanceof Constructor)) {
987
+ throw new TypeError("Directive handler received a state from a different host");
988
+ }
989
+ }
990
+ function invokeHandler(handler, state, params) {
991
+ if (typeof handler !== "function") {
992
+ throw new TypeError("Invalid directive handler");
993
+ }
994
+ const result = Reflect.apply(handler, void 0, [state, params]);
995
+ if (result !== void 0 && typeof result !== "boolean") {
996
+ throw new TypeError("Invalid directive handler result");
997
+ }
998
+ return result;
999
+ }
1000
+ function runtimeRules(ruler) {
1001
+ const rules = Reflect.get(ruler, "__rules__");
1002
+ if (!Array.isArray(rules)) {
1003
+ throw new TypeError("Missing native block rules");
1004
+ }
1005
+ return rules.map((rule) => {
1006
+ if (!isRecord(rule) || typeof rule.name !== "string" || typeof rule.enabled !== "boolean" || typeof rule.fn !== "function") {
1007
+ throw new TypeError("Invalid native block rule");
1008
+ }
1009
+ return {
1010
+ name: rule.name,
1011
+ enabled: rule.enabled,
1012
+ get fn() {
1013
+ const fn = rule.fn;
1014
+ if (typeof fn !== "function") throw new TypeError("Invalid native block rule");
1015
+ return (state, start, end, silent) => {
1016
+ const result = Reflect.apply(fn, void 0, [
1017
+ state,
1018
+ start,
1019
+ end,
1020
+ silent
1021
+ ]);
1022
+ if (typeof result !== "boolean")
1023
+ throw new TypeError("Invalid block rule result");
1024
+ return result;
1025
+ };
1026
+ },
1027
+ set fn(fn) {
1028
+ rule.fn = fn;
1029
+ }
1030
+ };
1031
+ });
1032
+ }
1033
+ function assertScanner(value) {
1034
+ if (!isRecord(value) || !isRecord(value.block) || typeof value.block.State !== "function" || typeof value.block.tokenize !== "function" || !isRecord(value.block.ruler)) {
1035
+ throw new TypeError("Invalid native block scanner");
1036
+ }
1037
+ const ruler = value.block.ruler;
1038
+ if (!["enableOnly", "before", "push"].every((key) => typeof ruler[key] === "function")) {
1039
+ throw new TypeError("Invalid native block scanner ruler");
1040
+ }
1041
+ }
1042
+ function assertBoundaryState(value) {
1043
+ if (!isRecord(value) || typeof value.src !== "string" || typeof value.parentType !== "string" || typeof value.tight !== "boolean" || typeof value.skipChars !== "function" || !isRecord(value.md) || typeof value.md.constructor !== "function" || !isRecord(value.md.block) || !isRecord(value.md.block.ruler)) {
1044
+ throw new TypeError("Invalid native block scanner state");
1045
+ }
1046
+ for (const key of ["bMarks", "eMarks", "tShift", "sCount", "bsCount"]) {
1047
+ const field = value[key];
1048
+ if (!Array.isArray(field) || !field.every((item) => typeof item === "number")) {
1049
+ throw new TypeError(`Invalid native block scanner state: ${key}`);
1050
+ }
1051
+ }
1052
+ if (value.ddIndent !== void 0 && typeof value.ddIndent !== "number") {
1053
+ throw new TypeError("Invalid native block scanner state: ddIndent");
1054
+ }
1055
+ for (const key of ["line", "lineMax", "blkIndent", "listIndent", "level"]) {
1056
+ if (typeof value[key] !== "number")
1057
+ throw new TypeError(`Invalid native block scanner state: ${key}`);
1058
+ }
1059
+ }
1060
+ function findClosingLine(state, startLine, endLine) {
1061
+ const md = Reflect.construct(state.md.constructor, ["commonmark", state.md.options]);
1062
+ assertScanner(md);
1063
+ const hostRules = runtimeRules(state.md.block.ruler);
1064
+ const enabled = new Set(hostRules.filter((rule) => rule.enabled).map((rule) => rule.name));
1065
+ const nativeRules = runtimeRules(md.block.ruler);
1066
+ md.block.ruler.enableOnly(
1067
+ nativeRules.filter((rule) => enabled.has(rule.name)).map(({ name }) => name)
1068
+ );
1069
+ let closingLine = -1;
1070
+ const scopes = [];
1071
+ const marker = (scanState2, line, end, silent) => {
1072
+ const pos = scanState2.bMarks[line] + scanState2.tShift[line];
1073
+ const max = scanState2.eMarks[line];
1074
+ const after = scanState2.skipChars(pos, 58);
1075
+ if (after - pos < 3) {
1076
+ return false;
1077
+ }
1078
+ if (silent) {
1079
+ return true;
1080
+ }
1081
+ if (scanState2.sCount[line] < scanState2.blkIndent) {
1082
+ return false;
1083
+ }
1084
+ const scope = scopes[scopes.length - 1];
1085
+ if (/^[ \t]*$/.test(scanState2.src.slice(after, max))) {
1086
+ if (scope.depth > 0 && --scope.depth === 0 && scope.root) {
1087
+ closingLine = line;
1088
+ scanState2.line = end;
1089
+ return true;
1090
+ }
1091
+ } else {
1092
+ scope.depth++;
1093
+ }
1094
+ scanState2.line = line + 1;
1095
+ return true;
1096
+ };
1097
+ const paragraph = nativeRules.find(({ name }) => name === "paragraph");
1098
+ if (paragraph) {
1099
+ const paragraphRule = paragraph.fn;
1100
+ paragraph.fn = (scanState2, begin, end, silent) => {
1101
+ const matched = paragraphRule(scanState2, begin, end, silent);
1102
+ if (matched && !silent) {
1103
+ const next = scanState2.line;
1104
+ for (let line = begin + 1; line < next; line++) {
1105
+ marker(scanState2, line, end, false);
1106
+ if (closingLine >= 0) {
1107
+ return matched;
1108
+ }
1109
+ }
1110
+ scanState2.line = next;
1111
+ }
1112
+ return matched;
1113
+ };
1114
+ }
1115
+ const tokenize = md.block.tokenize;
1116
+ md.block.tokenize = (scanState2, begin, end) => {
1117
+ scopes.push({ depth: scopes.length ? 0 : 1, root: scopes.length === 0 });
1118
+ try {
1119
+ tokenize.call(md.block, scanState2, begin, end);
1120
+ } finally {
1121
+ scopes.pop();
1122
+ }
1123
+ };
1124
+ md.block.ruler.before("heading", "directive_boundary", marker, {
1125
+ alt: ["paragraph", "reference", "blockquote", "list"]
1126
+ });
1127
+ md.block.ruler.push("directive_boundary_fallback", (scanState2, line, _end, silent) => {
1128
+ if (silent) {
1129
+ return false;
1130
+ }
1131
+ scanState2.line = line + 1;
1132
+ return true;
1133
+ });
1134
+ const scanState = Reflect.construct(md.block.State, [state.src, md, {}, []]);
1135
+ assertBoundaryState(scanState);
1136
+ Object.assign(scanState, {
1137
+ bMarks: state.bMarks.slice(),
1138
+ eMarks: state.eMarks.slice(),
1139
+ tShift: state.tShift.slice(),
1140
+ sCount: state.sCount.slice(),
1141
+ bsCount: state.bsCount.slice(),
1142
+ line: startLine + 1,
1143
+ lineMax: endLine,
1144
+ blkIndent: state.blkIndent,
1145
+ listIndent: state.listIndent,
1146
+ ddIndent: state.ddIndent,
1147
+ parentType: state.parentType,
1148
+ level: state.level,
1149
+ tight: state.tight
1150
+ });
1151
+ md.block.tokenize(scanState, startLine + 1, endLine);
1152
+ return closingLine;
1153
+ }
1154
+ function withBlockBoundary(rule) {
1155
+ return (state, startLine, endLine, silent) => {
1156
+ var _a;
1157
+ const start = state.bMarks[startLine] + state.tShift[startLine];
1158
+ if (state.src.slice(start, start + 3) !== ":::") {
1159
+ return rule(state, startLine, endLine, silent);
1160
+ }
1161
+ const name = (_a = state.src.slice(start, state.eMarks[startLine]).match(/^:{3,}[ \t]*([a-z][a-z0-9_-]*)/i)) == null ? void 0 : _a[1];
1162
+ const normalizedName = name == null ? void 0 : name.toLowerCase().replace("_", "-");
1163
+ if (!normalizedName || !registry(state.md, "blockDirectives")[normalizedName]) {
1164
+ return rule(state, startLine, endLine, silent);
1165
+ }
1166
+ const close = findClosingLine(state, startLine, endLine);
1167
+ if (close < 0) {
1168
+ return false;
1169
+ }
1170
+ const skipChars = state.skipChars;
1171
+ const descriptor = Object.getOwnPropertyDescriptor(state, "skipChars");
1172
+ const restore = () => {
1173
+ if (descriptor) {
1174
+ Object.defineProperty(state, "skipChars", descriptor);
1175
+ } else {
1176
+ Reflect.deleteProperty(state, "skipChars");
1177
+ }
1178
+ };
1179
+ const hidden = /* @__PURE__ */ new Set();
1180
+ for (let line = startLine + 1; line < close; line++) {
1181
+ hidden.add(state.bMarks[line] + state.tShift[line]);
1182
+ }
1183
+ const closingPos = state.bMarks[close] + state.tShift[close];
1184
+ state.skipChars = (pos, code) => {
1185
+ if (code === 58) {
1186
+ if (pos === closingPos) {
1187
+ restore();
1188
+ } else if (hidden.has(pos)) {
1189
+ return pos;
1190
+ }
1191
+ }
1192
+ return skipChars.call(state, pos, code);
1193
+ };
1194
+ try {
1195
+ return rule(state, startLine, endLine, silent);
1196
+ } finally {
1197
+ restore();
1198
+ }
1199
+ };
1200
+ }
1201
+ var RULE = {
1202
+ Inline: "inline_directive",
1203
+ Block: "block_directive"
1204
+ };
1205
+ var CONTAINER_KEY = /* @__PURE__ */ Symbol();
1206
+ var LEAF_BLOCK_KEY = /* @__PURE__ */ Symbol();
1207
+ function enableInlineDirectives(md) {
1208
+ md.inline.ruler.enable(RULE.Inline, true);
1209
+ }
1210
+ function disableInlineDirectives(md) {
1211
+ md.inline.ruler.disable(RULE.Inline, true);
1212
+ }
1213
+ function enableBlockDirectives(md) {
1214
+ md.block.ruler.enable(RULE.Block, true);
1215
+ }
1216
+ function disableBlockDirectives(md) {
1217
+ md.block.ruler.disable(RULE.Block, true);
1218
+ }
1219
+ function isFunction(arg) {
1220
+ return typeof arg === "function";
1221
+ }
1222
+ function isString(arg) {
1223
+ return typeof arg === "string";
1224
+ }
1225
+ function tokenizeInlineContent(state, content) {
1226
+ const oldPos = state.pos;
1227
+ const oldPosMax = state.posMax;
1228
+ state.pos = content.startPos;
1229
+ state.posMax = content.endPos;
1230
+ state.md.inline.tokenize(state);
1231
+ state.pos = oldPos;
1232
+ state.posMax = oldPosMax;
1233
+ }
1234
+ function tokenizeBlockContent2(state, content, parentType) {
1235
+ const oldParent = state.parentType;
1236
+ const oldLineMax = state.lineMax;
1237
+ state.parentType = parentType != null ? parentType : "directive";
1238
+ state.line = content.startLine;
1239
+ state.lineMax = content.endLine;
1240
+ state.md.block.tokenize(state, content.startLine, content.endLine);
1241
+ state.lineMax = oldLineMax;
1242
+ state.parentType = oldParent;
1243
+ }
1244
+ function createBlockInlineToken(state, { inlineContent, startLine }) {
1245
+ const token = state.push("inline", "", 0);
1246
+ token.children = [];
1247
+ token.content = (inlineContent == null ? void 0 : inlineContent.raw) || "";
1248
+ token.map = [startLine, startLine + 1];
1249
+ return token;
1250
+ }
1251
+ function registerInlineDirective(md, name, handler) {
1252
+ registry(md, "inlineDirectives")[name] = (args) => {
1253
+ assertHostState(args.state, md.inline.State);
1254
+ const params = buildInlineParams(args);
1255
+ return handler(args.state, params);
1256
+ };
1257
+ }
1258
+ function registerLeafBlockDirective(md, nameOrConfig, maybeHandler) {
1259
+ const [name, handler] = isString(nameOrConfig) ? [nameOrConfig, maybeHandler] : [nameOrConfig.name, buildLeafBlockHandler(nameOrConfig)];
1260
+ registry(md, LEAF_BLOCK_KEY, true);
1261
+ registry(md, LEAF_BLOCK_KEY)[name] = handler;
1262
+ registry(md, "blockDirectives")[name] = getBlockDefaultHandler(md, name);
1263
+ }
1264
+ function registerContainerDirective2(md, nameOrConfig, maybeHandler, options) {
1265
+ const [name, handler] = isString(nameOrConfig) ? [nameOrConfig, maybeHandler] : [
1266
+ nameOrConfig.name,
1267
+ nameOrConfig.type === "code_block" ? buildCodeContainerHandler(nameOrConfig) : buildContainerHandler(nameOrConfig)
1268
+ ];
1269
+ const onConflict = isString(nameOrConfig) ? options == null ? void 0 : options.onConflict : nameOrConfig.onConflict;
1270
+ const directives = registry(md, "blockDirectives");
1271
+ if (onConflict === "error" && Object.prototype.hasOwnProperty.call(directives, name)) {
1272
+ throw new Error(`Block directive already registered: ${name}`);
1273
+ }
1274
+ registry(md, CONTAINER_KEY, true);
1275
+ registry(md, CONTAINER_KEY)[name] = handler;
1276
+ registry(md, "blockDirectives")[name] = getBlockDefaultHandler(md, name);
1277
+ }
1278
+ function getBlockDefaultHandler(md, name) {
1279
+ return (args) => {
1280
+ assertHostState(args.state, md.block.State);
1281
+ const containerHandler = lookupHandler(md, CONTAINER_KEY, name);
1282
+ const leafBlockHandler = lookupHandler(md, LEAF_BLOCK_KEY, name);
1283
+ if (isString(args.content)) {
1284
+ if (containerHandler) {
1285
+ return invokeHandler(containerHandler, args.state, buildContainerParams(args));
1286
+ }
1287
+ } else if (leafBlockHandler) {
1288
+ return invokeHandler(leafBlockHandler, args.state, buildLeafBlockParams(args));
1289
+ }
1290
+ return false;
1291
+ };
1292
+ }
1293
+ function buildLeafBlockHandler(config) {
1294
+ return (state, params) => {
1295
+ if (!config.match(params, state)) {
1296
+ return false;
1297
+ }
1298
+ const { container } = config;
1299
+ const token = state.push(container.token, container.tag, 0);
1300
+ token.map = [params.startLine, params.endLine];
1301
+ token.markup = "::" + config.name;
1302
+ applyTokenFields(token, container, params, state.env);
1303
+ return true;
1304
+ };
1305
+ }
1306
+ function buildContainerHandler(config) {
1307
+ return (state, params) => {
1308
+ if (!params.content) {
1309
+ return false;
1310
+ }
1311
+ if (config.inlineContent && !params.inlineContent && config.inlineContent.required !== false) {
1312
+ return false;
1313
+ }
1314
+ if (!config.match(params, state)) {
1315
+ return false;
1316
+ }
1317
+ const { container, inlineContent, content, contentTokenizer } = config;
1318
+ let token = state.push(container.token + "_open", container.tag, 1);
1319
+ token.map = [params.startLine, params.endLine];
1320
+ token.markup = ":::" + config.name;
1321
+ applyTokenFields(token, container, params, state.env);
1322
+ if (inlineContent) {
1323
+ token = state.push(inlineContent.token + "_open", inlineContent.tag, 1);
1324
+ applyTokenFields(token, inlineContent, params, state.env);
1325
+ token = createBlockInlineToken(state, params);
1326
+ token = state.push(inlineContent.token + "_close", inlineContent.tag, -1);
1327
+ }
1328
+ if (content) {
1329
+ token = state.push(content.token + "_open", content.tag, 1);
1330
+ token.map = [params.startLine + 1, params.endLine - 1];
1331
+ applyTokenFields(token, content, params, state.env);
1332
+ }
1333
+ if (contentTokenizer) {
1334
+ contentTokenizer(state, params.content, params);
1335
+ } else {
1336
+ tokenizeBlockContent2(state, params.content, config.name + "-directive");
1337
+ }
1338
+ if (content) {
1339
+ token = state.push(content.token + "_close", content.tag, -1);
1340
+ }
1341
+ token = state.push(container.token + "_close", container.tag, -1);
1342
+ return true;
1343
+ };
1344
+ }
1345
+ function buildCodeContainerHandler(config) {
1346
+ return (state, params) => {
1347
+ if (!params.content) {
1348
+ return false;
1349
+ }
1350
+ if (!config.match(params, state)) {
1351
+ return false;
1352
+ }
1353
+ const { name, container } = config;
1354
+ const token = state.push(container.token, container.tag, 0);
1355
+ token.map = [params.startLine, params.endLine];
1356
+ token.content = params.content.raw;
1357
+ token.markup = ":::";
1358
+ token.info = name;
1359
+ applyTokenFields(token, container, params, state.env);
1360
+ return true;
1361
+ };
1362
+ }
1363
+ function buildInlineParams(args) {
1364
+ const params = {
1365
+ startPos: args.directiveStart,
1366
+ endPos: args.directiveEnd
1367
+ };
1368
+ if (args.attrs !== void 0) {
1369
+ params.attrs = args.attrs;
1370
+ }
1371
+ if (args.dests !== void 0) {
1372
+ params.dests = buildDests(args.dests);
1373
+ }
1374
+ if (args.content !== void 0) {
1375
+ params.content = {
1376
+ raw: args.content,
1377
+ startPos: args.contentStart,
1378
+ endPos: args.contentEnd
1379
+ };
1380
+ }
1381
+ return params;
1382
+ }
1383
+ function buildLeafBlockParams(args) {
1384
+ const params = {
1385
+ startLine: args.directiveStartLine,
1386
+ endLine: args.directiveEndLine
1387
+ };
1388
+ if (args.attrs !== void 0) {
1389
+ params.attrs = args.attrs;
1390
+ }
1391
+ if (args.dests !== void 0) {
1392
+ params.dests = buildDests(args.dests);
1393
+ }
1394
+ if (args.inlineContent !== void 0) {
1395
+ params.inlineContent = {
1396
+ raw: args.inlineContent,
1397
+ startPos: args.inlineContentStart,
1398
+ endPos: args.inlineContentEnd
1399
+ };
1400
+ }
1401
+ if (args.contentTitle) {
1402
+ params.contentTitle = {
1403
+ raw: args.contentTitle,
1404
+ startPos: args.contentTitleStart,
1405
+ endPos: args.contentTitleEnd
1406
+ };
1407
+ }
1408
+ return params;
1409
+ }
1410
+ function buildContainerParams(args) {
1411
+ const params = buildLeafBlockParams(args);
1412
+ return {
1413
+ ...params,
1414
+ content: {
1415
+ raw: args.content,
1416
+ startLine: args.contentStartLine,
1417
+ endLine: args.contentEndLine
1418
+ }
1419
+ };
1420
+ }
1421
+ function buildDests(orig) {
1422
+ var _a, _b;
1423
+ const dests = { _original_dests: orig };
1424
+ const link = (_a = orig.find((item) => item[0] === "link")) == null ? void 0 : _a[1];
1425
+ const string = (_b = orig.find((item) => item[0] === "string")) == null ? void 0 : _b[1];
1426
+ if (link !== void 0) {
1427
+ dests.link = link;
1428
+ }
1429
+ if (string !== void 0) {
1430
+ dests.string = string;
1431
+ }
1432
+ return dests;
1433
+ }
1434
+ function applyTokenFields(token, { attrs, meta }, params, env) {
1435
+ if (attrs !== void 0) {
1436
+ const value = isFunction(attrs) ? attrs(params, env) : attrs;
1437
+ token.attrs = Object.entries(value);
1438
+ }
1439
+ if (meta !== void 0) {
1440
+ const value = isFunction(meta) ? meta(params, env) : meta;
1441
+ token.meta = value;
1442
+ }
1443
+ }
1444
+ var BLOCK_LABELS_CONSTRAINED = /* @__PURE__ */ Symbol("block-labels-constrained");
1445
+ function lineEnd(src, start, fallback) {
1446
+ const lf = src.indexOf("\n", start);
1447
+ const cr = src.indexOf("\r", start);
1448
+ const ends = [lf, cr].filter((position) => position >= 0);
1449
+ return ends.length ? Math.min(...ends) : fallback;
1450
+ }
1451
+ function constrainBlockDirectiveLabels(md) {
1452
+ if (Reflect.get(md, BLOCK_LABELS_CONSTRAINED)) {
1453
+ return;
1454
+ }
1455
+ const rule = runtimeRules(md.block.ruler).find(({ name }) => name === "block_directive");
1456
+ if (!rule) {
1457
+ return;
1458
+ }
1459
+ const blockDirectiveRule = withBlockBoundary(rule.fn);
1460
+ if (!Reflect.set(md, BLOCK_LABELS_CONSTRAINED, true)) {
1461
+ throw new TypeError("Cannot mark directive block labels as constrained");
1462
+ }
1463
+ rule.fn = (state, startLine, endLine, silent) => {
1464
+ const parseLinkLabel = md.helpers.parseLinkLabel;
1465
+ md.helpers.parseLinkLabel = (inlineState, start, disableNested) => {
1466
+ if (inlineState.src.charCodeAt(start) !== 91) {
1467
+ return -1;
1468
+ }
1469
+ const posMax = inlineState.posMax;
1470
+ inlineState.posMax = Math.min(posMax, lineEnd(inlineState.src, start, posMax));
1471
+ try {
1472
+ return parseLinkLabel(inlineState, start, disableNested);
1473
+ } finally {
1474
+ inlineState.posMax = posMax;
1475
+ }
1476
+ };
1477
+ try {
1478
+ return blockDirectiveRule(state, startLine, endLine, silent);
1479
+ } finally {
1480
+ md.helpers.parseLinkLabel = parseLinkLabel;
1481
+ }
1482
+ };
1483
+ }
1484
+ var directiveParser2 = () => {
1485
+ return (md) => {
1486
+ Reflect.apply(import_markdown_it_directive.default, void 0, [md]);
1487
+ constrainBlockDirectiveLabels(md);
1488
+ };
1489
+ };
1490
+ }
1491
+ });
1492
+
585
1493
  // src/plugin/index-node.ts
586
1494
  var index_node_exports = {};
587
1495
  __export(index_node_exports, {
1496
+ recognizeTabsBoundary: () => recognizeTabsBoundary,
588
1497
  transform: () => transform2
589
1498
  });
590
1499
  module.exports = __toCommonJS(index_node_exports);
@@ -615,6 +1524,13 @@ var TABS_ACCORDION_CLASSNAME = "yfm-tabs-accordion";
615
1524
  var TABS_RADIO_CLASSNAME = "yfm-tabs-vertical";
616
1525
  var VERTICAL_TAB_CLASSNAME = "yfm-vertical-tab";
617
1526
  var TAB_DATA_VERTICAL_TAB = "data-diplodoc-vertical-tab";
1527
+ var TabsVariants = /* @__PURE__ */ ((TabsVariants2) => {
1528
+ TabsVariants2["Regular"] = "regular";
1529
+ TabsVariants2["Radio"] = "radio";
1530
+ TabsVariants2["Dropdown"] = "dropdown";
1531
+ TabsVariants2["Accordion"] = "accordion";
1532
+ return TabsVariants2;
1533
+ })(TabsVariants || {});
618
1534
 
619
1535
  // src/plugin/utils/strings.ts
620
1536
  function trim(target) {
@@ -662,8 +1578,14 @@ function createTabKey(value) {
662
1578
  // src/plugin/utils/tabs.ts
663
1579
  var CUSTOM_ID_REGEXP = /\[?{ ?#(\S+) ?}]?/;
664
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
+ }
665
1587
  function parseName(name) {
666
- const parts = name.match(CUSTOM_ID_REGEXP);
1588
+ const parts = findCustomAnchor(name);
667
1589
  let customAnchor = null;
668
1590
  let pure = name;
669
1591
  if (parts) {
@@ -673,7 +1595,7 @@ function parseName(name) {
673
1595
  pure = name;
674
1596
  customAnchor = null;
675
1597
  }
676
- if (pure.includes(ACTIVE_TAB_TEXT)) {
1598
+ if (findSelected(pure) !== -1) {
677
1599
  pure = pure.replace(ACTIVE_TAB_TEXT, "");
678
1600
  }
679
1601
  return {
@@ -691,7 +1613,30 @@ function getTabId(tab, { runId }) {
691
1613
  }
692
1614
  function isTabSelected(tab) {
693
1615
  const { name } = tab;
694
- return name.includes(ACTIVE_TAB_TEXT);
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 });
695
1640
  }
696
1641
  function getTabKey(tab) {
697
1642
  return createTabKey(getRawId(tab));
@@ -1161,6 +2106,9 @@ function matchOpenToken(tokens, i) {
1161
2106
  }
1162
2107
  return tokens[i + 1].content.match(TAB_RE);
1163
2108
  }
2109
+ function defaultTabsGroup(generateID) {
2110
+ return generateID(DEFAULT_TABS_GROUP_PREFIX.replace(/-$/, ""));
2111
+ }
1164
2112
  function props(content, generateID) {
1165
2113
  const clean = trim(content.replace("list tabs", ""));
1166
2114
  const props2 = clean.split(" ");
@@ -1170,10 +2118,9 @@ function props(content, generateID) {
1170
2118
  // DEFAULT_TABS_GROUP_PREFIX ends with '-', so strip it before passing to generateID
1171
2119
  // which appends '-N' itself. Result: 'defaultTabsGroup-1', 'defaultTabsGroup-2', …
1172
2120
  // TabsController checks group.startsWith(DEFAULT_TABS_GROUP_PREFIX) which still matches.
1173
- group: generateID(DEFAULT_TABS_GROUP_PREFIX.replace(/-$/, ""))
2121
+ group: defaultTabsGroup(generateID)
1174
2122
  };
1175
- for (const prop of props2) {
1176
- const [key, value] = prop.split("=").map(trim);
2123
+ visitProps(props2, (key, value) => {
1177
2124
  switch (key) {
1178
2125
  case "horizontal":
1179
2126
  case "radio":
@@ -1186,9 +2133,41 @@ function props(content, generateID) {
1186
2133
  break;
1187
2134
  default:
1188
2135
  }
1189
- }
2136
+ });
1190
2137
  return result;
1191
2138
  }
2139
+ function visitProps(parts, visit) {
2140
+ for (const prop of parts) {
2141
+ const pieces = prop.split("=").map(trim);
2142
+ visit(pieces[0], pieces[1], pieces);
2143
+ }
2144
+ }
2145
+ function recognizeTabsBoundary(tokens, i) {
2146
+ if (!tokens[i] || !tokens[i + 1]) return void 0;
2147
+ const match = matchOpenToken(tokens, i);
2148
+ const close = !match && matchCloseToken(tokens, i);
2149
+ if (!match && !close) return void 0;
2150
+ const map = tokens[i].map;
2151
+ const common = { map: map ? [map[0], map[1]] : null, raw: tokens[i + 1].content };
2152
+ if (close) return { kind: "close", ...common };
2153
+ if (!match || match[0].startsWith("`") && match[0].endsWith("`")) return void 0;
2154
+ if (tokens[i + 1].content.trim() !== match[0]) return { kind: "unsupported", ...common };
2155
+ let variant = { present: false };
2156
+ let group = { present: false };
2157
+ let unsupported = false;
2158
+ const parts = trim(match[0].replace("list tabs", "")).split(" ");
2159
+ visitProps(parts, (key, value, pieces) => {
2160
+ if ((!key || key === "{%" || key === "%}") && pieces.length === 1) return;
2161
+ if (["horizontal", "radio", "dropdown", "accordion"].includes(key) && pieces.length === 1 && !variant.present) {
2162
+ variant = { present: true, raw: key };
2163
+ } else if (key === "group" && pieces.length === 2 && value && !group.present) {
2164
+ group = { present: true, raw: value, value: unquote(value) };
2165
+ } else {
2166
+ unsupported = true;
2167
+ }
2168
+ });
2169
+ return unsupported ? { kind: "unsupported", ...common } : { kind: "open", ...common, variant, group };
2170
+ }
1192
2171
  function tryToFindTabs(tokens, index) {
1193
2172
  var _a;
1194
2173
  const match = matchOpenToken(tokens, index);
@@ -1234,7 +2213,7 @@ function tryToFindTabs(tokens, index) {
1234
2213
  extraTokensAfterClose
1235
2214
  };
1236
2215
  }
1237
- function findTabs(tokens, idx, closeTokenIdx, TokenConstructor) {
2216
+ function findTabs(tokens, idx, closeTokenIdx, TokenConstructor, end, titleTokens) {
1238
2217
  const tabs = [];
1239
2218
  let i = idx;
1240
2219
  let nestedLevel = -1;
@@ -1243,7 +2222,7 @@ function findTabs(tokens, idx, closeTokenIdx, TokenConstructor) {
1243
2222
  tokens: [],
1244
2223
  listItem: new TokenConstructor("list_item_open", "", 0)
1245
2224
  };
1246
- while (i < tokens.length) {
2225
+ while (i < end) {
1247
2226
  const token = tokens[i];
1248
2227
  switch (token.type) {
1249
2228
  case "ordered_list_open":
@@ -1283,6 +2262,7 @@ function findTabs(tokens, idx, closeTokenIdx, TokenConstructor) {
1283
2262
  }
1284
2263
  if (!pending.name && tokens[i + 1].type === "inline") {
1285
2264
  pending.name = tokens[i + 1].content;
2265
+ titleTokens == null ? void 0 : titleTokens.set(pending, tokens[i + 1]);
1286
2266
  i += 2;
1287
2267
  } else {
1288
2268
  pending.tokens.push(token);
@@ -1296,7 +2276,74 @@ function findTabs(tokens, idx, closeTokenIdx, TokenConstructor) {
1296
2276
  return tabs;
1297
2277
  }
1298
2278
 
2279
+ // src/plugin/directive.ts
2280
+ var import_directive = __toESM(require_build());
2281
+ var OPEN = "yfm_tabs_directive_open";
2282
+ var CLOSE = "yfm_tabs_directive_close";
2283
+ function parseParams(params) {
2284
+ var _a, _b;
2285
+ if (params.inlineContent || params.contentTitle || params.dests) {
2286
+ return { reason: "Tabs directives do not support a title or destination" };
2287
+ }
2288
+ const attrs = (_a = params.attrs) != null ? _a : {};
2289
+ for (const name of Object.keys(attrs)) {
2290
+ if (name !== "variant" && name !== "group")
2291
+ return { reason: `Unknown tabs attribute: ${name}` };
2292
+ if (Array.isArray(attrs[name])) return { reason: `Repeated tabs attribute: ${name}` };
2293
+ }
2294
+ const rawVariant = (_b = attrs.variant) != null ? _b : "regular" /* Regular */;
2295
+ const variant = Object.values(TabsVariants).find((candidate) => candidate === rawVariant);
2296
+ if (!variant) {
2297
+ return { reason: "Invalid tabs variant" };
2298
+ }
2299
+ const group = attrs.group;
2300
+ if (group !== void 0 && (typeof group !== "string" || !group.trim())) {
2301
+ return { reason: "Tabs group must be nonempty" };
2302
+ }
2303
+ return { variant, group };
2304
+ }
2305
+ function installTabsDirective(md, markers, onDiagnostic) {
2306
+ (0, import_directive.directiveParser)()(md);
2307
+ (0, import_directive.registerContainerDirective)(
2308
+ md,
2309
+ "tabs",
2310
+ (state, params) => {
2311
+ const parsed = parseParams(params);
2312
+ if ("reason" in parsed) {
2313
+ onDiagnostic == null ? void 0 : onDiagnostic({ line: params.startLine + 1, reason: parsed.reason });
2314
+ return false;
2315
+ }
2316
+ const open = state.push(OPEN, "", 0);
2317
+ open.map = [params.startLine, params.endLine];
2318
+ (0, import_directive.tokenizeBlockContent)(state, params.content, "tabs-directive");
2319
+ const close = state.push(CLOSE, "", 0);
2320
+ close.map = [params.endLine - 1, params.endLine];
2321
+ markers.set(open, { kind: "open", end: close, ...parsed });
2322
+ markers.set(close, { kind: "close" });
2323
+ return true;
2324
+ },
2325
+ { onConflict: "error" }
2326
+ );
2327
+ }
2328
+ function validateTabsMarkers(tokens, markers) {
2329
+ const expected = [];
2330
+ for (const token of tokens) {
2331
+ const marker = markers.get(token);
2332
+ if (!marker && (token.type === OPEN || token.type === CLOSE)) {
2333
+ throw new Error("Unowned tabs directive marker");
2334
+ }
2335
+ if ((marker == null ? void 0 : marker.kind) === "open") expected.push(marker.end);
2336
+ else if ((marker == null ? void 0 : marker.kind) === "close" && expected.pop() !== token) {
2337
+ throw new Error("Tabs directive opening marker is missing or crossed");
2338
+ }
2339
+ }
2340
+ if (expected.length) throw new Error("Tabs directive closing marker is missing");
2341
+ }
2342
+
1299
2343
  // src/plugin/transform.ts
2344
+ function copyMap(map) {
2345
+ return map ? Object.freeze([map[0], map[1]]) : null;
2346
+ }
1300
2347
  var defaultFeatures = {
1301
2348
  enabledVariants: {
1302
2349
  regular: true,
@@ -1317,6 +2364,36 @@ function appendRuntimeMeta(env, runtimeJsPath, runtimeCssPath) {
1317
2364
  meta.script.push(runtimeJsPath);
1318
2365
  meta.style.push(runtimeCssPath);
1319
2366
  }
2367
+ function matchTabs(tokens, start, markers, legacy, generateID) {
2368
+ var _a;
2369
+ const marker = markers.get(tokens[start]);
2370
+ if ((marker == null ? void 0 : marker.kind) === "close") throw new Error("Unexpected tabs directive closing marker");
2371
+ if (marker) {
2372
+ const close = tokens.findIndex((token, index) => index > start && token === marker.end);
2373
+ if (close < 0) throw new Error("Tabs directive closing marker is missing");
2374
+ const defaultGroup = defaultTabsGroup(generateID);
2375
+ return {
2376
+ close,
2377
+ bodyStart: start + 1,
2378
+ removeCount: close - start + 1,
2379
+ end: close,
2380
+ variant: marker.variant,
2381
+ group: (_a = marker.group) != null ? _a : defaultGroup
2382
+ };
2383
+ }
2384
+ if (!legacy) return { step: 1 };
2385
+ const result = tryToFindTabs(tokens, start);
2386
+ if ("step" in result) return result;
2387
+ const parsed = props(result.content, generateID);
2388
+ return {
2389
+ close: result.closeTokenIndex,
2390
+ bodyStart: start + 3,
2391
+ removeCount: result.closeTokenIndex - start + 3 + result.extraTokensAfterClose,
2392
+ end: tokens.length,
2393
+ variant: parsed.variant,
2394
+ group: parsed.group
2395
+ };
2396
+ }
1320
2397
  function transform(options = {}) {
1321
2398
  const {
1322
2399
  runtimeJsPath = "_assets/tabs-extension.js",
@@ -1324,46 +2401,67 @@ function transform(options = {}) {
1324
2401
  containerClasses = "",
1325
2402
  bundle = true,
1326
2403
  features = defaultFeatures,
1327
- onBundle: onBundle2
2404
+ onBundle: onBundle2,
2405
+ directiveSyntax = "disabled",
2406
+ onDiagnostic,
2407
+ onItemSource
1328
2408
  } = options;
1329
- return function tabs(md, options2) {
2409
+ function installCore(md, options2, markers, legacy) {
1330
2410
  const { output = ".", generateID: externalGenerateID } = options2 || {};
1331
2411
  const generateID = externalGenerateID != null ? externalGenerateID : (0, import_utils6.createIDGeneratorByStrategy)("random");
1332
2412
  const plugin = (state) => {
1333
2413
  const { tokens } = state;
2414
+ validateTabsMarkers(tokens, markers);
1334
2415
  const env = addHiddenProperty(state.env, "bundled", /* @__PURE__ */ new Set());
1335
2416
  const runId = String(++runsCounter);
1336
2417
  let i = 0;
1337
2418
  let tabsAreInserted = false;
1338
2419
  while (i < tokens.length) {
1339
- const result = tryToFindTabs(tokens, i);
1340
- if ("step" in result) {
1341
- i += result.step;
2420
+ const match = matchTabs(tokens, i, markers, legacy, generateID);
2421
+ if ("step" in match) {
2422
+ i += match.step;
1342
2423
  continue;
1343
2424
  }
1344
- const { content, closeTokenIndex, extraTokensAfterClose } = result;
1345
- const parsedProps = props(content, generateID);
1346
- if (!features.enabledVariants[parsedProps.variant]) {
1347
- parsedProps.variant = "regular" /* Regular */;
1348
- }
1349
- const tabs2 = findTabs(state.tokens, i + 3, closeTokenIndex, state.Token);
1350
- if (tabs2.length > 0) {
1351
- const tabsTokens = generateTabsTokens(tabs2, state, {
2425
+ const variant = features.enabledVariants[match.variant] ? match.variant : "regular" /* Regular */;
2426
+ const titleTokens = onItemSource ? /* @__PURE__ */ new WeakMap() : void 0;
2427
+ const tabs = findTabs(
2428
+ state.tokens,
2429
+ match.bodyStart,
2430
+ match.close,
2431
+ state.Token,
2432
+ match.end,
2433
+ titleTokens
2434
+ );
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
+ }
2453
+ const tabsTokens = generateTabsTokens(tabs, state, {
1352
2454
  containerClasses,
1353
- tabsGroup: parsedProps.group,
1354
- variant: parsedProps.variant,
2455
+ tabsGroup: match.group,
2456
+ variant,
1355
2457
  runId,
1356
2458
  generateID
1357
2459
  });
1358
- state.tokens.splice(
1359
- i,
1360
- closeTokenIndex - i + 3 + extraTokensAfterClose,
1361
- ...tabsTokens
1362
- );
2460
+ state.tokens.splice(i, match.removeCount, ...tabsTokens);
1363
2461
  i++;
1364
2462
  tabsAreInserted = true;
1365
2463
  } else {
1366
- state.tokens.splice(i, closeTokenIndex - i + 3 + extraTokensAfterClose);
2464
+ state.tokens.splice(i, match.removeCount);
1367
2465
  }
1368
2466
  }
1369
2467
  if (tabsAreInserted) {
@@ -1378,7 +2476,16 @@ function transform(options = {}) {
1378
2476
  } catch {
1379
2477
  md.core.ruler.push("tabs", plugin);
1380
2478
  }
1381
- };
2479
+ }
2480
+ function legacyPlugin(md, settings) {
2481
+ installCore(md, settings, /* @__PURE__ */ new WeakMap(), true);
2482
+ }
2483
+ function directivePlugin(md, settings) {
2484
+ const markers = /* @__PURE__ */ new WeakMap();
2485
+ installTabsDirective(md, markers, onDiagnostic);
2486
+ installCore(md, settings, markers, directiveSyntax === "enabled");
2487
+ }
2488
+ return directiveSyntax === "disabled" ? legacyPlugin : directivePlugin;
1382
2489
  }
1383
2490
 
1384
2491
  // src/plugin/index-node.ts
@@ -1386,7 +2493,18 @@ var onBundle = (args, cache) => {
1386
2493
  copyRuntimeFiles(args, cache);
1387
2494
  };
1388
2495
  function transform2(options = {}) {
1389
- return transform({ onBundle, ...options });
2496
+ if (!options.directiveSyntax || options.directiveSyntax === "disabled") {
2497
+ return transform({
2498
+ onBundle,
2499
+ ...options,
2500
+ directiveSyntax: "disabled"
2501
+ });
2502
+ }
2503
+ return transform({
2504
+ onBundle,
2505
+ ...options,
2506
+ directiveSyntax: options.directiveSyntax
2507
+ });
1390
2508
  }
1391
2509
  var PATH_TO_RUNTIME = "../runtime";
1392
2510
  function copyRuntimeFiles({
@@ -1415,6 +2533,34 @@ function copyFile(from, to) {
1415
2533
  }
1416
2534
  // Annotate the CommonJS export names for ESM import in node:
1417
2535
  0 && (module.exports = {
2536
+ recognizeTabsBoundary,
1418
2537
  transform
1419
2538
  });
2539
+ /*! Bundled license information:
2540
+
2541
+ @diplodoc/directive/build/index.js:
2542
+ (*!
2543
+ MIT License
2544
+
2545
+ Copyright (c) 2020 lookas
2546
+
2547
+ Permission is hereby granted, free of charge, to any person obtaining a copy
2548
+ of this software and associated documentation files (the "Software"), to deal
2549
+ in the Software without restriction, including without limitation the rights
2550
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2551
+ copies of the Software, and to permit persons to whom the Software is
2552
+ furnished to do so, subject to the following conditions:
2553
+
2554
+ The above copyright notice and this permission notice shall be included in all
2555
+ copies or substantial portions of the Software.
2556
+
2557
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2558
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2559
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2560
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2561
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2562
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2563
+ SOFTWARE.
2564
+ *)
2565
+ */
1420
2566
  //# sourceMappingURL=index-node.js.map