GithubHelp home page GithubHelp logo

rlugojr / hget Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bevacqua/hget

0.0 3.0 0.0 23 KB

:clap: Render websites in plain text from your terminal

Home Page: https://ponyfoo.com

JavaScript 10.40% HTML 89.60%

hget's Introduction

hget

npm version Build Status Coverage Status Dependency Status

Render websites in plain text from your terminal

A CLI and an API to convert HTML into plain text. Can be used to fetch a site's HTML version and convert it into plain text, or to deliver plain text versions of your site dynamically.

You can also convert HTML into HTML, ignoring certain document elements, and starting at a root element other than <html>. You can choose to take raw Markdown output as well, instead of the default terminal-formatted plain text.

Install

Globally or locally.

npm install hget --save
npm install hget -g

API

The API exports a function that takes in HTML and returns a formatted plain text string. It uses colors and formatting provided by chalk.

var hget = require('hget');
var html = '<p>Hello <b>Nico</b>!</p>';

hget(html);
// <- 'Hello Nico!'

You can also pass in a few options.

hget(html, options)

The options are as follows.

  • root sets the context root, it defaults to 'body'. Maybe you want to use 'main' or something akin to that.
  • ignore can be a single selector or an array of selectors. Any elements that match the provided selectors will be removed from the document before rendering the terminal-printable output. Keep in mind that these selectors will be rooted in the root element.
  • html means that you'll get HTML back, instead of the default human-readable terminal output
  • markdown means you'll get Markdown back, instead of the default human-readable terminal output

CLI

Easy and flexible to use!

hget ponyfoo.com
hget file.html
cat file.html | hget

Example usage

Ooh, the CLI also follows redirects.

hget ponyfoo.com/articles/last --root article --ignore footer,.mm-count,.at-meta

Also, the output will be paged using $PAGER for convenience. You can turn this off using --no-paging.

It works well on most sites. Here's just the news links from EchoJS.

hget echojs.com --root #newslist --ignore "article>:not(h2)"

echojs-output.png

License

MIT

hget's People

Contributors

adrieankhisbe avatar bevacqua avatar

Watchers

 avatar  avatar  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.