@luckyfishes/markdown-core 0.2.0 → 0.2.2
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/dist/index.cjs +71 -2
- package/dist/index.js +71 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -701,6 +701,62 @@ var legacyGuardBlockHandler = {
|
|
|
701
701
|
|
|
702
702
|
// src/remark/custom-syntax/handlers/tabs-block.ts
|
|
703
703
|
var TABS_START_RE = /^::tabs\s*$/i;
|
|
704
|
+
var FOOTNOTE_REF_PLACEHOLDER_RE = /@@MARKDOWN_CORE_FOOTNOTE_REF:([^@\s]+)@@/g;
|
|
705
|
+
function protectFootnoteReferences(markdown) {
|
|
706
|
+
return markdown.replace(/\[\^([^\]\s]+)\](?!:)/g, (_, identifier) => {
|
|
707
|
+
return `@@MARKDOWN_CORE_FOOTNOTE_REF:${identifier}@@`;
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
function restoreFootnoteReferencesInValue(value) {
|
|
711
|
+
if (!FOOTNOTE_REF_PLACEHOLDER_RE.test(value)) {
|
|
712
|
+
FOOTNOTE_REF_PLACEHOLDER_RE.lastIndex = 0;
|
|
713
|
+
return null;
|
|
714
|
+
}
|
|
715
|
+
FOOTNOTE_REF_PLACEHOLDER_RE.lastIndex = 0;
|
|
716
|
+
const nextChildren = [];
|
|
717
|
+
let lastIndex = 0;
|
|
718
|
+
for (const match of value.matchAll(FOOTNOTE_REF_PLACEHOLDER_RE)) {
|
|
719
|
+
const start = match.index ?? 0;
|
|
720
|
+
const identifier = match[1];
|
|
721
|
+
if (start > lastIndex) {
|
|
722
|
+
nextChildren.push({
|
|
723
|
+
type: "text",
|
|
724
|
+
value: value.slice(lastIndex, start)
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
if (identifier) {
|
|
728
|
+
nextChildren.push({
|
|
729
|
+
type: "footnoteReference",
|
|
730
|
+
identifier,
|
|
731
|
+
label: identifier
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
lastIndex = start + match[0].length;
|
|
735
|
+
}
|
|
736
|
+
if (lastIndex < value.length) {
|
|
737
|
+
nextChildren.push({
|
|
738
|
+
type: "text",
|
|
739
|
+
value: value.slice(lastIndex)
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
return nextChildren;
|
|
743
|
+
}
|
|
744
|
+
function restoreFootnoteReferences(nodes) {
|
|
745
|
+
return nodes.flatMap((node) => {
|
|
746
|
+
if (node.type === "text" && typeof node.value === "string") {
|
|
747
|
+
return restoreFootnoteReferencesInValue(node.value) ?? [node];
|
|
748
|
+
}
|
|
749
|
+
if ("children" in node && Array.isArray(node.children)) {
|
|
750
|
+
return [
|
|
751
|
+
{
|
|
752
|
+
...node,
|
|
753
|
+
children: restoreFootnoteReferences(node.children)
|
|
754
|
+
}
|
|
755
|
+
];
|
|
756
|
+
}
|
|
757
|
+
return [node];
|
|
758
|
+
});
|
|
759
|
+
}
|
|
704
760
|
function findTabsEnd(lines, startLine) {
|
|
705
761
|
let cursor = startLine + 1;
|
|
706
762
|
let nestedDepth = 0;
|
|
@@ -747,6 +803,7 @@ function splitTabSections(value) {
|
|
|
747
803
|
let yamlSource = "";
|
|
748
804
|
let yamlCaptured = false;
|
|
749
805
|
let inInnerFence = null;
|
|
806
|
+
let nestedBlockDepth = 0;
|
|
750
807
|
for (const line of lines) {
|
|
751
808
|
const trimmed = line.trim();
|
|
752
809
|
if (inInnerFence) {
|
|
@@ -766,7 +823,17 @@ function splitTabSections(value) {
|
|
|
766
823
|
currentSection.push(line);
|
|
767
824
|
continue;
|
|
768
825
|
}
|
|
769
|
-
if (
|
|
826
|
+
if (DOUBLE_BLOCK_START_RE.test(line)) {
|
|
827
|
+
nestedBlockDepth += 1;
|
|
828
|
+
currentSection.push(line);
|
|
829
|
+
continue;
|
|
830
|
+
}
|
|
831
|
+
if (BLOCK_END_RE.test(line) && nestedBlockDepth > 0) {
|
|
832
|
+
nestedBlockDepth -= 1;
|
|
833
|
+
currentSection.push(line);
|
|
834
|
+
continue;
|
|
835
|
+
}
|
|
836
|
+
if (nestedBlockDepth === 0 && YAML_BODY_SPLIT_RE.test(line)) {
|
|
770
837
|
if (!yamlCaptured) {
|
|
771
838
|
yamlSource = currentSection.join("\n");
|
|
772
839
|
yamlCaptured = true;
|
|
@@ -840,7 +907,9 @@ var tabsBlockHandler = {
|
|
|
840
907
|
(tab) => context.createFlowElement(
|
|
841
908
|
context.componentNames.tabsContent,
|
|
842
909
|
{ value: tab.value },
|
|
843
|
-
|
|
910
|
+
restoreFootnoteReferences(
|
|
911
|
+
context.transformFragment(protectFootnoteReferences(tab.content))
|
|
912
|
+
)
|
|
844
913
|
)
|
|
845
914
|
);
|
|
846
915
|
return {
|
package/dist/index.js
CHANGED
|
@@ -654,6 +654,62 @@ var legacyGuardBlockHandler = {
|
|
|
654
654
|
|
|
655
655
|
// src/remark/custom-syntax/handlers/tabs-block.ts
|
|
656
656
|
var TABS_START_RE = /^::tabs\s*$/i;
|
|
657
|
+
var FOOTNOTE_REF_PLACEHOLDER_RE = /@@MARKDOWN_CORE_FOOTNOTE_REF:([^@\s]+)@@/g;
|
|
658
|
+
function protectFootnoteReferences(markdown) {
|
|
659
|
+
return markdown.replace(/\[\^([^\]\s]+)\](?!:)/g, (_, identifier) => {
|
|
660
|
+
return `@@MARKDOWN_CORE_FOOTNOTE_REF:${identifier}@@`;
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
function restoreFootnoteReferencesInValue(value) {
|
|
664
|
+
if (!FOOTNOTE_REF_PLACEHOLDER_RE.test(value)) {
|
|
665
|
+
FOOTNOTE_REF_PLACEHOLDER_RE.lastIndex = 0;
|
|
666
|
+
return null;
|
|
667
|
+
}
|
|
668
|
+
FOOTNOTE_REF_PLACEHOLDER_RE.lastIndex = 0;
|
|
669
|
+
const nextChildren = [];
|
|
670
|
+
let lastIndex = 0;
|
|
671
|
+
for (const match of value.matchAll(FOOTNOTE_REF_PLACEHOLDER_RE)) {
|
|
672
|
+
const start = match.index ?? 0;
|
|
673
|
+
const identifier = match[1];
|
|
674
|
+
if (start > lastIndex) {
|
|
675
|
+
nextChildren.push({
|
|
676
|
+
type: "text",
|
|
677
|
+
value: value.slice(lastIndex, start)
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
if (identifier) {
|
|
681
|
+
nextChildren.push({
|
|
682
|
+
type: "footnoteReference",
|
|
683
|
+
identifier,
|
|
684
|
+
label: identifier
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
lastIndex = start + match[0].length;
|
|
688
|
+
}
|
|
689
|
+
if (lastIndex < value.length) {
|
|
690
|
+
nextChildren.push({
|
|
691
|
+
type: "text",
|
|
692
|
+
value: value.slice(lastIndex)
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
return nextChildren;
|
|
696
|
+
}
|
|
697
|
+
function restoreFootnoteReferences(nodes) {
|
|
698
|
+
return nodes.flatMap((node) => {
|
|
699
|
+
if (node.type === "text" && typeof node.value === "string") {
|
|
700
|
+
return restoreFootnoteReferencesInValue(node.value) ?? [node];
|
|
701
|
+
}
|
|
702
|
+
if ("children" in node && Array.isArray(node.children)) {
|
|
703
|
+
return [
|
|
704
|
+
{
|
|
705
|
+
...node,
|
|
706
|
+
children: restoreFootnoteReferences(node.children)
|
|
707
|
+
}
|
|
708
|
+
];
|
|
709
|
+
}
|
|
710
|
+
return [node];
|
|
711
|
+
});
|
|
712
|
+
}
|
|
657
713
|
function findTabsEnd(lines, startLine) {
|
|
658
714
|
let cursor = startLine + 1;
|
|
659
715
|
let nestedDepth = 0;
|
|
@@ -700,6 +756,7 @@ function splitTabSections(value) {
|
|
|
700
756
|
let yamlSource = "";
|
|
701
757
|
let yamlCaptured = false;
|
|
702
758
|
let inInnerFence = null;
|
|
759
|
+
let nestedBlockDepth = 0;
|
|
703
760
|
for (const line of lines) {
|
|
704
761
|
const trimmed = line.trim();
|
|
705
762
|
if (inInnerFence) {
|
|
@@ -719,7 +776,17 @@ function splitTabSections(value) {
|
|
|
719
776
|
currentSection.push(line);
|
|
720
777
|
continue;
|
|
721
778
|
}
|
|
722
|
-
if (
|
|
779
|
+
if (DOUBLE_BLOCK_START_RE.test(line)) {
|
|
780
|
+
nestedBlockDepth += 1;
|
|
781
|
+
currentSection.push(line);
|
|
782
|
+
continue;
|
|
783
|
+
}
|
|
784
|
+
if (BLOCK_END_RE.test(line) && nestedBlockDepth > 0) {
|
|
785
|
+
nestedBlockDepth -= 1;
|
|
786
|
+
currentSection.push(line);
|
|
787
|
+
continue;
|
|
788
|
+
}
|
|
789
|
+
if (nestedBlockDepth === 0 && YAML_BODY_SPLIT_RE.test(line)) {
|
|
723
790
|
if (!yamlCaptured) {
|
|
724
791
|
yamlSource = currentSection.join("\n");
|
|
725
792
|
yamlCaptured = true;
|
|
@@ -793,7 +860,9 @@ var tabsBlockHandler = {
|
|
|
793
860
|
(tab) => context.createFlowElement(
|
|
794
861
|
context.componentNames.tabsContent,
|
|
795
862
|
{ value: tab.value },
|
|
796
|
-
|
|
863
|
+
restoreFootnoteReferences(
|
|
864
|
+
context.transformFragment(protectFootnoteReferences(tab.content))
|
|
865
|
+
)
|
|
797
866
|
)
|
|
798
867
|
);
|
|
799
868
|
return {
|
package/package.json
CHANGED