logo

Markdown Rendering Simplified

tests ai-integration-tests GitHub license codecov npm npm

Features

Table of Contents

Getting Started

> npm install writr
  

Then you can use it like this:

import { Writr } from 'writr';
  
  const writr = new Writr(`# Hello World ::-):\n\n This is a test.`);
  
  const html = await writr.render(); // 

Hello World 🙂

This is a test.

Its just that simple. Want to add some options? No problem.

import { Writr } from 'writr';
  const writr = new Writr(`# Hello World ::-):\n\n This is a test.`);
  const options  = {
  	emoji: false
  }
  const html = await writr.render(options); // 

Hello World ::-):

This is a test.

An example passing in the options also via the constructor:

import { Writr, WritrOptions } from 'writr';
  const writrOptions = {
    renderOptions: {
      emoji: true,
      toc: true,
      slug: true,
      highlight: true,
      gfm: true,
      math: true,
      mdx: true,
      rawHtml: false,
      caching: true,
    }
  };
  const writr = new Writr(`# Hello World ::-):\n\n This is a test.`, writrOptions);
  const html = await writr.render(options); // 

Hello World ::-):

This is a test.

API

new Writr(arg?: string | WritrOptions, options?: WritrOptions)

By default the constructor takes in a markdown string or WritrOptions in the first parameter. You can also send in nothing and set the markdown via .content property. If you want to pass in your markdown and options you can easily do this with new Writr('## Your Markdown Here', { ...options here}). You can access the WritrOptions from the instance of Writr. Here is an example of WritrOptions.

import { Writr, WritrOptions } from 'writr';
  const writrOptions = {
    renderOptions: {
      emoji: true,
      toc: true,
      slug: true,
      highlight: true,
      gfm: true,
      math: true,
      mdx: true,
      rawHtml: false,
      caching: true,
    }
  };
  const writr = new Writr(writrOptions);
  

.content

Setting the markdown content for the instance of Writr. This can be set via the constructor or directly on the instance and can even handle frontmatter.


  import { Writr } from 'writr';
  const writr = new Writr();
  writr.content = `---
  title: Hello World
  ---
  # Hello World ::-):\n\n This is a test.`;
  

.body

gets the body of the markdown content. This is the content without the frontmatter.

import { Writr } from 'writr';
  const writr = new Writr();
  writr.content = `---
  title: Hello World
  ---
  # Hello World ::-):\n\n This is a test.`;
  console.log(writr.body); // '# Hello World ::-):\n\n This is a test.'
  

.options

Accessing the default options for this instance of Writr. Here is the default settings for WritrOptions. These are the default settings for the WritrOptions:

{
    renderOptions: {
      emoji: true,
      toc: true,
      slug: true,
      highlight: true,
      gfm: true,
      math: true,
      mdx: false,
      rawHtml: false,
      caching: true,
    }
  }
  

By default, raw HTML in markdown (such as