@diplodoc/tabs-extension 3.10.8-transform5.2 → 3.10.8-transform5.3

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) {
@@ -1161,6 +2077,9 @@ function matchOpenToken(tokens, i) {
1161
2077
  }
1162
2078
  return tokens[i + 1].content.match(TAB_RE);
1163
2079
  }
2080
+ function defaultTabsGroup(generateID) {
2081
+ return generateID(DEFAULT_TABS_GROUP_PREFIX.replace(/-$/, ""));
2082
+ }
1164
2083
  function props(content, generateID) {
1165
2084
  const clean = trim(content.replace("list tabs", ""));
1166
2085
  const props2 = clean.split(" ");
@@ -1170,10 +2089,9 @@ function props(content, generateID) {
1170
2089
  // DEFAULT_TABS_GROUP_PREFIX ends with '-', so strip it before passing to generateID
1171
2090
  // which appends '-N' itself. Result: 'defaultTabsGroup-1', 'defaultTabsGroup-2', …
1172
2091
  // TabsController checks group.startsWith(DEFAULT_TABS_GROUP_PREFIX) which still matches.
1173
- group: generateID(DEFAULT_TABS_GROUP_PREFIX.replace(/-$/, ""))
2092
+ group: defaultTabsGroup(generateID)
1174
2093
  };
1175
- for (const prop of props2) {
1176
- const [key, value] = prop.split("=").map(trim);
2094
+ visitProps(props2, (key, value) => {
1177
2095
  switch (key) {
1178
2096
  case "horizontal":
1179
2097
  case "radio":
@@ -1186,9 +2104,41 @@ function props(content, generateID) {
1186
2104
  break;
1187
2105
  default:
1188
2106
  }
1189
- }
2107
+ });
1190
2108
  return result;
1191
2109
  }
2110
+ function visitProps(parts, visit) {
2111
+ for (const prop of parts) {
2112
+ const pieces = prop.split("=").map(trim);
2113
+ visit(pieces[0], pieces[1], pieces);
2114
+ }
2115
+ }
2116
+ function recognizeTabsBoundary(tokens, i) {
2117
+ if (!tokens[i] || !tokens[i + 1]) return void 0;
2118
+ const match = matchOpenToken(tokens, i);
2119
+ const close = !match && matchCloseToken(tokens, i);
2120
+ if (!match && !close) return void 0;
2121
+ const map = tokens[i].map;
2122
+ const common = { map: map ? [map[0], map[1]] : null, raw: tokens[i + 1].content };
2123
+ if (close) return { kind: "close", ...common };
2124
+ if (!match || match[0].startsWith("`") && match[0].endsWith("`")) return void 0;
2125
+ if (tokens[i + 1].content.trim() !== match[0]) return { kind: "unsupported", ...common };
2126
+ let variant = { present: false };
2127
+ let group = { present: false };
2128
+ let unsupported = false;
2129
+ const parts = trim(match[0].replace("list tabs", "")).split(" ");
2130
+ visitProps(parts, (key, value, pieces) => {
2131
+ if ((!key || key === "{%" || key === "%}") && pieces.length === 1) return;
2132
+ if (["horizontal", "radio", "dropdown", "accordion"].includes(key) && pieces.length === 1 && !variant.present) {
2133
+ variant = { present: true, raw: key };
2134
+ } else if (key === "group" && pieces.length === 2 && value && !group.present) {
2135
+ group = { present: true, raw: value, value: unquote(value) };
2136
+ } else {
2137
+ unsupported = true;
2138
+ }
2139
+ });
2140
+ return unsupported ? { kind: "unsupported", ...common } : { kind: "open", ...common, variant, group };
2141
+ }
1192
2142
  function tryToFindTabs(tokens, index) {
1193
2143
  var _a;
1194
2144
  const match = matchOpenToken(tokens, index);
@@ -1234,7 +2184,7 @@ function tryToFindTabs(tokens, index) {
1234
2184
  extraTokensAfterClose
1235
2185
  };
1236
2186
  }
1237
- function findTabs(tokens, idx, closeTokenIdx, TokenConstructor) {
2187
+ function findTabs(tokens, idx, closeTokenIdx, TokenConstructor, end) {
1238
2188
  const tabs = [];
1239
2189
  let i = idx;
1240
2190
  let nestedLevel = -1;
@@ -1243,7 +2193,7 @@ function findTabs(tokens, idx, closeTokenIdx, TokenConstructor) {
1243
2193
  tokens: [],
1244
2194
  listItem: new TokenConstructor("list_item_open", "", 0)
1245
2195
  };
1246
- while (i < tokens.length) {
2196
+ while (i < end) {
1247
2197
  const token = tokens[i];
1248
2198
  switch (token.type) {
1249
2199
  case "ordered_list_open":
@@ -1296,6 +2246,70 @@ function findTabs(tokens, idx, closeTokenIdx, TokenConstructor) {
1296
2246
  return tabs;
1297
2247
  }
1298
2248
 
2249
+ // src/plugin/directive.ts
2250
+ var import_directive = __toESM(require_build());
2251
+ var OPEN = "yfm_tabs_directive_open";
2252
+ var CLOSE = "yfm_tabs_directive_close";
2253
+ function parseParams(params) {
2254
+ var _a, _b;
2255
+ if (params.inlineContent || params.contentTitle || params.dests) {
2256
+ return { reason: "Tabs directives do not support a title or destination" };
2257
+ }
2258
+ const attrs = (_a = params.attrs) != null ? _a : {};
2259
+ for (const name of Object.keys(attrs)) {
2260
+ if (name !== "variant" && name !== "group")
2261
+ return { reason: `Unknown tabs attribute: ${name}` };
2262
+ if (Array.isArray(attrs[name])) return { reason: `Repeated tabs attribute: ${name}` };
2263
+ }
2264
+ const rawVariant = (_b = attrs.variant) != null ? _b : "regular" /* Regular */;
2265
+ const variant = Object.values(TabsVariants).find((candidate) => candidate === rawVariant);
2266
+ if (!variant) {
2267
+ return { reason: "Invalid tabs variant" };
2268
+ }
2269
+ const group = attrs.group;
2270
+ if (group !== void 0 && (typeof group !== "string" || !group.trim())) {
2271
+ return { reason: "Tabs group must be nonempty" };
2272
+ }
2273
+ return { variant, group };
2274
+ }
2275
+ function installTabsDirective(md, markers, onDiagnostic) {
2276
+ (0, import_directive.directiveParser)()(md);
2277
+ (0, import_directive.registerContainerDirective)(
2278
+ md,
2279
+ "tabs",
2280
+ (state, params) => {
2281
+ const parsed = parseParams(params);
2282
+ if ("reason" in parsed) {
2283
+ onDiagnostic == null ? void 0 : onDiagnostic({ line: params.startLine + 1, reason: parsed.reason });
2284
+ return false;
2285
+ }
2286
+ const open = state.push(OPEN, "", 0);
2287
+ open.map = [params.startLine, params.endLine];
2288
+ (0, import_directive.tokenizeBlockContent)(state, params.content, "tabs-directive");
2289
+ const close = state.push(CLOSE, "", 0);
2290
+ close.map = [params.endLine - 1, params.endLine];
2291
+ markers.set(open, { kind: "open", end: close, ...parsed });
2292
+ markers.set(close, { kind: "close" });
2293
+ return true;
2294
+ },
2295
+ { onConflict: "error" }
2296
+ );
2297
+ }
2298
+ function validateTabsMarkers(tokens, markers) {
2299
+ const expected = [];
2300
+ for (const token of tokens) {
2301
+ const marker = markers.get(token);
2302
+ if (!marker && (token.type === OPEN || token.type === CLOSE)) {
2303
+ throw new Error("Unowned tabs directive marker");
2304
+ }
2305
+ if ((marker == null ? void 0 : marker.kind) === "open") expected.push(marker.end);
2306
+ else if ((marker == null ? void 0 : marker.kind) === "close" && expected.pop() !== token) {
2307
+ throw new Error("Tabs directive opening marker is missing or crossed");
2308
+ }
2309
+ }
2310
+ if (expected.length) throw new Error("Tabs directive closing marker is missing");
2311
+ }
2312
+
1299
2313
  // src/plugin/transform.ts
1300
2314
  var defaultFeatures = {
1301
2315
  enabledVariants: {
@@ -1317,6 +2331,36 @@ function appendRuntimeMeta(env, runtimeJsPath, runtimeCssPath) {
1317
2331
  meta.script.push(runtimeJsPath);
1318
2332
  meta.style.push(runtimeCssPath);
1319
2333
  }
2334
+ function matchTabs(tokens, start, markers, legacy, generateID) {
2335
+ var _a;
2336
+ const marker = markers.get(tokens[start]);
2337
+ if ((marker == null ? void 0 : marker.kind) === "close") throw new Error("Unexpected tabs directive closing marker");
2338
+ if (marker) {
2339
+ const close = tokens.findIndex((token, index) => index > start && token === marker.end);
2340
+ if (close < 0) throw new Error("Tabs directive closing marker is missing");
2341
+ const defaultGroup = defaultTabsGroup(generateID);
2342
+ return {
2343
+ close,
2344
+ bodyStart: start + 1,
2345
+ removeCount: close - start + 1,
2346
+ end: close,
2347
+ variant: marker.variant,
2348
+ group: (_a = marker.group) != null ? _a : defaultGroup
2349
+ };
2350
+ }
2351
+ if (!legacy) return { step: 1 };
2352
+ const result = tryToFindTabs(tokens, start);
2353
+ if ("step" in result) return result;
2354
+ const parsed = props(result.content, generateID);
2355
+ return {
2356
+ close: result.closeTokenIndex,
2357
+ bodyStart: start + 3,
2358
+ removeCount: result.closeTokenIndex - start + 3 + result.extraTokensAfterClose,
2359
+ end: tokens.length,
2360
+ variant: parsed.variant,
2361
+ group: parsed.group
2362
+ };
2363
+ }
1320
2364
  function transform(options = {}) {
1321
2365
  const {
1322
2366
  runtimeJsPath = "_assets/tabs-extension.js",
@@ -1324,46 +2368,47 @@ function transform(options = {}) {
1324
2368
  containerClasses = "",
1325
2369
  bundle = true,
1326
2370
  features = defaultFeatures,
1327
- onBundle: onBundle2
2371
+ onBundle: onBundle2,
2372
+ directiveSyntax = "disabled",
2373
+ onDiagnostic
1328
2374
  } = options;
1329
- return function tabs(md, options2) {
2375
+ function installCore(md, options2, markers, legacy) {
1330
2376
  const { output = ".", generateID: externalGenerateID } = options2 || {};
1331
2377
  const generateID = externalGenerateID != null ? externalGenerateID : (0, import_utils6.createIDGeneratorByStrategy)("random");
1332
2378
  const plugin = (state) => {
1333
2379
  const { tokens } = state;
2380
+ validateTabsMarkers(tokens, markers);
1334
2381
  const env = addHiddenProperty(state.env, "bundled", /* @__PURE__ */ new Set());
1335
2382
  const runId = String(++runsCounter);
1336
2383
  let i = 0;
1337
2384
  let tabsAreInserted = false;
1338
2385
  while (i < tokens.length) {
1339
- const result = tryToFindTabs(tokens, i);
1340
- if ("step" in result) {
1341
- i += result.step;
2386
+ const match = matchTabs(tokens, i, markers, legacy, generateID);
2387
+ if ("step" in match) {
2388
+ i += match.step;
1342
2389
  continue;
1343
2390
  }
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, {
2391
+ const variant = features.enabledVariants[match.variant] ? match.variant : "regular" /* Regular */;
2392
+ const tabs = findTabs(
2393
+ state.tokens,
2394
+ match.bodyStart,
2395
+ match.close,
2396
+ state.Token,
2397
+ match.end
2398
+ );
2399
+ if (tabs.length > 0) {
2400
+ const tabsTokens = generateTabsTokens(tabs, state, {
1352
2401
  containerClasses,
1353
- tabsGroup: parsedProps.group,
1354
- variant: parsedProps.variant,
2402
+ tabsGroup: match.group,
2403
+ variant,
1355
2404
  runId,
1356
2405
  generateID
1357
2406
  });
1358
- state.tokens.splice(
1359
- i,
1360
- closeTokenIndex - i + 3 + extraTokensAfterClose,
1361
- ...tabsTokens
1362
- );
2407
+ state.tokens.splice(i, match.removeCount, ...tabsTokens);
1363
2408
  i++;
1364
2409
  tabsAreInserted = true;
1365
2410
  } else {
1366
- state.tokens.splice(i, closeTokenIndex - i + 3 + extraTokensAfterClose);
2411
+ state.tokens.splice(i, match.removeCount);
1367
2412
  }
1368
2413
  }
1369
2414
  if (tabsAreInserted) {
@@ -1378,7 +2423,16 @@ function transform(options = {}) {
1378
2423
  } catch {
1379
2424
  md.core.ruler.push("tabs", plugin);
1380
2425
  }
1381
- };
2426
+ }
2427
+ function legacyPlugin(md, settings) {
2428
+ installCore(md, settings, /* @__PURE__ */ new WeakMap(), true);
2429
+ }
2430
+ function directivePlugin(md, settings) {
2431
+ const markers = /* @__PURE__ */ new WeakMap();
2432
+ installTabsDirective(md, markers, onDiagnostic);
2433
+ installCore(md, settings, markers, directiveSyntax === "enabled");
2434
+ }
2435
+ return directiveSyntax === "disabled" ? legacyPlugin : directivePlugin;
1382
2436
  }
1383
2437
 
1384
2438
  // src/plugin/index-node.ts
@@ -1386,7 +2440,18 @@ var onBundle = (args, cache) => {
1386
2440
  copyRuntimeFiles(args, cache);
1387
2441
  };
1388
2442
  function transform2(options = {}) {
1389
- return transform({ onBundle, ...options });
2443
+ if (!options.directiveSyntax || options.directiveSyntax === "disabled") {
2444
+ return transform({
2445
+ onBundle,
2446
+ ...options,
2447
+ directiveSyntax: "disabled"
2448
+ });
2449
+ }
2450
+ return transform({
2451
+ onBundle,
2452
+ ...options,
2453
+ directiveSyntax: options.directiveSyntax
2454
+ });
1390
2455
  }
1391
2456
  var PATH_TO_RUNTIME = "../runtime";
1392
2457
  function copyRuntimeFiles({
@@ -1415,6 +2480,34 @@ function copyFile(from, to) {
1415
2480
  }
1416
2481
  // Annotate the CommonJS export names for ESM import in node:
1417
2482
  0 && (module.exports = {
2483
+ recognizeTabsBoundary,
1418
2484
  transform
1419
2485
  });
2486
+ /*! Bundled license information:
2487
+
2488
+ @diplodoc/directive/build/index.js:
2489
+ (*!
2490
+ MIT License
2491
+
2492
+ Copyright (c) 2020 lookas
2493
+
2494
+ Permission is hereby granted, free of charge, to any person obtaining a copy
2495
+ of this software and associated documentation files (the "Software"), to deal
2496
+ in the Software without restriction, including without limitation the rights
2497
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2498
+ copies of the Software, and to permit persons to whom the Software is
2499
+ furnished to do so, subject to the following conditions:
2500
+
2501
+ The above copyright notice and this permission notice shall be included in all
2502
+ copies or substantial portions of the Software.
2503
+
2504
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2505
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2506
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2507
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2508
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2509
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2510
+ SOFTWARE.
2511
+ *)
2512
+ */
1420
2513
  //# sourceMappingURL=index-node.js.map