MCPcopy Create free account
hub / github.com/witheve/Eve / parseCloseBracket

Function parseCloseBracket

src/commonmark.js:1609–1727  ·  view source on GitHub ↗
(block)

Source from the content-addressed store, hash-verified

1607// to block's children. If there is a matching delimiter,
1608// remove it from the delimiter stack.
1609var parseCloseBracket = function(block) {
1610 var startpos;
1611 var is_image;
1612 var dest;
1613 var title;
1614 var matched = false;
1615 var reflabel;
1616 var opener;
1617
1618 this.pos += 1;
1619 startpos = this.pos;
1620
1621 // get last [ or ![
1622 opener = this.brackets;
1623
1624 if (opener === null) {
1625 // no matched opener, just return a literal
1626 block.appendChild(text(']'));
1627 return true;
1628 }
1629
1630 if (!opener.active) {
1631 // no matched opener, just return a literal
1632 block.appendChild(text(']'));
1633 // take opener off brackets stack
1634 this.removeBracket();
1635 return true;
1636 }
1637
1638 // If we got here, open is a potential opener
1639 is_image = opener.image;
1640
1641 // Check to see if we have a link/image
1642
1643 // Inline link?
1644 if (this.peek() === C_OPEN_PAREN) {
1645 this.pos++;
1646 if (this.spnl() &&
1647 ((dest = this.parseLinkDestination()) !== null) &&
1648 this.spnl() &&
1649 // make sure there's a space before the title:
1650 (reWhitespaceChar.test(this.subject.charAt(this.pos - 1)) &&
1651 (title = this.parseLinkTitle()) || true) &&
1652 this.spnl() &&
1653 this.peek() === C_CLOSE_PAREN) {
1654 this.pos += 1;
1655 matched = true;
1656 }
1657 } else {
1658
1659 // Next, see if there's a link label
1660 var savepos = this.pos;
1661 var beforelabel = this.pos;
1662 var n = this.parseLinkLabel();
1663 if (n > 2) {
1664 reflabel = this.subject.slice(beforelabel, beforelabel + n);
1665 } else if (!opener.bracketAfter) {
1666 // Empty or missing second label means to use the first label as the reference.

Callers

nothing calls this directly

Calls 3

textFunction · 0.85
peekMethod · 0.80
testMethod · 0.45

Tested by

no test coverage detected