marked-vars

a marked compiler with accessible variables

Usage no npm install needed!

<script type="module">
  import markedVars from 'https://cdn.skypack.dev/marked-vars';
</script>

README

Marked Vars

A markdown compiler with accessible variables.

This package depends on marked compiler because it's popular and effecient.

All the features in marked is accessible the only difference is the variables

Documentation

Installation

NPM

$ npm i marked-vars

Unpkg

<script src="https://unpkg.com/marked-vars"></script>

Usage

To assign a variable:

This is just like a javascript object, basic expressions will work

---vars
title: "Variables",
date: new Date().toDateString(),
age: 1 + 2 + 4,
name: "Cris"
---

# @(title) -> "Variables"
The date is @(date) -> Date Today
My name is @(name) -> "Cris"
My age is @(age) -> 7

You need to put the variables at the very top of the file To Access the variables you need to warap it on @(variable-name) as you can see on the example

import markedVars from 'marked-vars'

const markdown = `
---vars
title: "Marked Vars"

--- \n # @(title)
`

const compiled = markedVars(markdown)

compiled.html //-> "<h1 id='marked-vars'>Marked Vars</h1>"

compiled.vars //-> { title: "Marked Vars" }

Changing the delimeter

It's a open and closing tag to match of the variables

default: ["---vars","----"]

markedVars(markdown, { delims: ['---', '---'] })

Converting to marked vars

markedVars.convertToMarkdown(variables, markdown, delims)

variables: object

markdown: string

delims?: [string,string]

markedVars.convertToMarkdown(
  {
    title: 'Marked-Vars',
  },
  '# Hello world',
)
/*
  return `
  ---vars
  title: "Marked Vars"
  ---
  # Hello world
  `