在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):pablo-abc/svelte-markdown开源软件地址(OpenSource Url):https://github.com/pablo-abc/svelte-markdown开源编程语言(OpenSource Language):JavaScript 64.5%开源软件介绍(OpenSource Introduction):Svelte MarkdownA markdown parser that renders into Svelte Components. Inspired by ReactMarkdown. InstallationYou can install it with $ npm i -S svelte-markdown If you use npm or if you prefer yarn $ yarn add svelte-markdown If you're using Sapper you might need to install it as a dev dependency. Usage<script>
import SvelteMarkdown from 'svelte-markdown'
const source = `
# This is a header
This is a paragraph.
* This is a list
* With two items
1. And a sublist
2. That is ordered
* With another
* Sublist inside
| And this is | A table |
|-------------|---------|
| With two | columns |`
</script>
<SvelteMarkdown {source} /> This would render something like <h1>This is a header</h1>
<p>This is a paragraph.</p>
<ul>
<li>This is a list</li>
<li>
With two items
<ol start="1">
<li>And a sublist</li>
<li>
That is ordered
<ul>
<li>With another</li>
<li>Sublist inside</li>
</ul>
</li>
</ol>
</li>
</ul>
<table>
<thead>
<tr>
<th>And this is</th>
<th>A table</th>
</tr>
</thead>
<tbody>
<tr>
<td>With two</td>
<td>columns</td>
</tr>
</tbody>
</table> NoteJust like with React Markdown, this package doesn't use OptionsThe SvelteMarkdown component accepts the following options:
Rendering From TokensFor greater flexibility, an array of tokens may be given as <script>
import SvelteMarkdown from 'svelte-markdown'
import { marked } from 'marked'
const tokens = marked.lexer('this is an **example**')
marked.walkTokens(tokens, token=> {
if (token.type == 'strong') token.type = 'em'
token.raw = token.raw.toUpperCase()
})
</script>
<SvelteMarkdown source={tokens} /> This will render the following: <p>THIS IS AN <em>EXAMPLE</em></p> EventsA <script>
import SvelteMarkdown from 'svelte-markdown'
const source = `# This is a header`
function handleParsed(event) {
//access tokens via event.detail.tokens
console.log(event.detail.tokens);
}
</script>
<SvelteMarkdown {source} on:parsed={handleParsed}> Available renderersThese would be the property names expected by the
Optional List RenderersFor fine detail styling of lists, it can be useful to differentiate between ordered and un-ordered lists.
If either key is missing, the default
As an example, if we have an <style>
li::marker {
color: blue;
}
</style>
<li><slot></slot></li> 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 MarkdownTo use inline markdown, you can assign the prop <SvelteMarkdown {source} isInline /> HTML renderingWhile 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. This is a **markdown** paragraph.
<p>This is an <strong>HTML</strong> paragraph</p> Note that the HTML paragraph must be enclosed within DevelopingSome tests have been added to the You can clone this repo and do the following: $ 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: $ yarn link svelte-markdown And then import it like in the example above. As of now the only external dependency of this project is Related
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论