inline tokenizer

This commit is contained in:
Maxime Cannoodt 2022-06-25 10:25:30 +02:00
parent 15bd2edf5f
commit 39f5d33b09
5 changed files with 37 additions and 4 deletions

Binary file not shown.

View File

@ -13,8 +13,6 @@
import BugIcon from 'svelte-icons/md/MdBugReport.svelte'; import BugIcon from 'svelte-icons/md/MdBugReport.svelte';
import QuoteIcon from 'svelte-icons/md/MdFormatQuote.svelte'; import QuoteIcon from 'svelte-icons/md/MdFormatQuote.svelte';
export let icon: string; export let icon: string;
console.log(icon);
</script> </script>
{#if icon == 'note'} {#if icon == 'note'}

View File

@ -10,6 +10,7 @@
import Highlight from '$lib/marked/renderers/Highlight.svelte'; import Highlight from '$lib/marked/renderers/Highlight.svelte';
import InternalEmbed from '$lib/marked/renderers/InternalEmbed.svelte'; import InternalEmbed from '$lib/marked/renderers/InternalEmbed.svelte';
import Blockquote from '$lib/marked/renderers/Blockquote.svelte'; import Blockquote from '$lib/marked/renderers/Blockquote.svelte';
import MathInline from '$lib/marked/renderers/MathInline.svelte';
export let plaintext: string; export let plaintext: string;
@ -34,7 +35,8 @@ prose-blockquote:first:before:content-['']"
'internal-embed': InternalEmbed, 'internal-embed': InternalEmbed,
tag: Tag, tag: Tag,
highlight: Highlight, highlight: Highlight,
blockquote: Blockquote blockquote: Blockquote,
'math-inline': MathInline
}} }}
source={plaintext} source={plaintext}
{options} {options}

View File

@ -59,6 +59,7 @@ const HighlightExtension = {
name: 'highlight', name: 'highlight',
level: 'inline', level: 'inline',
start(src: string) { start(src: string) {
// console.log(src);
return src.match(/==/)?.index; return src.match(/==/)?.index;
}, },
tokenizer(src: string) { tokenizer(src: string) {
@ -74,6 +75,33 @@ const HighlightExtension = {
} }
}; };
export default [InternalLinkExtension, InternalEmbedExtension, TagExtension, HighlightExtension]; const MathInline = {
name: 'math-inline',
level: 'inline',
start(src: string) {
return src.indexOf('$');
},
tokenizer(src: string) {
const match = src.match(/^(\${1})((?:\\.|.)*)\1/);
console.log(src, match);
if (match) {
return {
type: 'math-inline',
raw: match[0],
text: match[2].trim()
};
}
return false;
}
};
export default [
InternalLinkExtension,
InternalEmbedExtension,
TagExtension,
HighlightExtension,
MathInline
];
// ^\#([\w\/]+)\W* // ^\#([\w\/]+)\W*

View File

@ -0,0 +1,5 @@
<script lang="ts">
export let text: string;
</script>
<span>{text}</span>