0.1.0 • Published 7 years ago

recreate-element-inline v0.1.0

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

recreate-element-inline

Build an element simulating the other one.

Install

$ npm install recreate-element-inline

or copy the function inside the source file. There's only one function without any dependency.

Usage

var recreateElement = require('recreate-element-inline');
var option = {
    output: 'element'
};
var recreated = recreateElement(option)(element);
  • element:
  • option
    • output: string or element, deciding the format of return value, default element;
    • (not supported yet) keepID: boolean, deciding whether to keep the element IDs, default false;
    • (not supported yet) keepClass: boolean, deciding whether to keep the element classes, default false;
    • (not supported yet) XHTML: boolean, deciding whether to use XHTML output, default false;
    • (not supported yet) attributes: boolean, deciding whether to keep unnecessary attributes(necessary for the appearance), default false;

Why not Node.cloneNode()

The final look of result of Node.cloneNode() depends on its ancestor nodes and CSS classes, and the cloning may cause duplicated element ID.

How does it work

It simply iterate everything, copy the computed style and sum up recursively;

TODO

  • More node type support;
  • Better API;
  • Implement the APIs
  • Optimize speed;
  • Tests;