Git Product home page Git Product logo

gfm-preview's Introduction

Usage

# install it
$ npm install --global gfm-preview

# preview your markdown
$ preview file.md

# preview with firefox
$ preview file.md --browser firefox

# preview with chrome on macOS
$ preview file.md --browser 'google chrome'

# preview custom host and port number
$ preview file.md --host yourhost --port 3333

# preview with GitHub Enterprise API
$ preview file.md --github-api-url https://your-ghe-host:port/api/v3

Feature

  • Render your markdown with GitHub API
  • Launch a local preview server (http://localhost:4649)
  • Hot reload previews when detecting changes
  • Close the server when the preview is closed
  • Support GitHub Enterprise

How to change default browser

The browser name is platform dependent. For example, Chrome is google chrome on macOS, google-chrome on Linux and chrome on Windows.

# with chrome on macOS
$ preview file.md --browser 'google chrome'

# with a custom executable
$ preview file.md --browser 'C:\\Program Files\\Mozilla Firefox\\firefox.exe'

If you use GitHub Enterprise (GHE)

Add an alias to your ~./bashrc:

alias preview='preview --github-api-url https://your-ghe-host:port/api/v3'

Then use it:

$ preview file.md

gfm-preview's People

Contributors

dependabot[bot] avatar saltyshiomix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

gnidan

gfm-preview's Issues

Newlines render incorrectly

Newlines do not (and have never) rendered correctly. If there is no full line gap between two paragraphs, the second just continues the first; GFM renders them as a full pressing of enter.

Add ability to set hostname for remote usage

Currently the app assumes that you're using localhost as your hostname. If you try to run it on a remote system, it loads but the HTML fails to pull in it's contents because it assumes everything is localhost. By changing the localhost value to another hostname, I was able to get it to work remotely. I would suggest that you do the same substitution that you do for <!--TITLE--> and allow the hostname to be passed in via the command line

Fails to run on Node.js v20.10.0

GFM was working fine (sans the rendering bugs), and then I updated my Node, to receive this error:

> gfm-preview: Ready on http://localhost:4649
/usr/local/lib/node_modules/gfm-preview/index.js:157
  watcher.on('change', () => {
          ^

TypeError: Cannot read properties of undefined (reading 'on')
    at Namespace.<anonymous> (/usr/local/lib/node_modules/gfm-preview/index.js:157:11)
    at Namespace.emit (node:events:514:28)
    at Namespace.emit (/usr/local/lib/node_modules/gfm-preview/node_modules/socket.io/lib/namespace.js:219:10)
    at /usr/local/lib/node_modules/gfm-preview/node_modules/socket.io/lib/namespace.js:190:12
    at process.processTicksAndRejections (node:internal/process/task_queues:77:11)

Node.js v20.10.0

It now fails to run.

Add github authentication to requests

(Hopefully my last request)

If you are in a host that hits github too frequently, you get rate limited. It would be nice to add the ability to set your github credentials. If there set, you can pass the credentials to the axios post like:

const config = {};
if (github_username === undefined) {
    config.auth = {
        username: github_username,
        password: github_password
    }
}
const response = await axios.post(apiUrl + '/markdown', { text, mode: 'gfm' }, config);

No error handling if axios call fails

If the axios call fails (for my example my IP address what rate limited for an unauthenticated request) no feedback is given. I think the code below should handle that case

try {
      const response = await axios.post(apiUrl + '/markdown', { text, mode: 'gfm' })
      content = response.data
} catch (e) {
      content = e.response.data.message
}

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.