GithubHelp home page GithubHelp logo

pratt3351 / clean-html-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from j-mendez/clean-html-js

0.0 0.0 0.0 257 KB

convert a url or html into a readability object

License: MIT License

TypeScript 100.00%

clean-html-js's Introduction

clean-html-js

CircleCI

clean html content for reading. simply pass in your content as html and get a readability object

Installation Instructions

$ yarn add clean-html-js

Example

iOS and android apps being parsed into readability views using the clean-html-js and react-native-reader package

import cleanHtml from "clean-html-js";

const url = "https://www.a11ywatch.com";

async function grabReaderData() {
  const source = await fetch(url);
  const html = await source.text();
  return await cleanHtml(html, url);
}

async function grabReaderDataSimple() {
  return await cleanHtml("", url);
}

grabReaderData().then((data) => {
  console.log(data);
});

// or just the url
grabReaderDataSimple().then((data) => {
  console.log(data);
});

Available Params

param default type description
html "" string Required: html string to parse
sourceUrl "" string Optional: url of the html source to prevent fetching extra resources
config {} Config Optional: config object

If html is not provided and sourceUrl is found an attempt to fetch the html is done.

Config

merges with config

prop default type description
allowedTags null array of strings html elements allowed note:(svgs must be inlined)
nonTextTags null array of strings html elements that should not be treated as text

Testing

to test custom pages pass in your params seperated by commas into the jest test example yarn jest '-params=mozilla,https://www.mozilla.com' or yarn jest '-params=a11ywatch,https://www.a11ywatch.com'. First param is the html file being pulled from the examples folder and the second is an optional uri for the resources.

  1. npm test

clean-html-js's People

Contributors

j-mendez avatar pratt3351 avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.