Code Monkey home page Code Monkey logo

svelte-preprocess-markdown's Introduction

svelte-preprocess-markdown

Allows to import *.md files as Svelte component. Very useful when your components have a lot of formatted texts and you doesn't want to write it in HTML. It is based on superfast Marked markdown parser.

npm npm

Documentaton

  • Please, see the Docs for more info
  • Or try yourself in the our Playground

Installation

Install package:

npm i -D svelte-preprocess-markdown

Then, edit rollup.config.js file:

// 1. import package
const {markdown} = require('svelte-preprocess-markdown');

export default {
  // ...
  plugins: [
    svelte({
      // 2. add '.md', to the extensions  
      extensions: ['.svelte','.md'],
      // 3. add markdown preprocessor
      preprocess: markdown()
    })
  ]
}

Usage

Common usage

<script>
    import Child from './Child.svelte';
    let name = 'world';
</script>

# Hello {name}!

This is text in `markdown` **notation**

<Child />

<style>
    h1{
        color:red
    }
</style>

MDSv usage

The MDSv format is MDX-like way to write documents using imported Svelte-components.

import Block from './Block.svelte';
import { data } from './my_data.js';

# The MDSv example

You can use *components* and a *logic* inside doc:

<Block color="red">
  My `data` list:
  {#each data as item}
    {item}
  {/each}
</Block>

Options

You can pass any options that accepts Marked.

...
plugins: [
    svelte({
      ...
      preprocess: markdown({
          headerIds: false
      })
      ...
    })
  ]
...

Renderer

If you need renderer object for options, you can get it from the package:

const {Renderer} = require('svelte-preprocess-markdown');

const renderer = Renderer();

renderer.heading = function (text, level) {
    ...
};

const options = {renderer};

svelte-preprocess-markdown's People

Contributors

alexxnb avatar dependabot[bot] 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.