Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lexical/markdown

Package Overview
Dependencies
Maintainers
3
Versions
195
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lexical/markdown - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

356

LexicalMarkdown.dev.js

@@ -128,15 +128,15 @@ /**

};
const markdownBold = { ...autoFormatBase,
markdownFormatKind: 'bold',
regEx: /(\*\*)(\s*)([^\*\*]*)(\s*)(\*\*)()/,
regExForAutoFormatting: /(\*\*)(\s*\b)([^\*\*]*)(\b\s*)(\*\*)(\s)$/
};
const markdownItalic = { ...autoFormatBase,
markdownFormatKind: 'italic',
regEx: /(\*)([^\*]*)(\*)/,
regEx: /(\*)(\s*)([^\*]*)(\s*)(\*)()/,
regExForAutoFormatting: /(\*)(\s*\b)([^\*]*)(\b\s*)(\*)(\s)$/
};
const markdownBold = { ...autoFormatBase,
markdownFormatKind: 'bold',
regEx: /(\*\*)([^\*\*]*)(\*\*)/,
regExForAutoFormatting: /(\*\*)(\s*\b)([^\*\*]*)(\b\s*)(\*\*)(\s)$/
};
const markdownBold2 = { ...autoFormatBase,
markdownFormatKind: 'bold',
regEx: /(__)(\s*)([^__]*)(\s*)(__)/,
regEx: /(__)(\s*)([^__]*)(\s*)(__)()/,
regExForAutoFormatting: /(__)(\s*)([^__]*)(\s*)(__)(\s)$/

@@ -146,3 +146,3 @@ };

markdownFormatKind: 'italic',
regEx: /(_)([^_]*)(_)/,
regEx: /(_)()([^_]*)()(_)()/,
regExForAutoFormatting: /(_)()([^_]*)()(_)(\s)$/ // Maintain 7 groups.

@@ -155,3 +155,3 @@

markdownFormatKind: 'underline',
regEx: /(\<u\>)(\s*\b)([^\<]*)(\b\s*)(\<\/u\>)/,
regEx: /(\<u\>)(\s*)([^\<]*)(\s*)(\<\/u\>)()/,
regExForAutoFormatting: /(\<u\>)(\s*\b)([^\<]*)(\b\s*)(\<\/u\>)(\s)$/

@@ -161,3 +161,3 @@ };

markdownFormatKind: 'strikethrough',
regEx: /(~~)([^~~]*)(~~)/,
regEx: /(~~)(\s*)([^~~]*)(\s*)(~~)()/,
regExForAutoFormatting: /(~~)(\s*\b)([^~~]*)(\b\s*)(~~)(\s)$/

@@ -167,3 +167,3 @@ };

markdownFormatKind: 'strikethrough_italic_bold',
regEx: /(~~_\*\*)(\s*\b)([^~~_\*\*][^\*\*_~~]*)(\b\s*)(\*\*_~~)/,
regEx: /(~~_\*\*)(\s*\b)([^~~_\*\*][^\*\*_~~]*)(\b\s*)(\*\*_~~)()/,
regExForAutoFormatting: /(~~_\*\*)(\s*\b)([^~~_\*\*][^\*\*_~~]*)(\b\s*)(\*\*_~~)(\s)$/

@@ -188,4 +188,4 @@ };

markdownFormatKind: 'link',
regEx: /(\[)(.+)(\]\()([^ ]+)(?: \"(?:.+)\")?(\))/,
regExForAutoFormatting: /(\[)(.+)(\]\()([^ ]+)(?: \"(?:.+)\")?(\))(\s)$/
regEx: /(\[)([^\]]*)(\]\()([^)]*)(\)*)()/,
regExForAutoFormatting: /(\[)([^\]]*)(\]\()([^)]*)(\)*)(\s)$/
};

@@ -195,5 +195,19 @@ const allMarkdownCriteriaForTextNodes = [// Place the combination formats ahead of the individual formats.

markdownStrikethroughItalicBold, markdownItalicbold, markdownStrikethroughItalic, markdownStrikethroughBold, // Individuals
markdownInlineCode, markdownItalic, markdownBold, markdownBold2, markdownItalic2, // Must appear after markdownBold2.
markdownInlineCode, markdownBold, markdownItalic, // Must appear after markdownBold
markdownBold2, markdownItalic2, // Must appear after markdownBold2.
fakeMarkdownUnderline, markdownStrikethrough, markdownLink];
const allMarkdownCriteria = [markdownHeader1, markdownHeader2, markdownHeader3, markdownHeader4, markdownHeader5, markdownBlockQuote, markdownUnorderedListDash, markdownUnorderedListAsterisk, markdownOrderedList, markdownCodeBlock, markdownHorizontalRule, markdownHorizontalRuleUsingDashes, ...allMarkdownCriteriaForTextNodes];
const allMarkdownCriteriaForParagraphs = [markdownHeader1, markdownHeader2, markdownHeader3, markdownHeader4, markdownHeader5, markdownBlockQuote, markdownUnorderedListDash, markdownUnorderedListAsterisk, markdownOrderedList, markdownCodeBlock, markdownHorizontalRule, markdownHorizontalRuleUsingDashes];
const allMarkdownCriteria = [...allMarkdownCriteriaForParagraphs, ...allMarkdownCriteriaForTextNodes];
function getAllTriggers() {
return triggers;
}
function getAllMarkdownCriteriaForParagraphs() {
return allMarkdownCriteriaForParagraphs;
}
function getAllMarkdownCriteriaForTextNodes() {
return allMarkdownCriteriaForTextNodes;
}
function getAllMarkdownCriteria() {
return allMarkdownCriteria;
}
function getInitialScanningContext(editor, isAutoFormatting, textNodeWithOffset, triggerState) {

@@ -222,3 +236,3 @@ return {

function resetScanningContext(scanningContext) {
scanningContext.joinedText = '';
scanningContext.joinedText = null;
scanningContext.markdownCriteria = {

@@ -242,2 +256,9 @@ markdownFormatKind: 'noTransformation',

}
function getPatternMatchResultsForCriteria(markdownCriteria, scanningContext, parentElementNode) {
if (markdownCriteria.requiresParagraphStart === true) {
return getPatternMatchResultsForParagraphs(markdownCriteria, scanningContext);
}
return getPatternMatchResultsForText(markdownCriteria, scanningContext, parentElementNode);
}
function getPatternMatchResultsForCodeBlock(scanningContext, text) {

@@ -292,2 +313,3 @@ const markdownCriteria = getCodeBlockCriteria();

}
function getPatternMatchResultsForParagraphs(markdownCriteria, scanningContext) {

@@ -303,14 +325,13 @@ const textNodeWithOffset = getTextNodeWithOffsetOrThrow(scanningContext); // At start of paragraph.

}
function getPatternMatchResultsForText(markdownCriteria, scanningContext) {
function getPatternMatchResultsForText(markdownCriteria, scanningContext, parentElementNode) {
if (scanningContext.joinedText == null) {
const parentNode = getParent(scanningContext);
if (lexical.$isElementNode(parentNode)) {
if (lexical.$isElementNode(parentElementNode)) {
if (scanningContext.joinedText == null) {
// Lazy calculate the text to search.
scanningContext.joinedText = text.$joinTextNodesInElementNode(parentNode, SEPARATOR_BETWEEN_TEXT_AND_NON_TEXT_NODES, getTextNodeWithOffsetOrThrow(scanningContext));
scanningContext.joinedText = text.$joinTextNodesInElementNode(parentElementNode, SEPARATOR_BETWEEN_TEXT_AND_NON_TEXT_NODES, getTextNodeWithOffsetOrThrow(scanningContext));
}
} else {
{
throw Error(`Expected node ${parentNode.__key} to to be a ElementNode.`);
throw Error(`Expected node ${parentElementNode.__key} to to be a ElementNode.`);
}

@@ -320,3 +341,4 @@ }

return getPatternMatchResultsWithRegEx(scanningContext.joinedText, false, true, markdownCriteria.regExForAutoFormatting);
const matchMustAppearAtEndOfString = markdownCriteria.regExForAutoFormatting === true;
return getPatternMatchResultsWithRegEx(scanningContext.joinedText, false, matchMustAppearAtEndOfString, scanningContext.isAutoFormatting ? markdownCriteria.regExForAutoFormatting : markdownCriteria.regEx);
}

@@ -524,2 +546,10 @@

function transformTextNodeForMarkdownCriteria(scanningContext, elementNode, createHorizontalRuleNode) {
if (scanningContext.markdownCriteria.requiresParagraphStart === true) {
transformTextNodeForElementNode(elementNode, scanningContext, createHorizontalRuleNode);
} else {
transformTextNodeForText(scanningContext, elementNode);
}
}
function transformTextNodeForElementNode(elementNode, scanningContext, createHorizontalRuleNode) {

@@ -553,3 +583,4 @@ if (scanningContext.textNodeWithOffset != null) {

}
function transformTextNodeForText(scanningContext) {
function transformTextNodeForText(scanningContext, parentElementNode) {
const markdownCriteria = scanningContext.markdownCriteria;

@@ -561,3 +592,3 @@

if (formatting != null) {
transformTextNodeWithFormatting(formatting, scanningContext);
transformTextNodeWithFormatting(formatting, scanningContext, parentElementNode);
return;

@@ -567,3 +598,3 @@ }

if (markdownCriteria.markdownFormatKind === 'link') {
transformTextNodeWithLink(scanningContext);
transformTextNodeWithLink(scanningContext, parentElementNode);
}

@@ -573,3 +604,3 @@ }

function transformTextNodeWithFormatting(formatting, scanningContext) {
function transformTextNodeWithFormatting(formatting, scanningContext, parentElementNode) {
const patternMatchResults = scanningContext.patternMatchResults;

@@ -593,12 +624,12 @@ const groupCount = patternMatchResults.regExCaptureGroups.length;

removeTextByCaptureGroups(5, 5, scanningContext); // Remove group 1.
removeTextByCaptureGroups(5, 5, scanningContext, parentElementNode); // Remove group 1.
removeTextByCaptureGroups(1, 1, scanningContext); // Apply the formatting.
removeTextByCaptureGroups(1, 1, scanningContext, parentElementNode); // Apply the formatting.
formatTextInCaptureGroupIndex(formatting, 3, scanningContext); // Place caret at end of final capture group.
formatTextInCaptureGroupIndex(formatting, 3, scanningContext, parentElementNode); // Place caret at end of final capture group.
selectAfterFinalCaptureGroup(scanningContext);
selectAfterFinalCaptureGroup(scanningContext, parentElementNode);
}
function transformTextNodeWithLink(scanningContext) {
function transformTextNodeWithLink(scanningContext, parentElementNode) {
const patternMatchResults = scanningContext.patternMatchResults;

@@ -629,6 +660,6 @@ const regExCaptureGroups = patternMatchResults.regExCaptureGroups;

removeTextByCaptureGroups(1, 5, scanningContext);
removeTextByCaptureGroups(1, 5, scanningContext, parentElementNode);
insertTextPriorToCaptureGroup(1, // Insert at the beginning of the meaningful capture groups, namely index 1. Index 0 refers to the whole matched string.
title, scanningContext);
const newSelectionForLink = createSelectionWithCaptureGroups(1, 1, false, true, scanningContext);
title, scanningContext, parentElementNode);
const newSelectionForLink = createSelectionWithCaptureGroups(1, 1, false, true, scanningContext, parentElementNode);

@@ -642,7 +673,7 @@ if (newSelectionForLink == null) {

selectAfterFinalCaptureGroup(scanningContext);
selectAfterFinalCaptureGroup(scanningContext, parentElementNode);
} // Below are lower level helper functions.
function getParent(scanningContext) {
function getParentElementNodeOrThrow(scanningContext) {
return getTextNodeWithOffsetOrThrow(scanningContext).node.getParentOrThrow();

@@ -696,3 +727,3 @@ }

function createSelectionWithCaptureGroups(anchorCaptureGroupIndex, focusCaptureGroupIndex, startAtEndOfAnchor, finishAtEndOfFocus, scanningContext) {
function createSelectionWithCaptureGroups(anchorCaptureGroupIndex, focusCaptureGroupIndex, startAtEndOfAnchor, finishAtEndOfFocus, scanningContext, parentElementNode) {
const patternMatchResults = scanningContext.patternMatchResults;

@@ -706,3 +737,2 @@ const regExCaptureGroups = patternMatchResults.regExCaptureGroups;

const parentElementNode = getParent(scanningContext);
const joinedTextLength = getJoinedTextLength(patternMatchResults);

@@ -716,2 +746,9 @@ const anchorCaptureGroupDetail = regExCaptureGroups[anchorCaptureGroupIndex];

if (anchorTextNodeWithOffset == null && focusTextNodeWithOffset == null && parentElementNode.getChildren().length === 0) {
const emptyElementSelection = lexical.$createRangeSelection();
emptyElementSelection.anchor.set(parentElementNode.getKey(), 0, 'element');
emptyElementSelection.focus.set(parentElementNode.getKey(), 0, 'element');
return emptyElementSelection;
}
if (anchorTextNodeWithOffset == null || focusTextNodeWithOffset == null) {

@@ -727,6 +764,6 @@ return null;

function removeTextByCaptureGroups(anchorCaptureGroupIndex, focusCaptureGroupIndex, scanningContext) {
function removeTextByCaptureGroups(anchorCaptureGroupIndex, focusCaptureGroupIndex, scanningContext, parentElementNode) {
const patternMatchResults = scanningContext.patternMatchResults;
const regExCaptureGroups = patternMatchResults.regExCaptureGroups;
const newSelection = createSelectionWithCaptureGroups(anchorCaptureGroupIndex, focusCaptureGroupIndex, false, true, scanningContext);
const newSelection = createSelectionWithCaptureGroups(anchorCaptureGroupIndex, focusCaptureGroupIndex, false, true, scanningContext, parentElementNode);

@@ -759,3 +796,3 @@ if (newSelection != null) {

function insertTextPriorToCaptureGroup(captureGroupIndex, text, scanningContext) {
function insertTextPriorToCaptureGroup(captureGroupIndex, text, scanningContext, parentElementNode) {
const patternMatchResults = scanningContext.patternMatchResults;

@@ -774,3 +811,3 @@ const regExCaptureGroups = patternMatchResults.regExCaptureGroups;

};
const newSelection = createSelectionWithCaptureGroups(captureGroupIndex, captureGroupIndex, false, false, scanningContext);
const newSelection = createSelectionWithCaptureGroups(captureGroupIndex, captureGroupIndex, false, false, scanningContext, parentElementNode);

@@ -796,3 +833,3 @@ if (newSelection != null) {

function formatTextInCaptureGroupIndex(formatTypes, captureGroupIndex, scanningContext) {
function formatTextInCaptureGroupIndex(formatTypes, captureGroupIndex, scanningContext, parentElementNode) {
const patternMatchResults = scanningContext.patternMatchResults;

@@ -812,3 +849,3 @@ const regExCaptureGroups = patternMatchResults.regExCaptureGroups;

const newSelection = createSelectionWithCaptureGroups(captureGroupIndex, captureGroupIndex, false, true, scanningContext);
const newSelection = createSelectionWithCaptureGroups(captureGroupIndex, captureGroupIndex, false, true, scanningContext, parentElementNode);

@@ -828,3 +865,3 @@ if (newSelection != null) {

function selectAfterFinalCaptureGroup(scanningContext) {
function selectAfterFinalCaptureGroup(scanningContext, parentElementNode) {
const patternMatchResults = scanningContext.patternMatchResults;

@@ -839,3 +876,3 @@ const groupCount = patternMatchResults.regExCaptureGroups.length;

const lastGroupIndex = groupCount - 1;
const newSelection = createSelectionWithCaptureGroups(lastGroupIndex, lastGroupIndex, true, true, scanningContext);
const newSelection = createSelectionWithCaptureGroups(lastGroupIndex, lastGroupIndex, true, true, scanningContext, parentElementNode);

@@ -855,28 +892,3 @@ if (newSelection != null) {

*/
function getAllTriggers() {
return triggers;
}
function getAllMarkdownCriteriaForTextNodes() {
return allMarkdownCriteriaForTextNodes;
}
function getAllMarkdownCriteria() {
return allMarkdownCriteria;
}
function transformTextNodeForMarkdownCriteria(scanningContext, createHorizontalRuleNode) {
if (scanningContext.markdownCriteria.requiresParagraphStart === true) {
const elementNode = getTextNodeWithOffsetOrThrow(scanningContext).node.getParentOrThrow();
transformTextNodeForElementNode(elementNode, scanningContext, createHorizontalRuleNode);
} else {
transformTextNodeForText(scanningContext);
}
}
function getPatternMatchResultsForCriteria(markdownCriteria, scanningContext) {
if (markdownCriteria.requiresParagraphStart === true) {
return getPatternMatchResultsForParagraphs(markdownCriteria, scanningContext);
}
return getPatternMatchResultsForText(markdownCriteria, scanningContext);
}
function getTextNodeForAutoFormatting(selection) {

@@ -901,3 +913,4 @@ if (!lexical.$isRangeSelection(selection)) {

editor.update(() => {
transformTextNodeForMarkdownCriteria(scanningContext, createHorizontalRuleNode);
const elementNode = getTextNodeWithOffsetOrThrow(scanningContext).node.getParentOrThrow();
transformTextNodeForMarkdownCriteria(scanningContext, elementNode, createHorizontalRuleNode);
}, {

@@ -916,3 +929,3 @@ tag: 'history-push'

if (currentTriggerState != null && currentTriggerState.isCodeBlock === false || markdownCriteria.markdownFormatKind === 'paragraphCodeBlock') {
const patternMatchResults = getPatternMatchResultsForCriteria(markdownCriteria, scanningContext);
const patternMatchResults = getPatternMatchResultsForCriteria(markdownCriteria, scanningContext, getParentElementNodeOrThrow(scanningContext));

@@ -1001,3 +1014,5 @@ if (patternMatchResults != null) {

const currentTextContentLength = currentTriggerState.textContent.length;
const triggerOffset = currentTriggerState.anchorOffset - triggerStringLength;
const triggerOffset = currentTriggerState.anchorOffset - triggerStringLength; // Todo: these checks help w/ performance, yet we can do more.
// We might consider looking for ** + space or __ + space and so on to boost performance
// even further. Make sure the patter is driven from the trigger state type.

@@ -1047,4 +1062,57 @@ if ((currentTriggerState.hasParentNode === true && currentTriggerState.isSimpleText && currentTriggerState.isSelectionCollapsed && currentTriggerState.anchorOffset !== priorTriggerState.anchorOffset && triggerOffset >= 0 && triggerOffset + triggerStringLength <= currentTextContentLength && currentTriggerState.textContent.substr(triggerOffset, triggerStringLength) === triggerString && // Some code differentiation needed if trigger kind is not a simple space character.

}
function convertMarkdownForElementNodes(editor, createHorizontalRuleNode) {
// Please see the declaration of ScanningContext for a detailed explanation.
const scanningContext = getInitialScanningContext(editor, false, null, null);
const root = lexical.$getRoot();
let done = false;
let startIndex = 0; // Handle the paragraph level markdown.
function convertElementNodeContainingMarkdown(scanningContext, elementNode, createHorizontalRuleNode) {
while (!done) {
done = true;
const elementNodes = root.getChildren();
const countOfElementNodes = elementNodes.length;
for (let i = startIndex; i < countOfElementNodes; i++) {
const elementNode = elementNodes[i];
if (lexical.$isElementNode(elementNode)) {
convertParagraphLevelMarkdown(scanningContext, elementNode, createHorizontalRuleNode);
} // Reset the scanning information that relates to the particular element node.
resetScanningContext(scanningContext);
if (root.getChildren().length !== countOfElementNodes) {
// The conversion added or removed an from root's children.
startIndex = i;
done = false;
break;
}
}
} // while
done = false;
startIndex = 0; // Handle the text level markdown.
while (!done) {
done = true;
const elementNodes = root.getChildren();
const countOfElementNodes = elementNodes.length;
for (let i = startIndex; i < countOfElementNodes; i++) {
const elementNode = elementNodes[i];
if (lexical.$isElementNode(elementNode)) {
convertTextLevelMarkdown(scanningContext, elementNode, createHorizontalRuleNode);
} // Reset the scanning information that relates to the particular element node.
resetScanningContext(scanningContext);
}
} // while
}
function convertParagraphLevelMarkdown(scanningContext, elementNode, createHorizontalRuleNode) {
const textContent = elementNode.getTextContent(); // Handle paragraph nodes below.

@@ -1074,3 +1142,3 @@

transformTextNodeForElementNode(elementNode, scanningContext, createHorizontalRuleNode);
transformTextNodeForMarkdownCriteria(scanningContext, elementNode, createHorizontalRuleNode);
return;

@@ -1080,28 +1148,30 @@ }

if (elementNode.getChildren().length) {
const allCriteria = getAllMarkdownCriteria();
const allCriteria = getAllMarkdownCriteriaForParagraphs();
const count = allCriteria.length;
scanningContext.joinedText = paragraphNode.getTextContent();
if (!(firstChild != null && firstChildIsTextNode)) {
throw Error(`Expect paragraph containing only text nodes.`);
}
scanningContext.textNodeWithOffset = {
node: firstChild,
offset: 0
};
for (let i = 0; i < count; i++) {
const criteria = allCriteria[i];
if (criteria.requiresParagraphStart === true) {
if (!(firstChild != null && firstChildIsTextNode)) {
throw Error(`Expect paragraph containing only text nodes.`);
}
if (criteria.requiresParagraphStart === false) {
return;
}
scanningContext.textNodeWithOffset = {
node: firstChild,
offset: 0
};
scanningContext.joinedText = paragraphNode.getTextContent();
const patternMatchResults = getPatternMatchResultsForParagraphs(criteria, scanningContext);
const patternMatchResults = getPatternMatchResultsForCriteria(criteria, scanningContext, getParentElementNodeOrThrow(scanningContext));
if (patternMatchResults != null) {
// Lazy fill-in the particular format criteria and any matching result information.
scanningContext.markdownCriteria = criteria;
scanningContext.patternMatchResults = patternMatchResults; // Perform text transformation here.
if (patternMatchResults != null) {
scanningContext.markdownCriteria = criteria;
scanningContext.patternMatchResults = patternMatchResults; // Perform text transformation here.
transformTextNodeForElementNode(elementNode, scanningContext, createHorizontalRuleNode);
return;
}
transformTextNodeForMarkdownCriteria(scanningContext, elementNode, createHorizontalRuleNode);
return;
}

@@ -1113,7 +1183,33 @@ }

function convertMarkdownForElementNodes(editor, createHorizontalRuleNode) {
// Please see the declaration of ScanningContext for a detailed explanation.
const scanningContext = getInitialScanningContext(editor, false, null, null);
const root = lexical.$getRoot();
let done = false;
function convertTextLevelMarkdown(scanningContext, elementNode, createHorizontalRuleNode) {
const firstChild = elementNode.getFirstChild();
if (lexical.$isTextNode(firstChild)) {
// This function will convert all text nodes within the elementNode.
convertMarkdownForTextCriteria(scanningContext, elementNode, createHorizontalRuleNode);
return;
} // Handle the case where the elementNode has child elementNodes like lists.
// Since we started at a text import, we don't need to worry about anything but textNodes.
const children = elementNode.getChildren();
const countOfChildren = children.length;
for (let i = 0; i < countOfChildren; i++) {
const node = children[i];
if (lexical.$isElementNode(node)) {
// Recurse down until we find a text node.
convertTextLevelMarkdown(scanningContext, node, createHorizontalRuleNode);
}
}
}
function convertMarkdownForTextCriteria(scanningContext, elementNode, createHorizontalRuleNode) {
resetScanningContext(scanningContext); // Cycle through all the criteria and convert all text patterns in the parent element.
const allCriteria = getAllMarkdownCriteriaForTextNodes();
const count = allCriteria.length;
let textContent = elementNode.getTextContent();
let done = textContent.length === 0;
let startIndex = 0;

@@ -1123,17 +1219,43 @@

done = true;
const elementNodes = root.getChildren();
const countOfElementNodes = elementNodes.length;
for (let i = startIndex; i < countOfElementNodes; i++) {
const elementNode = elementNodes[i];
for (let i = startIndex; i < count; i++) {
const criteria = allCriteria[i];
if (lexical.$isElementNode(elementNode)) {
convertElementNodeContainingMarkdown(scanningContext, elementNode, createHorizontalRuleNode);
} // Reset the scanning information that relates to the particular element node.
if (scanningContext.textNodeWithOffset == null) {
// Need to search through the very last text node in the element.
const lastTextNode = getLastTextNodeInElementNode(elementNode);
if (lastTextNode == null) {
// If we have no more text nodes, then there's nothing to search and transform.
return;
}
resetScanningContext(scanningContext);
scanningContext.textNodeWithOffset = {
node: lastTextNode,
offset: lastTextNode.getTextContent().length
};
}
if (root.getChildren().length !== countOfElementNodes) {
// The conversion added or removed an from root's children.
const patternMatchResults = getPatternMatchResultsForCriteria(criteria, scanningContext, elementNode);
if (patternMatchResults != null) {
scanningContext.markdownCriteria = criteria;
scanningContext.patternMatchResults = patternMatchResults; // Perform text transformation here.
transformTextNodeForMarkdownCriteria(scanningContext, elementNode, createHorizontalRuleNode);
resetScanningContext(scanningContext);
const currentTextContent = elementNode.getTextContent();
if (currentTextContent.length === 0) {
// Nothing left to convert.
return;
}
if (currentTextContent === textContent) {
// Nothing was changed by this transformation, so move on to the next crieteria.
continue;
} // The text was changed. Perhaps there is another hit for the same criteria.
textContent = currentTextContent;
startIndex = i;

@@ -1144,4 +1266,16 @@ done = false;

}
} // while
}
}
function getLastTextNodeInElementNode(elementNode) {
const children = elementNode.getChildren();
const countOfChildren = children.length;
for (let i = countOfChildren - 1; i >= 0; i--) {
if (lexical.$isTextNode(children[i])) {
return children[i];
}
}
return null;
}

@@ -1148,0 +1282,0 @@

@@ -7,32 +7,35 @@ /**

*/
var k=require("@lexical/code"),m=require("@lexical/list"),n=require("lexical"),t=require("@lexical/link"),u=require("@lexical/rich-text"),v=require("@lexical/text");function w(c){throw Error(`Minified Lexical error #${c}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
const x=[{triggerKind:"space_trigger",triggerString:" "}],y={markdownFormatKind:null,regEx:/(?:)/,regExForAutoFormatting:/(?:)/,requiresParagraphStart:!1},A={...y,requiresParagraphStart:!0},B={...A,markdownFormatKind:"paragraphCodeBlock",regEx:/^(```)$/,regExForAutoFormatting:/^(```)([a-z]*)( )/},C=[{...y,markdownFormatKind:"strikethrough_italic_bold",regEx:/(~~_\*\*)(\s*\b)([^~~_\*\*][^\*\*_~~]*)(\b\s*)(\*\*_~~)/,regExForAutoFormatting:/(~~_\*\*)(\s*\b)([^~~_\*\*][^\*\*_~~]*)(\b\s*)(\*\*_~~)(\s)$/},
{...y,markdownFormatKind:"italic_bold",regEx:/(_\*\*)(\s*\b)([^_\*\*][^\*\*_]*)(\b\s*)(\*\*_)/,regExForAutoFormatting:/(_\*\*)(\s*\b)([^_\*\*][^\*\*_]*)(\b\s*)(\*\*_)(\s)$/},{...y,markdownFormatKind:"strikethrough_italic",regEx:/(~~_)(\s*)([^~~_][^_~~]*)(\s*)(_~~)/,regExForAutoFormatting:/(~~_)(\s*)([^~~_][^_~~]*)(\s*)(_~~)(\s)$/},{...y,markdownFormatKind:"strikethrough_bold",regEx:/(~~\*\*)(\s*\b)([^~~\*\*][^\*\*~~]*)(\b\s*)(\*\*~~)/,regExForAutoFormatting:/(~~\*\*)(\s*\b)([^~~\*\*][^\*\*~~]*)(\b\s*)(\*\*~~)(\s)$/},
{...y,markdownFormatKind:"code",regEx:/(`)([^`]*)(`)/,regExForAutoFormatting:/(`)(\s*\b)([^`]*)(\b\s*)(`)(\s)$/},{...y,markdownFormatKind:"italic",regEx:/(\*)([^\*]*)(\*)/,regExForAutoFormatting:/(\*)(\s*\b)([^\*]*)(\b\s*)(\*)(\s)$/},{...y,markdownFormatKind:"bold",regEx:/(\*\*)([^\*\*]*)(\*\*)/,regExForAutoFormatting:/(\*\*)(\s*\b)([^\*\*]*)(\b\s*)(\*\*)(\s)$/},{...y,markdownFormatKind:"bold",regEx:/(__)(\s*)([^__]*)(\s*)(__)/,regExForAutoFormatting:/(__)(\s*)([^__]*)(\s*)(__)(\s)$/},{...y,markdownFormatKind:"italic",
regEx:/(_)([^_]*)(_)/,regExForAutoFormatting:/(_)()([^_]*)()(_)(\s)$/},{...y,markdownFormatKind:"underline",regEx:/(<u>)(\s*\b)([^<]*)(\b\s*)(<\/u>)/,regExForAutoFormatting:/(<u>)(\s*\b)([^<]*)(\b\s*)(<\/u>)(\s)$/},{...y,markdownFormatKind:"strikethrough",regEx:/(~~)([^~~]*)(~~)/,regExForAutoFormatting:/(~~)(\s*\b)([^~~]*)(\b\s*)(~~)(\s)$/},{...y,markdownFormatKind:"link",regEx:/(\[)(.+)(\]\()([^ ]+)(?: "(?:.+)")?(\))/,regExForAutoFormatting:/(\[)(.+)(\]\()([^ ]+)(?: "(?:.+)")?(\))(\s)$/}],D=[{...A,
markdownFormatKind:"paragraphH1",regEx:/^(?:# )/,regExForAutoFormatting:/^(?:# )/},{...A,markdownFormatKind:"paragraphH2",regEx:/^(?:## )/,regExForAutoFormatting:/^(?:## )/},{...A,markdownFormatKind:"paragraphH3",regEx:/^(?:### )/,regExForAutoFormatting:/^(?:### )/},{...A,markdownFormatKind:"paragraphH4",regEx:/^(?:#### )/,regExForAutoFormatting:/^(?:#### )/},{...A,markdownFormatKind:"paragraphH5",regEx:/^(?:##### )/,regExForAutoFormatting:/^(?:##### )/},{...A,markdownFormatKind:"paragraphBlockQuote",
regEx:/^(?:> )/,regExForAutoFormatting:/^(?:> )/},{...A,markdownFormatKind:"paragraphUnorderedList",regEx:/^(\s{0,10})(?:- )/,regExForAutoFormatting:/^(\s{0,10})(?:- )/},{...A,markdownFormatKind:"paragraphUnorderedList",regEx:/^(\s{0,10})(?:\* )/,regExForAutoFormatting:/^(\s{0,10})(?:\* )/},{...A,markdownFormatKind:"paragraphOrderedList",regEx:/^(\s{0,10})(\d+)\.\s/,regExForAutoFormatting:/^(\s{0,10})(\d+)\.\s/},B,{...A,markdownFormatKind:"horizontalRule",regEx:/^(?:\*\*\*)$/,regExForAutoFormatting:/^(?:\*\*\* )/},
{...A,markdownFormatKind:"horizontalRule",regEx:/^(?:---)$/,regExForAutoFormatting:/^(?:--- )/},...C];function E(c,d,e,a){return{currentElementNode:null,editor:c,isAutoFormatting:d,isWithinCodeBlock:!1,joinedText:null,markdownCriteria:{markdownFormatKind:"noTransformation",regEx:/(?:)/,regExForAutoFormatting:/(?:)/,requiresParagraphStart:null},patternMatchResults:{regExCaptureGroups:[]},textNodeWithOffset:e,triggerState:a}}
function F(c,d,e,a){const b={regExCaptureGroups:[]};a=c.match(a);if(null!==a&&0<a.length&&(!1===d||0===a.index)&&(!1===e||a.index+a[0].length===c.length)){c=a.length;d=a.index;for(e=0;e<c;e++){const f=a[e];b.regExCaptureGroups.push({offsetInParent:d,text:f});0<e&&(d+=f.length)}return b}return null}function I(c){c=c.textNodeWithOffset;null==c&&w(82);return c}
function J(c,d){var e=I(d);return null===e.node.getPreviousSibling()?(e=e.node.getTextContent(),F(e,!0,!1,d.isAutoFormatting?c.regExForAutoFormatting:c.regEx)):null}
function K(c,d,e){var a=null,b=d.getChildren();const f=c.markdownCriteria,g=c.patternMatchResults;if(null!=f.markdownFormatKind)switch(f.markdownFormatKind){case "paragraphH1":a=u.$createHeadingNode("h1");a.append(...b);break;case "paragraphH2":a=u.$createHeadingNode("h2");a.append(...b);break;case "paragraphH3":a=u.$createHeadingNode("h3");a.append(...b);break;case "paragraphH4":a=u.$createHeadingNode("h4");a.append(...b);break;case "paragraphH5":a=u.$createHeadingNode("h5");a.append(...b);break;
case "paragraphBlockQuote":a=u.$createQuoteNode();a.append(...b);break;case "paragraphUnorderedList":return L(d,b,g,"ul"),{newNode:null,shouldDelete:!1};case "paragraphOrderedList":return a=1<g.regExCaptureGroups.length?g.regExCaptureGroups[g.regExCaptureGroups.length-1].text:"1",c=c.isAutoFormatting?parseInt(a,10):void 0,L(d,b,g,"ol",c),{newNode:null,shouldDelete:!1};case "paragraphCodeBlock":if(!1===c.isAutoFormatting){if(0<c.patternMatchResults.regExCaptureGroups.length)return c.isWithinCodeBlock=
!0!==c.isWithinCodeBlock,c.currentElementNode=null,{newNode:null,shouldDelete:!0};if(c.isWithinCodeBlock){if(null==c.currentElementNode)return d=k.$createCodeNode(),d.append(...b),c.currentElementNode=d,{newNode:d,shouldDelete:!1};null!=c.currentElementNode&&(d=c.currentElementNode,c=n.$createLineBreakNode(),d.append(c),b.length&&d.append(c),d.append(...b))}return{newNode:null,shouldDelete:!0}}null!=c.triggerState&&c.triggerState.isCodeBlock?a=n.$createParagraphNode():(a=k.$createCodeNode(),d=3<=
g.regExCaptureGroups.length?g.regExCaptureGroups[2].text:null,null!=d&&0<d.length&&a.setLanguage(d));a.append(...b);break;case "horizontalRule":null!=e&&(b=e(),d.insertBefore(b))}return{newNode:a,shouldDelete:!1}}
function L(c,d,e,a,b){const f=m.$createListItemNode();e=(e=e.regExCaptureGroups[0].text.match(/^\s*/))?Math.floor(e[0].length/4):0;f.append(...d);d=c.getPreviousSibling();m.$isListNode(d)&&d.getTag()===a?(d.append(f),c.remove()):(a=m.$createListNode(a,b),a.append(f),c.replace(a));e&&f.setIndent(e)}
function M(c,d,e){if(null!=d.textNodeWithOffset){var a=I(d);0<d.patternMatchResults.regExCaptureGroups.length&&(a=a.node.spliceText(0,d.patternMatchResults.regExCaptureGroups[0].text.length,"",!0),""===a.getTextContent()&&(a.selectPrevious(),a.remove()))}const {newNode:b,shouldDelete:f}=K(d,c,e);f?c.remove():null!==b&&c.replace(b)}
function N(c){switch(c){case "italic":case "bold":case "underline":case "strikethrough":case "code":return[c];case "strikethrough_italic_bold":return["strikethrough","italic","bold"];case "italic_bold":return["italic","bold"];case "strikethrough_italic":return["strikethrough","italic"];case "strikethrough_bold":return["strikethrough","bold"]}return null}
function Q(c,d,e,a,b){var f=b.patternMatchResults;const g=f.regExCaptureGroups;var h=g.length;if(c>=h||d>=h)return null;b=I(b).node.getParentOrThrow();h=f.regExCaptureGroups.length;2>h?f=0:(--h,f=f.regExCaptureGroups[h].offsetInParent+f.regExCaptureGroups[h].text.length);c=g[c];d=g[d];a=a?d.offsetInParent+d.text.length:d.offsetInParent;e=v.$findNodeWithOffsetFromJoinedText(e?c.offsetInParent+c.text.length:c.offsetInParent,f,1,b);a=v.$findNodeWithOffsetFromJoinedText(a,f,1,b);if(null==e||null==a)return null;
b=n.$createRangeSelection();b.anchor.set(e.node.getKey(),e.offset,"text");b.focus.set(a.node.getKey(),a.offset,"text");return b}function R(c,d,e){const a=e.patternMatchResults.regExCaptureGroups;e=Q(c,d,!1,!0,e);if(null!=e&&(n.$setSelection(e),e=n.$getSelection(),null!=e&&n.$isRangeSelection(e)&&!1===e.isCollapsed())){e.removeText();e=0;const b=a.length;for(let f=c;f<b;f++){const g=a[f];f>c&&(g.offsetInParent-=e);f<=d&&(e+=g.text.length,g.text="")}}}
function S(c){var d=c.patternMatchResults.regExCaptureGroups.length;2>d||(--d,c=Q(d,d,!0,!0,c),null!=c&&n.$setSelection(c))}
function T(c,d,e){c.update(()=>{if(!0===d.markdownCriteria.requiresParagraphStart){var a=I(d).node.getParentOrThrow();M(a,d,e)}else if(a=d.markdownCriteria,null!=a.markdownFormatKind){var b=N(a.markdownFormatKind);if(null!=b){if(a=b,7===d.patternMatchResults.regExCaptureGroups.length){R(5,5,d);R(1,1,d);b=d.patternMatchResults.regExCaptureGroups;3<b.length||w(65);if(0!==b[3].text.length&&(b=Q(3,3,!1,!0,d),null!=b&&(n.$setSelection(b),b=n.$getSelection(),n.$isRangeSelection(b))))for(var f=0;f<a.length;f++)b.formatText(a[f]);
S(d)}}else if("link"===a.markdownFormatKind&&(a=d.patternMatchResults.regExCaptureGroups,7===a.length&&(f=a[2].text,a=a[4].text,0!==f.length&&0!==a.length))){R(1,5,d);b=d.patternMatchResults.regExCaptureGroups;if(!(1>=b.length)){f={offsetInParent:b[1].offsetInParent,text:f};var g=Q(1,1,!1,!1,d);if(null!=g&&(n.$setSelection(g),g=n.$getSelection(),null!=g&&n.$isRangeSelection(g)&&g.isCollapsed())){g.insertText(f.text);b.splice(1,0,f);f=f.text.length;g=b.length;for(let h=2;h<g;h++)b[h].offsetInParent+=
f}}b=Q(1,1,!1,!0,d);null!=b&&(n.$setSelection(b),d.editor.dispatchCommand(t.TOGGLE_LINK_COMMAND,a),S(d))}}},{tag:"history-push"})}
function U(c,d){let e=null;c.getEditorState().read(()=>{var a=n.$getSelection();if(n.$isRangeSelection(a)){var b=a.anchor.getNode();a=n.$isTextNode(b)?{node:b,offset:a.anchor.offset}:null}else a=null;if(null!==a){a=E(c,!0,a,d);a:{b=!1===d.isParentAListItemNode?D:C;const h=a.triggerState,r=b.length;for(let p=0;p<r;p++){const l=b[p];if(null!=h&&!1===h.isCodeBlock||"paragraphCodeBlock"===l.markdownFormatKind){var f=l,g=a;if(!0===f.requiresParagraphStart)f=J(f,g);else{if(null==g.joinedText){const q=I(g).node.getParentOrThrow();
n.$isElementNode(q)?null==g.joinedText&&(g.joinedText=v.$joinTextNodesInElementNode(q,"\u0004",I(g))):w(52,q.__key)}f=F(g.joinedText,!1,!0,f.regExForAutoFormatting)}if(null!=f){b={markdownCriteria:l,patternMatchResults:f};break a}}}b={markdownCriteria:null,patternMatchResults:null}}null!==b.markdownCriteria&&null!==b.patternMatchResults&&(e=a,e.markdownCriteria=b.markdownCriteria,e.patternMatchResults=b.patternMatchResults)}});return e}
function V(c){let d=null;c.read(()=>{const e=n.$getSelection();if(n.$isRangeSelection(e)&&e.isCollapsed()){var a=e.anchor.getNode(),b=a.getParent(),f=m.$isListItemNode(b);d={anchorOffset:e.anchor.offset,hasParentNode:null!==b,isCodeBlock:k.$isCodeNode(a),isParentAListItemNode:f,isSelectionCollapsed:!0,isSimpleText:n.$isTextNode(a)&&a.isSimpleText(),nodeKey:a.getKey(),textContent:a.getTextContent()}}});return d}
exports.$convertFromMarkdownString=function(c,d,e){if(c.length){var a=[];c=c.split("\n");var b=c.length;for(var f=0;f<b;f++)0<c[f].length?a.push(n.$createParagraphNode().append(n.$createTextNode(c[f]))):a.push(n.$createParagraphNode());a.length?(c=n.$getRoot(),c.clear(),c.append(...a),a=c):a=null}else a=null;if(null!=a)for(d=E(d,!1,null,null),a=n.$getRoot(),c=!1,b=0;!c;){c=!0;f=a.getChildren();const q=f.length;for(let z=b;z<q;z++){var g=f[z];if(n.$isElementNode(g)){var h=d,r=e,p=g.getTextContent();
if(n.$isParagraphNode(g)){var l=g.getFirstChild();const O=n.$isTextNode(l);if(!0===h.isWithinCodeBlock)null!=l&&O&&(h.textNodeWithOffset={node:l,offset:0},l=F(p,!0,!1,h.isAutoFormatting?B.regExForAutoFormatting:B.regEx),null!=l&&(h.patternMatchResults=l)),h.markdownCriteria=B,M(g,h,r);else if(g.getChildren().length){p=D.length;for(let G=0;G<p;G++){const H=D[G];if(!0===H.requiresParagraphStart){null!=l&&O||w(80);h.textNodeWithOffset={node:l,offset:0};h.joinedText=g.getTextContent();const P=J(H,h);
if(null!=P){h.markdownCriteria=H;h.patternMatchResults=P;M(g,h,r);break}}}}}}h=d;h.joinedText="";h.markdownCriteria={markdownFormatKind:"noTransformation",regEx:/(?:)/,regExForAutoFormatting:/(?:)/,requiresParagraphStart:null};h.patternMatchResults={regExCaptureGroups:[]};h.triggerState=null;h.textNodeWithOffset=null;if(a.getChildren().length!==q){b=z;c=!1;break}}}};
exports.registerMarkdownShortcuts=function(c,d){let e=null;return c.registerUpdateListener(({tags:a})=>{if(!1===a.has("historic")){a=V(c.getEditorState());if(null==a)var b=null;else a:{b=a;var f=e;if(null==b||null==f)b=null;else{var g=x.length;for(let h=0;h<g;h++){const r=x[h].triggerString,p=r.length,l=b.textContent.length,q=b.anchorOffset-p;if(!1===(!0===b.hasParentNode&&b.isSimpleText&&b.isSelectionCollapsed&&b.anchorOffset!==f.anchorOffset&&0<=q&&q+p<=l&&b.textContent.substr(q,p)===r&&b.textContent!==
f.textContent)){b=null;break a}}b=U(c,b)}}null!=b&&T(c,b,d);e=a}else e=null})};
var k=require("@lexical/code"),n=require("@lexical/list"),p=require("lexical"),u=require("@lexical/link"),v=require("@lexical/rich-text"),x=require("@lexical/text");function y(a){throw Error(`Minified Lexical error #${a}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
const z=[{triggerKind:"space_trigger",triggerString:" "}],A={markdownFormatKind:null,regEx:/(?:)/,regExForAutoFormatting:/(?:)/,requiresParagraphStart:!1},B={...A,requiresParagraphStart:!0},C={...B,markdownFormatKind:"paragraphCodeBlock",regEx:/^(```)$/,regExForAutoFormatting:/^(```)([a-z]*)( )/},D=[{...A,markdownFormatKind:"strikethrough_italic_bold",regEx:/(~~_\*\*)(\s*\b)([^~~_\*\*][^\*\*_~~]*)(\b\s*)(\*\*_~~)()/,regExForAutoFormatting:/(~~_\*\*)(\s*\b)([^~~_\*\*][^\*\*_~~]*)(\b\s*)(\*\*_~~)(\s)$/},
{...A,markdownFormatKind:"italic_bold",regEx:/(_\*\*)(\s*\b)([^_\*\*][^\*\*_]*)(\b\s*)(\*\*_)/,regExForAutoFormatting:/(_\*\*)(\s*\b)([^_\*\*][^\*\*_]*)(\b\s*)(\*\*_)(\s)$/},{...A,markdownFormatKind:"strikethrough_italic",regEx:/(~~_)(\s*)([^~~_][^_~~]*)(\s*)(_~~)/,regExForAutoFormatting:/(~~_)(\s*)([^~~_][^_~~]*)(\s*)(_~~)(\s)$/},{...A,markdownFormatKind:"strikethrough_bold",regEx:/(~~\*\*)(\s*\b)([^~~\*\*][^\*\*~~]*)(\b\s*)(\*\*~~)/,regExForAutoFormatting:/(~~\*\*)(\s*\b)([^~~\*\*][^\*\*~~]*)(\b\s*)(\*\*~~)(\s)$/},
{...A,markdownFormatKind:"code",regEx:/(`)([^`]*)(`)/,regExForAutoFormatting:/(`)(\s*\b)([^`]*)(\b\s*)(`)(\s)$/},{...A,markdownFormatKind:"bold",regEx:/(\*\*)(\s*)([^\*\*]*)(\s*)(\*\*)()/,regExForAutoFormatting:/(\*\*)(\s*\b)([^\*\*]*)(\b\s*)(\*\*)(\s)$/},{...A,markdownFormatKind:"italic",regEx:/(\*)(\s*)([^\*]*)(\s*)(\*)()/,regExForAutoFormatting:/(\*)(\s*\b)([^\*]*)(\b\s*)(\*)(\s)$/},{...A,markdownFormatKind:"bold",regEx:/(__)(\s*)([^__]*)(\s*)(__)()/,regExForAutoFormatting:/(__)(\s*)([^__]*)(\s*)(__)(\s)$/},
{...A,markdownFormatKind:"italic",regEx:/(_)()([^_]*)()(_)()/,regExForAutoFormatting:/(_)()([^_]*)()(_)(\s)$/},{...A,markdownFormatKind:"underline",regEx:/(<u>)(\s*)([^<]*)(\s*)(<\/u>)()/,regExForAutoFormatting:/(<u>)(\s*\b)([^<]*)(\b\s*)(<\/u>)(\s)$/},{...A,markdownFormatKind:"strikethrough",regEx:/(~~)(\s*)([^~~]*)(\s*)(~~)()/,regExForAutoFormatting:/(~~)(\s*\b)([^~~]*)(\b\s*)(~~)(\s)$/},{...A,markdownFormatKind:"link",regEx:/(\[)([^\]]*)(\]\()([^)]*)(\)*)()/,regExForAutoFormatting:/(\[)([^\]]*)(\]\()([^)]*)(\)*)(\s)$/}],
E=[{...B,markdownFormatKind:"paragraphH1",regEx:/^(?:# )/,regExForAutoFormatting:/^(?:# )/},{...B,markdownFormatKind:"paragraphH2",regEx:/^(?:## )/,regExForAutoFormatting:/^(?:## )/},{...B,markdownFormatKind:"paragraphH3",regEx:/^(?:### )/,regExForAutoFormatting:/^(?:### )/},{...B,markdownFormatKind:"paragraphH4",regEx:/^(?:#### )/,regExForAutoFormatting:/^(?:#### )/},{...B,markdownFormatKind:"paragraphH5",regEx:/^(?:##### )/,regExForAutoFormatting:/^(?:##### )/},{...B,markdownFormatKind:"paragraphBlockQuote",
regEx:/^(?:> )/,regExForAutoFormatting:/^(?:> )/},{...B,markdownFormatKind:"paragraphUnorderedList",regEx:/^(\s{0,10})(?:- )/,regExForAutoFormatting:/^(\s{0,10})(?:- )/},{...B,markdownFormatKind:"paragraphUnorderedList",regEx:/^(\s{0,10})(?:\* )/,regExForAutoFormatting:/^(\s{0,10})(?:\* )/},{...B,markdownFormatKind:"paragraphOrderedList",regEx:/^(\s{0,10})(\d+)\.\s/,regExForAutoFormatting:/^(\s{0,10})(\d+)\.\s/},C,{...B,markdownFormatKind:"horizontalRule",regEx:/^(?:\*\*\*)$/,regExForAutoFormatting:/^(?:\*\*\* )/},
{...B,markdownFormatKind:"horizontalRule",regEx:/^(?:---)$/,regExForAutoFormatting:/^(?:--- )/}],F=[...E,...D];function G(a,d,c,b){return{currentElementNode:null,editor:a,isAutoFormatting:d,isWithinCodeBlock:!1,joinedText:null,markdownCriteria:{markdownFormatKind:"noTransformation",regEx:/(?:)/,regExForAutoFormatting:/(?:)/,requiresParagraphStart:null},patternMatchResults:{regExCaptureGroups:[]},textNodeWithOffset:c,triggerState:b}}
function H(a){a.joinedText=null;a.markdownCriteria={markdownFormatKind:"noTransformation",regEx:/(?:)/,regExForAutoFormatting:/(?:)/,requiresParagraphStart:null};a.patternMatchResults={regExCaptureGroups:[]};a.triggerState=null;a.textNodeWithOffset=null;return a}
function I(a,d,c){if(!0===a.requiresParagraphStart)return c=J(d),null===c.node.getPreviousSibling()?(c=c.node.getTextContent(),a=K(c,!0,!1,d.isAutoFormatting?a.regExForAutoFormatting:a.regEx)):a=null,a;null==d.joinedText&&(p.$isElementNode(c)?null==d.joinedText&&(d.joinedText=x.$joinTextNodesInElementNode(c,"\u0004",J(d))):y(52,c.__key));return K(d.joinedText,!1,!0===a.regExForAutoFormatting,d.isAutoFormatting?a.regExForAutoFormatting:a.regEx)}
function K(a,d,c,b){const e={regExCaptureGroups:[]};b=a.match(b);if(null!==b&&0<b.length&&(!1===d||0===b.index)&&(!1===c||b.index+b[0].length===a.length)){a=b.length;d=b.index;for(c=0;c<a;c++){const f=b[c];e.regExCaptureGroups.push({offsetInParent:d,text:f});0<c&&(d+=f.length)}return e}return null}function J(a){a=a.textNodeWithOffset;null==a&&y(82);return a}
function L(a,d,c){var b=null,e=d.getChildren();const f=a.markdownCriteria,g=a.patternMatchResults;if(null!=f.markdownFormatKind)switch(f.markdownFormatKind){case "paragraphH1":b=v.$createHeadingNode("h1");b.append(...e);break;case "paragraphH2":b=v.$createHeadingNode("h2");b.append(...e);break;case "paragraphH3":b=v.$createHeadingNode("h3");b.append(...e);break;case "paragraphH4":b=v.$createHeadingNode("h4");b.append(...e);break;case "paragraphH5":b=v.$createHeadingNode("h5");b.append(...e);break;
case "paragraphBlockQuote":b=v.$createQuoteNode();b.append(...e);break;case "paragraphUnorderedList":return M(d,e,g,"ul"),{newNode:null,shouldDelete:!1};case "paragraphOrderedList":return b=1<g.regExCaptureGroups.length?g.regExCaptureGroups[g.regExCaptureGroups.length-1].text:"1",a=a.isAutoFormatting?parseInt(b,10):void 0,M(d,e,g,"ol",a),{newNode:null,shouldDelete:!1};case "paragraphCodeBlock":if(!1===a.isAutoFormatting){if(0<a.patternMatchResults.regExCaptureGroups.length)return a.isWithinCodeBlock=
!0!==a.isWithinCodeBlock,a.currentElementNode=null,{newNode:null,shouldDelete:!0};if(a.isWithinCodeBlock){if(null==a.currentElementNode)return d=k.$createCodeNode(),d.append(...e),a.currentElementNode=d,{newNode:d,shouldDelete:!1};null!=a.currentElementNode&&(d=a.currentElementNode,a=p.$createLineBreakNode(),d.append(a),e.length&&d.append(a),d.append(...e))}return{newNode:null,shouldDelete:!0}}null!=a.triggerState&&a.triggerState.isCodeBlock?b=p.$createParagraphNode():(b=k.$createCodeNode(),d=3<=
g.regExCaptureGroups.length?g.regExCaptureGroups[2].text:null,null!=d&&0<d.length&&b.setLanguage(d));b.append(...e);break;case "horizontalRule":null!=c&&(e=c(),d.insertBefore(e))}return{newNode:b,shouldDelete:!1}}
function M(a,d,c,b,e){const f=n.$createListItemNode();c=(c=c.regExCaptureGroups[0].text.match(/^\s*/))?Math.floor(c[0].length/4):0;f.append(...d);d=a.getPreviousSibling();n.$isListNode(d)&&d.getTag()===b?(d.append(f),a.remove()):(b=n.$createListNode(b,e),b.append(f),a.replace(b));c&&f.setIndent(c)}
function N(a,d,c){if(!0===a.markdownCriteria.requiresParagraphStart){if(null!=a.textNodeWithOffset){var b=J(a);0<a.patternMatchResults.regExCaptureGroups.length&&(b=b.node.spliceText(0,a.patternMatchResults.regExCaptureGroups[0].text.length,"",!0),""===b.getTextContent()&&(b.selectPrevious(),b.remove()))}const {newNode:g,shouldDelete:h}=L(a,d,c);h?d.remove():null!==g&&d.replace(g)}else if(c=a.markdownCriteria,null!=c.markdownFormatKind)if(b=O(c.markdownFormatKind),null!=b){if(c=b,7===a.patternMatchResults.regExCaptureGroups.length){Q(5,
5,a,d);Q(1,1,a,d);b=a.patternMatchResults.regExCaptureGroups;3<b.length||y(65);if(0!==b[3].text.length&&(b=R(3,3,!1,!0,a,d),null!=b&&(p.$setSelection(b),b=p.$getSelection(),p.$isRangeSelection(b))))for(var e=0;e<c.length;e++)b.formatText(c[e]);S(a,d)}}else if("link"===c.markdownFormatKind&&(c=a.patternMatchResults.regExCaptureGroups,7===c.length&&(e=c[2].text,c=c[4].text,0!==e.length&&0!==c.length))){Q(1,5,a,d);b=a.patternMatchResults.regExCaptureGroups;if(!(1>=b.length)){e={offsetInParent:b[1].offsetInParent,
text:e};var f=R(1,1,!1,!1,a,d);if(null!=f&&(p.$setSelection(f),f=p.$getSelection(),null!=f&&p.$isRangeSelection(f)&&f.isCollapsed())){f.insertText(e.text);b.splice(1,0,e);e=e.text.length;f=b.length;for(let g=2;g<f;g++)b[g].offsetInParent+=e}}b=R(1,1,!1,!0,a,d);null!=b&&(p.$setSelection(b),a.editor.dispatchCommand(u.TOGGLE_LINK_COMMAND,c),S(a,d))}}
function O(a){switch(a){case "italic":case "bold":case "underline":case "strikethrough":case "code":return[a];case "strikethrough_italic_bold":return["strikethrough","italic","bold"];case "italic_bold":return["italic","bold"];case "strikethrough_italic":return["strikethrough","italic"];case "strikethrough_bold":return["strikethrough","bold"]}return null}
function R(a,d,c,b,e,f){var g=e.patternMatchResults;e=g.regExCaptureGroups;var h=e.length;if(a>=h||d>=h)return null;h=g.regExCaptureGroups.length;2>h?g=0:(--h,g=g.regExCaptureGroups[h].offsetInParent+g.regExCaptureGroups[h].text.length);a=e[a];d=e[d];b=b?d.offsetInParent+d.text.length:d.offsetInParent;c=x.$findNodeWithOffsetFromJoinedText(c?a.offsetInParent+a.text.length:a.offsetInParent,g,1,f);b=x.$findNodeWithOffsetFromJoinedText(b,g,1,f);if(null==c&&null==b&&0===f.getChildren().length)return c=
p.$createRangeSelection(),c.anchor.set(f.getKey(),0,"element"),c.focus.set(f.getKey(),0,"element"),c;if(null==c||null==b)return null;f=p.$createRangeSelection();f.anchor.set(c.node.getKey(),c.offset,"text");f.focus.set(b.node.getKey(),b.offset,"text");return f}
function Q(a,d,c,b){const e=c.patternMatchResults.regExCaptureGroups;c=R(a,d,!1,!0,c,b);if(null!=c&&(p.$setSelection(c),c=p.$getSelection(),null!=c&&p.$isRangeSelection(c)&&!1===c.isCollapsed())){c.removeText();c=0;b=e.length;for(let f=a;f<b;f++){const g=e[f];f>a&&(g.offsetInParent-=c);f<=d&&(c+=g.text.length,g.text="")}}}function S(a,d){var c=a.patternMatchResults.regExCaptureGroups.length;2>c||(--c,a=R(c,c,!0,!0,a,d),null!=a&&p.$setSelection(a))}
function T(a,d,c){a.update(()=>{const b=J(d).node.getParentOrThrow();N(d,b,c)},{tag:"history-push"})}
function U(a,d){let c=null;a.getEditorState().read(()=>{var b=p.$getSelection();if(p.$isRangeSelection(b)){var e=b.anchor.getNode();b=p.$isTextNode(e)?{node:e,offset:b.anchor.offset}:null}else b=null;if(null!==b){b=G(a,!0,b,d);a:{e=!1===d.isParentAListItemNode?F:D;const f=b.triggerState,g=e.length;for(let h=0;h<g;h++){const l=e[h];if(null!=f&&!1===f.isCodeBlock||"paragraphCodeBlock"===l.markdownFormatKind){const m=I(l,b,J(b).node.getParentOrThrow());if(null!=m){e={markdownCriteria:l,patternMatchResults:m};
break a}}}e={markdownCriteria:null,patternMatchResults:null}}null!==e.markdownCriteria&&null!==e.patternMatchResults&&(c=b,c.markdownCriteria=e.markdownCriteria,c.patternMatchResults=e.patternMatchResults)}});return c}
function V(a){let d=null;a.read(()=>{const c=p.$getSelection();if(p.$isRangeSelection(c)&&c.isCollapsed()){var b=c.anchor.getNode(),e=b.getParent(),f=n.$isListItemNode(e);d={anchorOffset:c.anchor.offset,hasParentNode:null!==e,isCodeBlock:k.$isCodeNode(b),isParentAListItemNode:f,isSelectionCollapsed:!0,isSimpleText:p.$isTextNode(b)&&b.isSimpleText(),nodeKey:b.getKey(),textContent:b.getTextContent()}}});return d}
function W(a,d,c){var b=d.getFirstChild();if(p.$isTextNode(b))a:{H(a);b=D.length;var e=d.getTextContent(),f=0===e.length;let m=0;for(;!f;){f=!0;for(let t=m;t<b;t++){var g=D[t];if(null==a.textNodeWithOffset){b:{var h=d.getChildren();var l=h.length;for(--l;0<=l;l--)if(p.$isTextNode(h[l])){h=h[l];break b}h=null}if(null==h)break a;a.textNodeWithOffset={node:h,offset:h.getTextContent().length}}h=I(g,a,d);if(null!=h){a.markdownCriteria=g;a.patternMatchResults=h;N(a,d,c);H(a);g=d.getTextContent();if(0===
g.length)break a;if(g!==e){e=g;m=t;f=!1;break}}}}}else for(d=d.getChildren(),b=d.length,e=0;e<b;e++)f=d[e],p.$isElementNode(f)&&W(a,f,c)}
exports.$convertFromMarkdownString=function(a,d,c){if(a.length){var b=[];a=a.split("\n");var e=a.length;for(var f=0;f<e;f++)0<a[f].length?b.push(p.$createParagraphNode().append(p.$createTextNode(a[f]))):b.push(p.$createParagraphNode());b.length?(a=p.$getRoot(),a.clear(),a.append(...b),b=a):b=null}else b=null;if(null!=b){d=G(d,!1,null,null);b=p.$getRoot();a=!1;for(e=0;!a;){a=!0;var g=b.getChildren(),h=g.length;for(var l=e;l<h;l++){var m=g[l];if(p.$isElementNode(m)){f=d;var t=c;var r=m.getTextContent();
if(p.$isParagraphNode(m)){var q=m.getFirstChild(),w=p.$isTextNode(q);if(!0===f.isWithinCodeBlock)null!=q&&w&&(f.textNodeWithOffset={node:q,offset:0},q=C,r=K(r,!0,!1,f.isAutoFormatting?q.regExForAutoFormatting:q.regEx),null!=r&&(f.patternMatchResults=r)),f.markdownCriteria=C,N(f,m,t);else if(m.getChildren().length)for(r=E.length,f.joinedText=m.getTextContent(),null!=q&&w||y(80),f.textNodeWithOffset={node:q,offset:0},q=0;q<r;q++){w=E[q];if(!1===w.requiresParagraphStart)break;const P=I(w,f,J(f).node.getParentOrThrow());
if(null!=P){f.markdownCriteria=w;f.patternMatchResults=P;N(f,m,t);break}}}}H(d);if(b.getChildren().length!==h){e=l;a=!1;break}}}a=!1;for(e=0;!a;)for(a=!0,f=b.getChildren(),g=f.length,h=e;h<g;h++)l=f[h],p.$isElementNode(l)&&W(d,l,c),H(d)}};
exports.registerMarkdownShortcuts=function(a,d){let c=null;return a.registerUpdateListener(({tags:b})=>{if(!1===b.has("historic")){b=V(a.getEditorState());if(null==b)var e=null;else a:{e=b;var f=c;if(null==e||null==f)e=null;else{var g=z.length;for(let h=0;h<g;h++){const l=z[h].triggerString,m=l.length,t=e.textContent.length,r=e.anchorOffset-m;if(!1===(!0===e.hasParentNode&&e.isSimpleText&&e.isSelectionCollapsed&&e.anchorOffset!==f.anchorOffset&&0<=r&&r+m<=t&&e.textContent.substr(r,m)===l&&e.textContent!==
f.textContent)){e=null;break a}}e=U(a,e)}}null!=e&&T(a,e,d);c=b}else c=null})};

@@ -11,14 +11,14 @@ {

"license": "MIT",
"version": "0.2.1",
"version": "0.2.2",
"main": "LexicalMarkdown.js",
"peerDependencies": {
"lexical": "0.2.1"
"lexical": "0.2.2"
},
"dependencies": {
"@lexical/utils": "0.2.1",
"@lexical/code": "0.2.1",
"@lexical/text": "0.2.1",
"@lexical/rich-text": "0.2.1",
"@lexical/list": "0.2.1",
"@lexical/link": "0.2.1"
"@lexical/utils": "0.2.2",
"@lexical/code": "0.2.2",
"@lexical/text": "0.2.2",
"@lexical/rich-text": "0.2.2",
"@lexical/list": "0.2.2",
"@lexical/link": "0.2.2"
},

@@ -25,0 +25,0 @@ "repository": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc