htmlsplitter

0.1.4 • Public • Published

Usage

You need html content to split into DOM node :

$.get('contentHTML.html',function(data){
        alltext = $(document.createElement('HTML')).html(data)[0];
        ...

      });

Get content from start DOM to first result of needle

  var result = document.createElement('div');
  HtmlSplitter.splitTo(alltext.querySelector('body'), result, "#chapter1_3");

Get content from needle1 to needle2, excluding content of node with needle2

  var result2 = document.createElement('div');
  HtmlSplitter.splitFromTo(alltext.querySelector('body'), result2, "#chapter1_3", "#chapter1_3_2");

To get content from needle to last node you can omit needle2

  var result3 = document.createElement('div');
  HtmlSplitter.splitFromTo(alltext.querySelector('body'), result3, "#chapter1_4_1");
      });

Api

HtmlSplitter.splitFromTo(orig,dest,needle)

Create a orig content copy from first orig node to needle.

@param {Node} orig Dom node with content to split

@param {Node} dest Destination to result. Usually will be Document Fragment

@param {String} needle End selector.

HtmlSplitter.splitTo(orig,firstidentifier,lastidentifier)

Create a orig content copy from startid node orig node to endid node.

If endid is same orig then this function return content from startid to end orig

@param {node} orig Dom node with content to split

@param {Node} dest Destination to result. Usually will be Document Fragment

@param {string} startid Start node selector

@param {string} endid End node selector

HtmlSplitter.searchCommonParent(orig,firstidentifier,lastidentifier)

Search common parent between two nodes from orig

@param {node} orig Dom node with content to search

@param {String} firstidentifier First identifier to search parent

@param {String} lastidentifier Second identifier to search parent

@return {Node} Common parent

Readme

Keywords

Package Sidebar

Install

npm i htmlsplitter

Weekly Downloads

1

Version

0.1.4

License

GPL3

Last publish

Collaborators

  • raurodse