Socket
Socket
Sign inDemoInstall

markio

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    markio

A custom Markdown rendering package for Express


Version published
Weekly downloads
3
increased by50%
Maintainers
1
Install size
3.99 kB
Created
Weekly downloads
 

Readme

Source

Markio

npm dependents install size Downloads NPM Version run on repl.it

Markio is a custom Markdown rendering package for Express that can handle Markdown input from a file or a block of text in the main file.

Installation

You can install Markio using NPM:

npm install markio

Usage To use Markio in an Express application, first require the package and add the markioMiddleware middleware to your application:

const express = require("express");
const markio = require("markio");

const app = express();

app.use(markio.markioMiddleware);

app.get("/", (req, res) => {
  res.locals.data = "# Hello, world!";
  res.send(markio.renderMarkdown(res.locals.data));
});

app.get("/file", (req, res) => {
  res.locals.data = { filename: "example.md" };
  const markdown = "## " + fs.readFileSync(res.locals.data.filename, "utf8");
  res.send(markio.renderMarkdown(markdown));
});

app.listen(3000, () => {
  console.log("Server listening on port 3000");
});

In this example, we're setting the data variable in res.locals to a Markdown string in the "/" route handler, while in the "/file" route handler, we're setting it to an object with a filename property that points to a Markdown file.

When the markioMiddleware middleware is called for a GET request with the format query parameter set to md, it will check the type of res.locals.data and render the corresponding Markdown input.

API

Markio exports two functions:

renderMarkdown(input: string): string

Renders the given Markdown input string and returns the resulting HTML string.

markioMiddleware(req: Request, res: Response, next: NextFunction): void

Express middleware that checks if the format query parameter is set to md and renders the corresponding Markdown input in the response. If res.locals.data is a string, it is assumed to contain Markdown input. If it is an object with a filename property, the contents of the file with the specified filename are read and assumed to contain Markdown input. If res.locals.data is not a string or an object with a filename property, the next middleware in the chain is called.

License

Markio is released under the ISC License. See LICENSE for details.

Keywords

FAQs

Last updated on 31 Mar 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc