markdown highlight
This commit is contained in:
parent
3b27be0211
commit
ed3cbc91df
Binary file not shown.
@ -7,6 +7,7 @@
|
|||||||
import extensions from '$lib/marked/extensions';
|
import extensions from '$lib/marked/extensions';
|
||||||
import Link from '$lib/marked/renderers/Link.svelte';
|
import Link from '$lib/marked/renderers/Link.svelte';
|
||||||
import Tag from '$lib/marked/renderers/Tag.svelte';
|
import Tag from '$lib/marked/renderers/Tag.svelte';
|
||||||
|
import Highlight from '$lib/marked/renderers/Highlight.svelte';
|
||||||
|
|
||||||
export let plaintext: string;
|
export let plaintext: string;
|
||||||
|
|
||||||
@ -28,7 +29,8 @@ prose-blockquote:first:before:content-['']"
|
|||||||
list: List,
|
list: List,
|
||||||
link: Link,
|
link: Link,
|
||||||
'internal-link': InternalLink,
|
'internal-link': InternalLink,
|
||||||
tag: Tag
|
tag: Tag,
|
||||||
|
highlight: Highlight
|
||||||
}}
|
}}
|
||||||
source={plaintext}
|
source={plaintext}
|
||||||
{options}
|
{options}
|
||||||
|
@ -26,7 +26,6 @@ const TagExtension = {
|
|||||||
tokenizer(src: string) {
|
tokenizer(src: string) {
|
||||||
const match = src.match(/^#([\w/]+)[\W\s]/);
|
const match = src.match(/^#([\w/]+)[\W\s]/);
|
||||||
if (match) {
|
if (match) {
|
||||||
console.log(match);
|
|
||||||
return {
|
return {
|
||||||
type: 'tag',
|
type: 'tag',
|
||||||
raw: match[0].trim(),
|
raw: match[0].trim(),
|
||||||
@ -37,6 +36,25 @@ const TagExtension = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default [InternalLinkExtension, TagExtension];
|
const HighlightExtension = {
|
||||||
|
name: 'highlight',
|
||||||
|
level: 'inline',
|
||||||
|
start(src: string) {
|
||||||
|
return src.match(/==/)?.index;
|
||||||
|
},
|
||||||
|
tokenizer(src: string) {
|
||||||
|
const match = src.match(/^==(.+)==/);
|
||||||
|
if (match) {
|
||||||
|
return {
|
||||||
|
type: 'highlight',
|
||||||
|
raw: match[0].trim(),
|
||||||
|
text: match[1].trim()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default [InternalLinkExtension, TagExtension, HighlightExtension];
|
||||||
|
|
||||||
// ^\#([\w\/]+)\W*
|
// ^\#([\w\/]+)\W*
|
||||||
|
5
webapp/src/lib/marked/renderers/Highlight.svelte
Normal file
5
webapp/src/lib/marked/renderers/Highlight.svelte
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
export let text: string;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<span class="bg-yellow-300">{text}</span>
|
Loading…
Reference in New Issue
Block a user