@diplodoc/tabs-extension 3.10.8-transform5.3 → 4.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/build/plugin/find.d.ts +2 -1
- package/build/plugin/index-node.js +60 -942
- package/build/plugin/index-node.js.map +4 -4
- package/build/plugin/index.d.ts +2 -1
- package/build/plugin/index.js +60 -942
- package/build/plugin/index.js.map +4 -4
- package/build/plugin/transform.d.ts +16 -0
- package/build/plugin/utils/tabs.d.ts +18 -0
- package/build/runtime/index.js +1 -1
- package/package.json +7 -3
package/build/plugin/index.js
CHANGED
|
@@ -582,914 +582,6 @@ 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_exports2 = {};
|
|
949
|
-
__export2(index_exports2, {
|
|
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_exports2);
|
|
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
|
-
|
|
1493
585
|
// src/plugin/index.ts
|
|
1494
586
|
var index_exports = {};
|
|
1495
587
|
__export(index_exports, {
|
|
@@ -1578,8 +670,14 @@ function createTabKey(value) {
|
|
|
1578
670
|
// src/plugin/utils/tabs.ts
|
|
1579
671
|
var CUSTOM_ID_REGEXP = /\[?{ ?#(\S+) ?}]?/;
|
|
1580
672
|
var sluggersStorage = /* @__PURE__ */ new Map();
|
|
673
|
+
function findCustomAnchor(name) {
|
|
674
|
+
return name.match(CUSTOM_ID_REGEXP);
|
|
675
|
+
}
|
|
676
|
+
function findSelected(name) {
|
|
677
|
+
return name.indexOf(ACTIVE_TAB_TEXT);
|
|
678
|
+
}
|
|
1581
679
|
function parseName(name) {
|
|
1582
|
-
const parts = name
|
|
680
|
+
const parts = findCustomAnchor(name);
|
|
1583
681
|
let customAnchor = null;
|
|
1584
682
|
let pure = name;
|
|
1585
683
|
if (parts) {
|
|
@@ -1589,7 +687,7 @@ function parseName(name) {
|
|
|
1589
687
|
pure = name;
|
|
1590
688
|
customAnchor = null;
|
|
1591
689
|
}
|
|
1592
|
-
if (pure
|
|
690
|
+
if (findSelected(pure) !== -1) {
|
|
1593
691
|
pure = pure.replace(ACTIVE_TAB_TEXT, "");
|
|
1594
692
|
}
|
|
1595
693
|
return {
|
|
@@ -1607,7 +705,30 @@ function getTabId(tab, { runId }) {
|
|
|
1607
705
|
}
|
|
1608
706
|
function isTabSelected(tab) {
|
|
1609
707
|
const { name } = tab;
|
|
1610
|
-
return name
|
|
708
|
+
return findSelected(name) !== -1;
|
|
709
|
+
}
|
|
710
|
+
function span(start, end) {
|
|
711
|
+
return Object.freeze([start, end]);
|
|
712
|
+
}
|
|
713
|
+
function observeTabName(name) {
|
|
714
|
+
var _a;
|
|
715
|
+
const anchor = findCustomAnchor(name);
|
|
716
|
+
const anchorStart = (_a = anchor == null ? void 0 : anchor.index) != null ? _a : -1;
|
|
717
|
+
const anchorEnd = anchor ? anchorStart + anchor[0].length : -1;
|
|
718
|
+
const withoutAnchor = anchor ? name.slice(0, anchorStart) + name.slice(anchorEnd) : name;
|
|
719
|
+
const active = findSelected(name);
|
|
720
|
+
const display = findSelected(withoutAnchor);
|
|
721
|
+
const length = ACTIVE_TAB_TEXT.length;
|
|
722
|
+
if (anchor && display !== -1 && display < anchorStart && display + length > anchorStart) {
|
|
723
|
+
return Object.freeze({ kind: "unsupported", reason: "discontinuous-display-marker" });
|
|
724
|
+
}
|
|
725
|
+
const displayStart = anchor && display >= anchorStart ? display + anchor[0].length : display;
|
|
726
|
+
const markers = Object.freeze({
|
|
727
|
+
customAnchor: anchor ? span(anchorStart, anchorEnd) : null,
|
|
728
|
+
selectedForActivation: active === -1 ? null : span(active, active + length),
|
|
729
|
+
selectedForDisplay: display === -1 ? null : span(displayStart, displayStart + length)
|
|
730
|
+
});
|
|
731
|
+
return Object.freeze({ kind: "ok", markers });
|
|
1611
732
|
}
|
|
1612
733
|
function getTabKey(tab) {
|
|
1613
734
|
return createTabKey(getRawId(tab));
|
|
@@ -2184,7 +1305,7 @@ function tryToFindTabs(tokens, index) {
|
|
|
2184
1305
|
extraTokensAfterClose
|
|
2185
1306
|
};
|
|
2186
1307
|
}
|
|
2187
|
-
function findTabs(tokens, idx, closeTokenIdx, TokenConstructor, end) {
|
|
1308
|
+
function findTabs(tokens, idx, closeTokenIdx, TokenConstructor, end, titleTokens) {
|
|
2188
1309
|
const tabs = [];
|
|
2189
1310
|
let i = idx;
|
|
2190
1311
|
let nestedLevel = -1;
|
|
@@ -2233,6 +1354,7 @@ function findTabs(tokens, idx, closeTokenIdx, TokenConstructor, end) {
|
|
|
2233
1354
|
}
|
|
2234
1355
|
if (!pending.name && tokens[i + 1].type === "inline") {
|
|
2235
1356
|
pending.name = tokens[i + 1].content;
|
|
1357
|
+
titleTokens == null ? void 0 : titleTokens.set(pending, tokens[i + 1]);
|
|
2236
1358
|
i += 2;
|
|
2237
1359
|
} else {
|
|
2238
1360
|
pending.tokens.push(token);
|
|
@@ -2247,7 +1369,7 @@ function findTabs(tokens, idx, closeTokenIdx, TokenConstructor, end) {
|
|
|
2247
1369
|
}
|
|
2248
1370
|
|
|
2249
1371
|
// src/plugin/directive.ts
|
|
2250
|
-
var import_directive =
|
|
1372
|
+
var import_directive = require("@diplodoc/directive");
|
|
2251
1373
|
var OPEN = "yfm_tabs_directive_open";
|
|
2252
1374
|
var CLOSE = "yfm_tabs_directive_close";
|
|
2253
1375
|
function parseParams(params) {
|
|
@@ -2311,6 +1433,9 @@ function validateTabsMarkers(tokens, markers) {
|
|
|
2311
1433
|
}
|
|
2312
1434
|
|
|
2313
1435
|
// src/plugin/transform.ts
|
|
1436
|
+
function copyMap(map) {
|
|
1437
|
+
return map ? Object.freeze([map[0], map[1]]) : null;
|
|
1438
|
+
}
|
|
2314
1439
|
var defaultFeatures = {
|
|
2315
1440
|
enabledVariants: {
|
|
2316
1441
|
regular: true,
|
|
@@ -2370,7 +1495,8 @@ function transform(options = {}) {
|
|
|
2370
1495
|
features = defaultFeatures,
|
|
2371
1496
|
onBundle,
|
|
2372
1497
|
directiveSyntax = "disabled",
|
|
2373
|
-
onDiagnostic
|
|
1498
|
+
onDiagnostic,
|
|
1499
|
+
onItemSource
|
|
2374
1500
|
} = options;
|
|
2375
1501
|
function installCore(md, options2, markers, legacy) {
|
|
2376
1502
|
const { output = ".", generateID: externalGenerateID } = options2 || {};
|
|
@@ -2389,14 +1515,33 @@ function transform(options = {}) {
|
|
|
2389
1515
|
continue;
|
|
2390
1516
|
}
|
|
2391
1517
|
const variant = features.enabledVariants[match.variant] ? match.variant : "regular" /* Regular */;
|
|
1518
|
+
const titleTokens = onItemSource ? /* @__PURE__ */ new WeakMap() : void 0;
|
|
2392
1519
|
const tabs = findTabs(
|
|
2393
1520
|
state.tokens,
|
|
2394
1521
|
match.bodyStart,
|
|
2395
1522
|
match.close,
|
|
2396
1523
|
state.Token,
|
|
2397
|
-
match.end
|
|
1524
|
+
match.end,
|
|
1525
|
+
titleTokens
|
|
2398
1526
|
);
|
|
2399
1527
|
if (tabs.length > 0) {
|
|
1528
|
+
if (onItemSource && titleTokens) {
|
|
1529
|
+
const openMap = tokens[i].map;
|
|
1530
|
+
const closeMap = tokens[match.close].map;
|
|
1531
|
+
const containerMap = openMap && closeMap && openMap[0] <= closeMap[1] ? copyMap([openMap[0], closeMap[1]]) : null;
|
|
1532
|
+
for (const tab of tabs) {
|
|
1533
|
+
const title = titleTokens.get(tab);
|
|
1534
|
+
const source = title ? observeTabName(tab.name) : { kind: "unsupported", reason: "missing-title" };
|
|
1535
|
+
onItemSource(
|
|
1536
|
+
Object.freeze({
|
|
1537
|
+
rawName: tab.name,
|
|
1538
|
+
inlineMap: title ? copyMap(title.map) : null,
|
|
1539
|
+
containerMap,
|
|
1540
|
+
...source
|
|
1541
|
+
})
|
|
1542
|
+
);
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
2400
1545
|
const tabsTokens = generateTabsTokens(tabs, state, {
|
|
2401
1546
|
containerClasses,
|
|
2402
1547
|
tabsGroup: match.group,
|
|
@@ -2439,31 +1584,4 @@ function transform(options = {}) {
|
|
|
2439
1584
|
recognizeTabsBoundary,
|
|
2440
1585
|
transform
|
|
2441
1586
|
});
|
|
2442
|
-
/*! Bundled license information:
|
|
2443
|
-
|
|
2444
|
-
@diplodoc/directive/build/index.js:
|
|
2445
|
-
(*!
|
|
2446
|
-
MIT License
|
|
2447
|
-
|
|
2448
|
-
Copyright (c) 2020 lookas
|
|
2449
|
-
|
|
2450
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
2451
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
2452
|
-
in the Software without restriction, including without limitation the rights
|
|
2453
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
2454
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
2455
|
-
furnished to do so, subject to the following conditions:
|
|
2456
|
-
|
|
2457
|
-
The above copyright notice and this permission notice shall be included in all
|
|
2458
|
-
copies or substantial portions of the Software.
|
|
2459
|
-
|
|
2460
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
2461
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
2462
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
2463
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
2464
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
2465
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
2466
|
-
SOFTWARE.
|
|
2467
|
-
*)
|
|
2468
|
-
*/
|
|
2469
1587
|
//# sourceMappingURL=index.js.map
|