function processHtml(source, bookmark, method) {
    const $ = cheerio.load(source);
    let text = null;
    switch (method) {
      case 'story':
        text = $(`a[name="${bookmark}"]`)
          .parent()
          .parent()
          .nextUntil('hr', 'p');
        break;
      case 'story2':
        text = $(`a[name="${bookmark}"]`)
          .parent()
          .next()
          .next()
          .nextUntil('h2', 'p');
        break;
      case 'book1':
        text = $(`a[name="${bookmark}"]`)
          .parent()
          .next()
          .nextUntil('div', 'p');
        break;
      case 'book2':
        text = $(`a[name="${bookmark}"]`)
          .parent()
          .nextUntil('h3', 'p');
        break;
      case 'book3':
        text = $(`a[name="${bookmark}"]`)
          .next()
          .next()
          .nextUntil('h3', 'p');
        break;
      default:
        throw new Error(`Unknown method: ${method}`);
    }
    let v = text.eq(1);
    // console.log(v.text());
    return text.map(function(i, el) {
      const p = $(this)
        .text()
        .replace(/\s+/g,' ') // Collapse spaces
        .replace(/[“”"]/g,'') // Remove quotes
        .trim(); // remove leading and trailing spaces
      return {
        paragraph: i + 1,
        text: (p) ? tokenizer.sentences(p) : null
      };
    }).get();
}
/**
 * Turn HTML body into an array of paragraphs of text.
 * @param source The HTML page body
 * @param bookmark The bookmark id used to find the text.
 * @param method The predefined method used to isolate the text.
 * @return An array of paragraph objects {paragraph: #, text: []}
 */
Turn HTML body into an array of paragraphs of text.
@param source The HTML page body
@param bookmark The bookmark id used to find the text.
@param method The predefined method used to isolate the text.
@return An array of paragraph objects {paragraph: #, text: []}
Turn HTML body into an array of paragraphs of text . @param source The HTML page body @param bookmark The bookmark id used to find the text . @param method The predefined method used to isolate the text . @return An array of paragraph objects { paragraph : # text : [] }
function processHtml(source, bookmark, method) {
    const $ = cheerio.load(source);
    let text = null;
    switch (method) {
      case 'story':
        text = $(`a[name="${bookmark}"]`)
          .parent()
          .parent()
          .nextUntil('hr', 'p');
        break;
      case 'story2':
        text = $(`a[name="${bookmark}"]`)
          .parent()
          .next()
          .next()
          .nextUntil('h2', 'p');
        break;
      case 'book1':
        text = $(`a[name="${bookmark}"]`)
          .parent()
          .next()
          .nextUntil('div', 'p');
        break;
      case 'book2':
        text = $(`a[name="${bookmark}"]`)
          .parent()
          .nextUntil('h3', 'p');
        break;
      case 'book3':
        text = $(`a[name="${bookmark}"]`)
          .next()
          .next()
          .nextUntil('h3', 'p');
        break;
      default:
        throw new Error(`Unknown method: ${method}`);
    }
    let v = text.eq(1);
    return text.map(function(i, el) {
      const p = $(this)
        .text()
        .replace(/\s+/g,' ') 
        .replace(/[“”"]/g,'') // R
        .trim(); 
      return {
        paragraph: i + 1,
        text: (p) ? tokenizer.sentences(p) : null
      };
    }).get();
}
function processHtml ( source , bookmark , method ) { const $ = cheerio . load ( source ) ; let text = null ; switch ( method ) { case 'story' : text = $ ( ` ${ bookmark } ` ) . parent ( ) . parent ( ) . nextUntil ( 'hr' , 'p' ) ; break ; case 'story2' : text = $ ( ` ${ bookmark } ` ) . parent ( ) . next ( ) . next ( ) . nextUntil ( 'h2' , 'p' ) ; break ; case 'book1' : text = $ ( ` ${ bookmark } ` ) . parent ( ) . next ( ) . nextUntil ( 'div' , 'p' ) ; break ; case 'book2' : text = $ ( ` ${ bookmark } ` ) . parent ( ) . nextUntil ( 'h3' , 'p' ) ; break ; case 'book3' : text = $ ( ` ${ bookmark } ` ) . next ( ) . next ( ) . nextUntil ( 'h3' , 'p' ) ; break ; default : throw new Error ( ` ${ method } ` ) ; } let v = text . eq ( 1 ) ; return text . map ( function ( i , el ) { const p = $ ( this ) . text ( ) . replace ( / \s+ / g , ' ' ) . replace ( / [“”"]/g,' ' ) // . trim ( ) ; return { paragraph : i + 1 , text : ( p ) ? tokenizer . sentences ( p ) : null } ; } ) . get ( ) ; }
Turn HTML body into an array of paragraphs of text.
Turn HTML body into an array of paragraphs of text .
// console.log(v.text()); // Collapse spaces emove quotes // remove leading and trailing spaces