Giter Site home page Giter Site logo

yamadapc / cheapskate-terminal Goto Github PK

View Code? Open in Web Editor NEW
8.0 4.0 0.0 2.27 MB

Render markdown on the terminal. Ports msee from Node.js to Haskell using the cheapskate markdown parser.

License: BSD 3-Clause "New" or "Revised" License

Haskell 97.86% Makefile 2.14%

cheapskate-terminal's Introduction

cheapskate-terminal

Render markdown on the terminal. Ports msee from Node.js using the cheapskate markdown parser. Exposes a library and a command-line tool for doing so.

Basic highlighting

Installing

$ stack install cheapskate-terminal

Library Usage

The library exports:

prettyPrint :: Doc -> IO ()

Example usage:

import           Cheapskate
import           Cheapskate.Terminal
import qualified Data.Text.IO        as Text (readFile)

main = do
    tc <- Text.readFile "test-file"
    prettyPrint (markdown def tc)

Haskell Source code highlighting

Pygments highlighting

Performance considerations

It's a complete implementation, but it's very reasonably inefficient; since when printing to the terminal (even with multiple megabytes of data), most of the time is spent printing - not parsing/manipulating - it's roughly as efficient as the Node.js implementation; however, I did a bad job with this... Without terminal wrapping it was about 10-20% faster, with terminal wrapping it's doing stupid conversions and a lot of copying.

It'll be battle-tested soon, but it's enough to say that it serves it's purpouse. For the actual usecase of pretty-printing markdown to the terminal (not 20MB files for benchmarking), it's actually much faster than JavaScript because it doesn't need to boot an interpreter or load a bunch of code.

If you can write a wrapping function that operates over a Text.Builder you'll make it a whole lot faster (challenge accepted?). This actually took me quite a bit to get working, ANSI escape sequences get in the way of wrapping text, since they mess-up with your notion of length, unless you have a fancy abstraction or an escape sequence parser.

I tried implementing this with ansi-terminal-builder, but eventually settled for dropping windows support. There's a branch with the stash at that point.

License

This code is published under the MIT License.

cheapskate-terminal's People

Contributors

yamadapc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cheapskate-terminal's Issues

Text width wrapping

This is an important feature of the msee package that needs to be implemented.

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.