Git Product home page Git Product logo

markdown-preview's Introduction

markdown-preview

A small react app to show the live preview of the markdown. Only supports text, links and headings for now.

Demo

Sample

Installation

  1. Clone the repository using git clone https://github/akarshit/markdown-preview.git
  2. Go in the cloned directory cd markdown-preview
  3. Install the dependency npm install
  4. Start the project with npm start
  5. Visit localhost:3000 to access the project

Usage

Type the markdown on the left hand input and see the live preview on the right. To see the raw HTML being generated use the switch button on the top-right. To switch back to preview, click the button again.

Note: The content is not saved. So if you refresh the content will be lost.

Approach

The initial idea was to implement a line by parser. This would have been much faster, but would hamper both the readability and extendibility of the code a lot.

Since the markdown has a structured grammer, it was easier and more cleaner to use regex to do to the conversion. The code is split into multiple parsers. Each of these parsers has a specific and modular task to do.

To make this process faster, the trick is that once we encounter \n\n, the markdown before is independent of the markdown after. So while reading a huge file we can process line by line until we encounter \n\n. These chucks can then be collated to return the complete HTML. Another advantage of this is that since the regex is now applied to smaller text, it is much faster.

The two functions are convert(markdown: string) and convertFast(markdown: string).

markdown-preview's People

Contributors

akarshit avatar

Watchers

 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.