MCPcopy
hub / github.com/pngwn/MDsveX / eat

Function eat

packages/site/static/workers/mdsvex.js:31592–31641  ·  view source on GitHub ↗
(subvalue)

Source from the content-addressed store, hash-verified

31590 // Remove `subvalue` from `value`. `subvalue` must be at the start of
31591 // `value`.
31592 function eat(subvalue) {
31593 var indent = getOffset();
31594 var pos = position();
31595 var current = now();
31596
31597 validateEat(subvalue);
31598
31599 apply.reset = reset;
31600 reset.test = test;
31601 apply.test = test;
31602
31603 value = value.slice(subvalue.length);
31604
31605 updatePosition(subvalue);
31606
31607 indent = indent();
31608
31609 return apply
31610
31611 // Add the given arguments, add `position` to the returned node, and
31612 // return the node.
31613 function apply(node, parent) {
31614 return pos(add(pos(node), parent), indent)
31615 }
31616
31617 // Functions just like apply, but resets the content: the line and
31618 // column are reversed, and the eaten value is re-added. This is
31619 // useful for nodes with a single type of content, such as lists and
31620 // tables. See `apply` above for what parameters are expected.
31621 function reset() {
31622 var node = apply.apply(null, arguments);
31623
31624 line = current.line;
31625 column = current.column;
31626 value = subvalue + value;
31627
31628 return node
31629 }
31630
31631 // Test the position, after eating, and reverse to a not-eaten state.
31632 function test() {
31633 var result = pos({});
31634
31635 line = current.line;
31636 column = current.column;
31637 value = subvalue + value;
31638
31639 return result.position
31640 }
31641 }
31642 }
31643 }
31644

Callers 15

blankLineFunction · 0.70
indentedCodeFunction · 0.70
fencedCodeFunction · 0.70
blockquoteFunction · 0.70
atxHeadingFunction · 0.70
thematicBreakFunction · 0.70
listFunction · 0.70
setextHeadingFunction · 0.70
blockHtmlFunction · 0.70
definitionFunction · 0.70
tableFunction · 0.70
paragraphFunction · 0.70

Calls 7

getOffsetFunction · 0.85
positionFunction · 0.85
nowFunction · 0.85
validateEatFunction · 0.85
updatePositionFunction · 0.85
updateFunction · 0.85
sliceMethod · 0.80

Tested by

no test coverage detected