index.js
function _list (str, isOrdered) {
  if (!str) return str;

  var $ = cheerio.load(str);
  var listEl = isOrdered ? 'ol' : 'ul';

  $(listEl).each(function (i, el) {
    var $out = cheerio.load('<p></p>');
    var $el = $(el);

    $el.find('li').each(function (j, li) {
      var tick = isOrdered ? String(j + 1) + '.' : '-';

      $out('p').append(tick + ' ' + _escapeHtml($(li).text()) + '<br />');
    });

    // avoid excess spacing coming off last element
    // (we are wrapping with a <p> anyway)
    $out('br').last().remove();

    $el.replaceWith($out.html());
  });

  return $.html();
}
function _list (str, isOrdered) {
  if (!str) return str;

  var $ = cheerio.load(str);
  var listEl = isOrdered ? 'ol' : 'ul';

  $(listEl).each(function (i, el) {
    var $out = cheerio.load('<p></p>');
    var $el = $(el);

    $el.find('li').each(function (j, li) {
      var tick = isOrdered ? String(j + 1) + '.' : '-';

      $out('p').append(tick + ' ' + _escapeHtml($(li).text()) + '<br />');
    });

    // avoid excess spacing coming off last element
    // (we are wrapping with a <p> anyway)
    $out('br').last().remove();

    $el.replaceWith($out.html());
  });

  return $.html();
}
function _list ( str , isOrdered ) { if ( ! str ) return str ; var $ = cheerio . load ( str ) ; var listEl = isOrdered ? 'ol' : 'ul' ; $ ( listEl ) . each ( function ( i , el ) { var $out = cheerio . load ( '<p></p>' ) ; var $el = $ ( el ) ; $el . find ( 'li' ) . each ( function ( j , li ) { var tick = isOrdered ? String ( j + 1 ) + '.' : '-' ; $out ( 'p' ) . append ( tick + ' ' + _escapeHtml ( $ ( li ) . text ( ) ) + '<br />' ) ; } ) ; // avoid excess spacing coming off last element // (we are wrapping with a <p> anyway) $out ( 'br' ) . last ( ) . remove ( ) ; $el . replaceWith ( $out . html ( ) ) ; } ) ; return $ . html ( ) ; }
"private" helper for list processing into plaintext
private helper for list processing into plaintext