Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/andycall/htmlflatten
- Owner: andycall
- Created: 2017-03-22T14:54:11.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-03-23T03:10:43.000Z (almost 8 years ago)
- Last Synced: 2024-10-19T04:31:20.526Z (3 months ago)
- Language: HTML
- Size: 51.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# htmlflatten
Flatten your html source, and generate json text dataThis 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);
```