Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/andycall/htmlflatten

Flatten your html source, and generate json text data
https://github.com/andycall/htmlflatten

Last synced: 23 days ago
JSON representation

Flatten your html source, and generate json text data

Awesome Lists containing this project

README

        

# htmlflatten
Flatten your html source, and generate json text data

This Project is still under development

## Platform
written based on DOM3 API
so this project can be running in most Browser environment or jsdom.

## What is Used To be
If we have some html code
```html


helloworld



text
text3
text4

1234567890
2333333




wwwww
12323
1232323
213123123


```
Without CSS Stylesheets, This code should looking like this:

![image](https://cloud.githubusercontent.com/assets/4409743/24209325/e1985ab4-0f60-11e7-9b24-e2297e3c01a9.png)

This Project can help to generate json with data and keep the newline of the text;

```javascript
{ image_num: 1,
items:
[ { type: 'text', data: 'helloworld' },
{ type: 'text', data: 'text\n text3\n text4' },
{ type: 'text', data: '1234567890' },
{ type: 'text', data: '2333333' },
{ type: 'image',
data: { src: 'https://avatars3.githubusercontent.com/u/4409743?v=3&s=460' } },
{ type: 'text', data: 'wwwww123231232323\n213123123' },
[length]: 6 ] }
```

## How to Use

```javascript
let jsdom = require('jsdom');
let html = `


helloworld



text
text3
text4

1234567890
2333333




wwwww
12323
1232323
213123123


`

let document = jsdom(html, {
features: {
FetchExternalResources: false,
ProcessExternalResources: false
}
});
let DOMParser = require('htmlflatten');
let parser = new DOMParser(document.body);
let json = parser.toJSON();

console.log(json);
```