{{ s|nl2br }}

    Convert newlines into <p> and <br />s.
350250
def nl2br(s):
    
    if not isinstance(s, basestring):
        s = str(s)
    s = re.sub(r'\r\n|\r|\n', '\n', s)
    paragraphs = re.split('\n{2,}', s)
    paragraphs = ['<p>%s</p>' % p.strip().replace('\n', '<br />') for p in paragraphs]
    return '\n\n'.join(paragraphs)
1019397
def add_newlines(tree):
    
    for br in tree.xpath("*//br"):
        br.tail = u"\n" + br.tail if br.tail else u"\n"
567255
def lines(text):
    
    assert text is not None
    assert '\r' not in text
    previous_newline_index = 0
    newline_index = text.find('\n')
    while newline_index != -1:
        yield text[previous_newline_index:newline_index]
        previous_newline_index = newline_index + 1
        newline_index = text.find('\n', previous_newline_index)
    last_line = text[previous_newline_index:]
    if last_line != '':
        yield last_line
24516
function(str, indent) {
			var lines = str.split("\n");
			for (var i=0; i<lines.length; i++)
				lines[i] = indent + lines[i];
			return lines.join("\n");
		}
207308
function breaklines () {
  return through2.obj(function (chunk, _, cb) {
    String(chunk)
      .split('\n')
      .filter(Boolean)
      .forEach(line => this.push(line))
    cb()
  })
}
566670
def _LineWrap(text, width):
    
    return reduce(lambda line, word, width=width: '%s%s%s' %
                  (line,
                   ' \n'[(len(line) - line.rfind('\n') - 1 +
                         len(word.split('\n', 1)[0]) >= width)],
                   word),
                  text.split(' ')
                 )
1183535
def _convert_to_spans(self, tree, start, set, parent = None): 
        "" 
        if len(tree) == 3:
            # Binary rule.
            # Remove unary collapsing.
            current = self._remove_vertical_markovization(tree[0]).split("+")
            split = self._convert_to_spans(tree[1], start, set, None)
            end = self._convert_to_spans(tree[2], split + 1, set, current[-1])
            
            # Add phrases to set
            if current[0] != parent: 
                set.add((current[0], start, end))
            for nt in current[1:]:
                set.add((nt, start, end))
            return end
        
        elif len(tree) == 2:
            # Unary rule.
            
            # Can have a constituent if it is collapsed.
            current = self._remove_vertical_markovization(tree[0]).split("+")
            for nt in current[:-1]:
                set.add((nt, start, start))
            return start
959142
function toCookedString(s) {
  let sb = ['"'];
  let i = 0, k = 1, c, c2;
  while (i < s.length) {
    c = s[i++];
    switch (c) {
      case '\\':
        c2 = s[i++];
        switch (c2) {
          // Strip line continuation.
          case '\n':
          case '\u2028':
          case '\u2029':
            break;
          case '\r':
            // \ \r \n should be stripped as one
            if (s[i + 1] === '\n') {
              i++;
            }
            break;

          default:
            sb[k++] = c;
            sb[k++] = c2;
        }
        break;

      // Since we wrap the string in " we need to escape those.
      case '"':
        sb[k++] = '\\"';
        break;

      // Whitespace
      case '\n':
        sb[k++] = '\\n';
        break;
      // <CR><LF> and <CR> LineTerminatorSequences are normalized to <LF>
      // for both TV and TRV.
      case '\r':
        if (s[i] === '\n')
          i++;
        sb[k++] = '\\n';
        break;
      case '\t':
        sb[k++] = '\\t';
        break;
      case '\f':
        sb[k++] = '\\f';
        break;
      case '\b':
        sb[k++] = '\\b';
        break;
      case '\u2028':
        sb[k++] = '\\u2028';
        break;
      case '\u2029':
        sb[k++] = '\\u2029';
        break;

      default:
        sb[k++] = c;
    }
  }

  sb[k++] = '"';
  return sb.join('');
}
1028770
function normalizeBlocks(input) {

    var numberOfLinesToIndent = 0;
    var thisLineContainsStuff = false;
    var thisLinesIndentation = '';
    var out = '';

    for (var i = 0; i < input.length; i++) {

        var chr = input[i];

        if (chr == '\r') {
            continue;
        }

        if (chr === '\n') {
            if (!thisLineContainsStuff) {
                numberOfLinesToIndent++;
            } else {
                out += '\n';
            }

            thisLineContainsStuff = false;
            thisLinesIndentation = '';
            continue;
        }

        if (!thisLineContainsStuff && (chr === ' ' || chr === '\t')) {
            thisLinesIndentation += chr;
            continue;
        }

        if (chr !== ' ' || chr !== '\t') {

            if (!thisLineContainsStuff) {
                for (var j = 0; j < numberOfLinesToIndent; j++) {
                    out += thisLinesIndentation + '\n';
                }

                out += thisLinesIndentation + chr;
            } else {
                out += chr;
            }

            numberOfLinesToIndent = 0;
            thisLineContainsStuff = true;

        }

    }

    return out;

}
614316
def parselinenos(spec, nlines=None):
    

    items = {}
    parts = spec.split(',')

    for part in parts:
        line_class = LINECLASS_RE.match(part)
        start = int(line_class.group('start'))

        if line_class.group('range'):
            if line_class.group('end'):
                end = int(line_class.group('end'))
            else:
                end = nlines

            for line_no in range(start, end + 1):
                items[line_no] = line_class.group('class')

        else:
            items[start] = line_class.group('class')

    return items
1238815
function(n_newlines) {
				if('number' === typeof n_newlines) {
					for(let i=0; i<n_newlines; i++) {
						a_chunks.push('');
					}
				}
				else {
					a_chunks.push('');
				}
			}
1012743
function(lines) {
		let output = [];
		let newlineCount = 0;
		for (let i = 0; i < lines.length; i++) {
			const line = lines[i];
			if (!line.trim()) {
				newlineCount++;
			} else {
				newlineCount = 0;
			}

			if (newlineCount >= 2) continue;

			output.push(line);
		}
		return output;
	}
1186587
function wrap(str, lineLength) {
    str = (str || '').toString();
    lineLength = lineLength || 76;

    if (str.length <= lineLength) {
        return str;
    }

    let result = [];
    let pos = 0;
    let chunkLength = lineLength * 1024;
    while (pos < str.length) {
        let wrappedLines = str
            .substr(pos, chunkLength)
            .replace(new RegExp('.{' + lineLength + '}', 'g'), '$&\r\n')
            .trim();
        result.push(wrappedLines);
        pos += chunkLength;
    }

    return result.join('\r\n').trim();
}
447082
function makeSeparator(state, sep, nlConstraints) {
	var origSep = sep;

	// Split on comment/ws-only lines, consuming subsequent newlines since
	// those lines are ignored by the PHP parser
	// Ignore lines with ws and a single comment in them
	var splitReString = [
		'(?:\n(?:[ \t]*?',
		Util.COMMENT_REGEXP.source,
		'[ \t]*?)+(?=\n))+|',
		Util.COMMENT_REGEXP.source,
	].join('');
	var splitRe = new RegExp(splitReString);
	var sepMatch = sep.split(splitRe).join('').match(/\n/g);
	var sepNlCount = sepMatch && sepMatch.length || 0;
	var minNls = nlConstraints.min || 0;

	if (state.atStartOfOutput && minNls > 0) {
		// Skip first newline as we are in start-of-line context
		minNls--;
	}

	if (minNls > 0 && sepNlCount < minNls) {
		// Append newlines
		var nlBuf = [];
		for (var i = 0; i < (minNls - sepNlCount); i++) {
			nlBuf.push('\n');
		}

		/* ------------------------------------------------------------------
		 * The following two heuristics try to do a best-guess on where to
		 * add the newlines relative to nodeA and nodeB that best matches
		 * wikitext output expectations.
		 *
		 * 1. In a parent-child separator scenario, where the first child of
		 *    nodeA is not an element, it could have contributed to the separator.
		 *    In that case, the newlines should be prepended because they
		 *    usually correspond to the parent's constraints,
		 *    and the separator was plucked from the child.
		 *
		 *    Try html2wt on this snippet:
		 *
		 *    a<p><!--cmt-->b</p>
		 *
		 * 2. In a sibling scenario, if nodeB is a literal-HTML element, nodeA is
		 *    forcing the newline and hence the newline should be emitted right
		 *    after it.
		 *
		 *    Try html2wt on this snippet:
		 *
		 *    <p>foo</p>  <p data-parsoid='{"stx":"html"}'>bar</p>
		 * -------------------------------------------------------------------- */
		var constraintInfo = nlConstraints.constraintInfo || {};
		var sepType = constraintInfo.sepType;
		var nodeA = constraintInfo.nodeA;
		var nodeB = constraintInfo.nodeB;
		if (sepType === 'parent-child' &&
				!DOMUtils.isContentNode(DOMUtils.firstNonDeletedChild(nodeA)) &&
				!(Consts.HTML.ChildTableTags.has(nodeB.nodeName) &&
					!WTUtils.isLiteralHTMLNode(nodeB))) {
			sep = nlBuf.join('') + sep;
		} else if (sepType === 'sibling' && WTUtils.isLiteralHTMLNode(nodeB)) {
			sep = nlBuf.join('') + sep;
		} else {
			sep += nlBuf.join('');
		}
	} else if (nlConstraints.max !== undefined && sepNlCount > nlConstraints.max) {
		// Strip some newlines outside of comments
		// Capture separators in a single array with a capturing version of
		// the split regexp, so that we can work on the non-separator bits
		// when stripping newlines.
		var allBits = sep.split(new RegExp('(' + splitReString + ')'));
		var newBits = [];
		var n = sepNlCount;

		while (n > nlConstraints.max) {
			var bit = allBits.pop();
			while (bit && bit.match(splitRe)) {
				// skip comments
				newBits.push(bit);
				bit = allBits.pop();
			}
			while (n > nlConstraints.max && bit.match(/\n/)) {
				bit = bit.replace(/\n([^\n]*)/, '$1');
				n--;
			}
			newBits.push(bit);
		}
		newBits.reverse();
		newBits = allBits.concat(newBits);
		sep = newBits.join('');
	}

	state.env.log("debug/wts/sep", 'make-new   |', function() {
		var constraints = Util.clone(nlConstraints);
		constraints.constraintInfo = undefined;
		return JSON.stringify(sep) + ", " +
			JSON.stringify(origSep) + ", " +
			minNls + ", " + sepNlCount + ", " + JSON.stringify(constraints);
	});

	return sep;
}
76215
function parseLines(lines) {
        var propertyMap = {};
        lines.forEach(function (line) {
            var parsed = parseLine(line);
            if (!parsed) {
                throw new Error('Cannot parse line: ', line);
            }
            propertyMap[parsed[1]] = parsed[2];
        });
        return propertyMap;
    }
1078797
function (s) {
		return s.replace(re_NewLine, NewLine).replace(re_quot, quot).replace(re_apos, apos).replace(re_acute, acute).replace(re_sbquo, sbquo).replace(re_bdquo, bdquo).replace(re_hellip, hellip).replace(re_dagger, dagger).replace(re_Dagger, Dagger).replace(re_lsquo, lsquo).replace(re_rsquo, rsquo).replace(re_ldquo, ldquo).replace(re_rdquo, rdquo).replace(re_bull, bull).replace(re_ndash, ndash).replace(re_mdash, mdash).replace(re_copy, copyright_mark).replace(re_nbsp, nbsp).replace(re_laquo, laquo).replace(re_raquo, raquo);
	}
1206470
function splitNewlines(str) {
	if ((typeof str === 'string' || str instanceof String) && str.indexOf('\n') > -1) {
		return str.split('\n');
	}
	return str;
}