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

Function parseString

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

Source from the content-addressed store, hash-verified

1756// Parse a run of ordinary characters, or a single character with
1757// a special meaning in markdown, as a plain string.
1758var parseString = function(block) {
1759 var m;
1760 if ((m = this.match(reMain))) {
1761 if (this.options.smart) {
1762 block.appendChild(text(
1763 m.replace(reEllipses, "\u2026")
1764 .replace(reDash, function(chars) {
1765 var enCount = 0;
1766 var emCount = 0;
1767 if (chars.length % 3 === 0) { // If divisible by 3, use all em dashes
1768 emCount = chars.length / 3;
1769 } else if (chars.length % 2 === 0) { // If divisible by 2, use all en dashes
1770 enCount = chars.length / 2;
1771 } else if (chars.length % 3 === 2) { // If 2 extra dashes, use en dash for last 2; em dashes for rest
1772 enCount = 1;
1773 emCount = (chars.length - 2) / 3;
1774 } else { // Use en dashes for last 4 hyphens; em dashes for rest
1775 enCount = 2;
1776 emCount = (chars.length - 4) / 3;
1777 }
1778 return "\u2014".repeat(emCount) + "\u2013".repeat(enCount);
1779 })));
1780 } else {
1781 block.appendChild(text(m));
1782 }
1783 return true;
1784 } else {
1785 return false;
1786 }
1787};
1788
1789// Parse a newline. If it was preceded by two spaces, return a hard
1790// line break; otherwise a soft line break.

Callers

nothing calls this directly

Calls 2

textFunction · 0.85
matchMethod · 0.80

Tested by

no test coverage detected