Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
S

svelte-markdown

> 编程语言
Open source

Markdown parser to svelte components

389 stars0 likes0 views
WebsiteGitHub

About

Markdown parser to svelte components

Svelte Markdown

A markdown parser that renders into Svelte Components. Inspired by ReactMarkdown.

Installation

You can install it with

bash
$ npm i -S svelte-markdown

If you use npm or if you prefer yarn

bash
$ yarn add svelte-markdown

If you're using Sapper you might need to install it as a dev dependency.

Usage

xml

This would render something like

xml

This is a header

This is a paragraph.

  
This is a list

  

    With two items
    

      
And a sublist

      

        That is ordered
        

          
With another

          
Sublist inside

        

      

    

  

  
    

      And this is
      A table
    

  
  
    

      With two
      columns
    

  

Note

Just like with React Markdown, this package doesn't use {@html ...} unless you need to render HTML.

Props

The SvelteMarkdown component accepts the following props:

  • source - string or array The Markdown source to be parsed, or an array of tokens to be rendered directly.
  • renderers - object (optional) An object where the keys represent a node type and the value is a Svelte component. This object will be merged with the default renderers. For now you can check how the default renderers are written in the source code at src/renderers.
  • options - object (optional) An object containing options for Marked

Renderers

To create custom renderer for an element, you can create a Svelte component with the default props (you can check them here), for example:

ImageComponent.svelte

svelte

So you can import the component and pass to the renderers props:

svelte

Rendering From Tokens

For greater flexibility, an array of tokens may be given as source, in which case parsing is skipped and the tokens will be rendered directly. This alows you to generate and transform the tokens freely beforehand. Example:

xml

This will render the following:

xml

THIS IS AN EXAMPLE

Events

A parsed event will be fired when the final tokens have been calculated, allowing you to access the raw token array if needed for things like generating Table of Contents from headings.

xml

Available renderers

These would be the property names expected by the renderers option.

  • text - Text rendered inside of other elements, such as paragraphs
  • paragraph - Paragraph ( )
  • em - Emphasis (``)
  • strong - Strong/bold (``)
  • hr - Horizontal rule / thematic break ( )
  • blockquote - Block quote ( )
  • del - Deleted/strike-through (``)
  • link - Link (``)
  • image - Image (``)
  • table - Table (``)
  • tablehead - Table head (``)
  • tablebody - Table body (``)
  • tablerow - Table row ( )
  • tablecell - Table cell (/)
  • list - List ( / )
  • listitem - List item ( )
  • heading - Heading ( - )
  • codespan - Inline code (``)
  • code - Block of code (``)
  • html - HTML node

Optional List Renderers

For fine detail styling of lists, it can be useful to differentiate between ordered and un-ordered lists. If either key is missing, the default listitem will be used. There are two optional keys in the renderers option which can provide this:

  • orderedlistitem - A list item appearing inside an ordered list
  • unorderedlistitem A list item appearing inside an un-ordered list

As an example, if we have an orderedlistitem:

xml

Then numbers at the start of ordered list items would be colored blue. Bullets at the start of unordered list items would remain the default text color.

Inline Markdown

To use inline markdown, you can assign the prop isInline to the component.

xml

HTML rendering

While the most common flavours of markdown let you use HTML in markdown paragraphs, due to how Svelte handles plain HTML it is currently not possible to do this with this package. A paragraph must be either all HTML or all markdown.

markdown
This is a **markdown** paragraph.

This is an HTML paragraph

Note that the HTML paragraph must be enclosed within tags.

Developing

Some tests have been added to the tests folder. You can clone this repo and create another svelte app and link it to this repo to try modifying it.

You can clone this repo and do the following:

bash
$ yarn
$ yarn link
$ yarn dev

This will watch all changes and make the project linkable. Now on the app you created you can link it with:

bash
$ yarn link svelte-markdown

And then import it like in the example above.

As of now the only external dependency of this project is marked.

Related

  • ReactMarkdown - React library to render markdown using React components. Inspiration for this library.
  • Svelte - JavaScript front-end framework.
  • Marked - Markdown parser

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言