Giter VIP home page Giter VIP logo

minimark's Introduction

minimark

npm version

minimark is a Svelte library that render nodes from a string with markdown like tags.
The text is converted to nodes that are then displayed as Svelte components, without any html assignments.

You can find a demo with a live preview of the rendered text at http://minimark.nikurasu.org/.

Installation

pnpm add @glagan/minimark

How to use

You only need to use the <Minimark> component to render text:

<Minimark text="This will be renderer **in bold**" />

The generated node will be surrounded by a <div> by default, but you can use any tag you want by setting the tag props.

Tags

You can insert links, images and stylize text by using tags that resemble Markdown. Most of these tags can be nested to combine their effects.

Name Description CSS
Inline code ``code`` code
Header (h1) # Header 1\n
Header (h2) ## Header 2\n
Link {{title|http://www.example.org/}} or {{http://www.example.org/}} without title.
Image ![title|http://www.example.org/image.jpg] or ![http://www.example.org/image.jpg] without title.
Bold **http://www.example.org/** bold
Italic *http://www.example.org/* italic
Separator \n---\n separator
Float right >*>Text< float-right

Tags work by looking for an open token, an optional separator if there is a title, and the close token. If the tag can have a title you need to use | as the separator with the content.

You can add custom tags easily with the addTag(definition) function. A tag object can have the following properties:

import { addTag } from '@glagan/minimark';

addTag({
    tag: "span", // The node tag, e.g <span>
    classes: "class1 class2", // Optional classes as a string
    attributes: {
        name: "value"
    }, // Optional attributes to set
    textContent: "$content", // textContent of the created node, see below for variables
                             // If textContent is defined and not false the content cannot have childs (nested other tags)
							 // If textContent is set to false, it"s ignored (for self-closing tags)
    open: "{{", // The opening token - any length
    close: "}}" // The closing token - can be linebreak by using \n - can also be empty
});

Variables

There are two usable variables inside attribute values textContent and title:

  • $content: the content found between the open and close token, without the title if there is one.
  • $title: the title found, if there is none it is replaced by the same value as $content.

minimark's People

Contributors

glagan avatar

Watchers

 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.