fix: links in lists
This commit is contained in:
1 parent
9bde0e5686
commit
bcc3c48f27
8 files changed
+90
-32
No files matched your search
@@ -8,7 +8,6 @@
|
||||
MdImage,
|
||||
MdLink,
|
||||
MdQuote,
|
||||
MdText,
|
||||
MdList,
|
||||
MdTable,
|
||||
MdTableBody,
|
||||
@@ -16,17 +15,21 @@
|
||||
MdTableCell,
|
||||
MdTableHead,
|
||||
MdTableRow,
|
||||
MdParagraph,
|
||||
MdListItem,
|
||||
MdSubscript,
|
||||
MdSuperscript,
|
||||
} from './renderers/index'
|
||||
import { linkify } from './renderers/plugins'
|
||||
import { linkify, subSupscriptExtension } from './renderers/plugins'
|
||||
import containerExtension from './renderers/spoiler/spoiler'
|
||||
|
||||
marked.setOptions({
|
||||
pedantic: false,
|
||||
// @ts-ignore
|
||||
export const options: any = {
|
||||
mangle: false,
|
||||
// @ts-ignore
|
||||
headerIds: false,
|
||||
})
|
||||
pedantic: false,
|
||||
}
|
||||
|
||||
marked.setOptions(options)
|
||||
|
||||
marked.use(linkify, {
|
||||
extensions: [
|
||||
@@ -41,6 +44,23 @@
|
||||
}
|
||||
return null
|
||||
}),
|
||||
subSupscriptExtension((params: any) => {
|
||||
if (params.type == 'subscript') {
|
||||
return {
|
||||
type: 'subscript',
|
||||
raw: params.raw,
|
||||
text: params.content,
|
||||
}
|
||||
}
|
||||
if (params.type == 'superscript') {
|
||||
return {
|
||||
type: 'superscript',
|
||||
raw: params.raw,
|
||||
text: params.content,
|
||||
}
|
||||
}
|
||||
return null
|
||||
}),
|
||||
],
|
||||
})
|
||||
|
||||
@@ -51,10 +71,8 @@
|
||||
blockquote: MdQuote,
|
||||
hr: MdHr,
|
||||
html: MdHtml,
|
||||
text: MdText,
|
||||
code: MdCode,
|
||||
list: MdList,
|
||||
del: MdText,
|
||||
// @ts-ignore
|
||||
spoiler: MdSpoiler,
|
||||
table: MdTable,
|
||||
@@ -62,11 +80,10 @@
|
||||
tablecell: MdTableCell,
|
||||
tablehead: MdTableHead,
|
||||
tablerow: MdTableRow,
|
||||
}
|
||||
|
||||
export const options: any = {
|
||||
mangle: false,
|
||||
headerIds: false,
|
||||
paragraph: MdParagraph,
|
||||
listitem: MdListItem,
|
||||
subscript: MdSubscript,
|
||||
superscript: MdSuperscript,
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<script>
|
||||
export let tokens
|
||||
</script>
|
||||
|
||||
<li>
|
||||
<slot />
|
||||
</li>
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
function extractTitle(text: string) {
|
||||
const spoilerRegex = /^::: ?spoiler (.+)\n([\s\S]+?)\n:::/gm
|
||||
|
||||
const result = spoilerRegex.exec(text)
|
||||
|
||||
if (!result?.[1] || !result?.[2])
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<script lang="ts">
|
||||
export let text: string
|
||||
</script>
|
||||
|
||||
<sub>{text}</sub>
|
||||
@@ -0,0 +1,5 @@
|
||||
<script lang="ts">
|
||||
export let text: string
|
||||
</script>
|
||||
|
||||
<sup>{text}</sup>
|
||||
@@ -1,16 +1 @@
|
||||
<script lang="ts">
|
||||
export let raw: string
|
||||
|
||||
function preprocess(src: string): string {
|
||||
// superscript, subscript support
|
||||
src = src
|
||||
.replaceAll(/~([^~]+)~/g, '<sub>$1</sub>')
|
||||
.replaceAll(/\^([^^]+)\^/g, '<sup>$1</sup>')
|
||||
|
||||
return src
|
||||
}
|
||||
|
||||
$: processed = preprocess(raw)
|
||||
</script>
|
||||
|
||||
{@html processed}
|
||||
<slot />
|
||||
@@ -5,7 +5,6 @@ import MdQuote from './MdQuote.svelte'
|
||||
import MdHr from './MdHr.svelte'
|
||||
import MdCode from './MdCode.svelte'
|
||||
import MdHtml from './MdHtml.svelte'
|
||||
import MdText from './MdText.svelte'
|
||||
import MdList from './MdList.svelte'
|
||||
import MdSpoiler from './MdSpoiler.svelte'
|
||||
import MdTable from './table/MdTable.svelte'
|
||||
@@ -14,6 +13,9 @@ import MdTableCell from './table/MdTableCell.svelte'
|
||||
import MdTableHead from './table/MdTableHead.svelte'
|
||||
import MdTableRow from './table/MdTableRow.svelte'
|
||||
import MdParagraph from './MdParagraph.svelte'
|
||||
import MdListItem from './MdListItem.svelte'
|
||||
import MdSubscript from './MdSubscript.svelte'
|
||||
import MdSuperscript from './MdSuperscript.svelte'
|
||||
|
||||
export {
|
||||
MdCode,
|
||||
@@ -23,7 +25,6 @@ export {
|
||||
MdImage,
|
||||
MdLink,
|
||||
MdQuote,
|
||||
MdText,
|
||||
MdList,
|
||||
MdSpoiler,
|
||||
MdTable,
|
||||
@@ -32,4 +33,7 @@ export {
|
||||
MdTableHead,
|
||||
MdTableRow,
|
||||
MdParagraph,
|
||||
MdListItem,
|
||||
MdSubscript,
|
||||
MdSuperscript,
|
||||
}
|
||||
@@ -119,3 +119,37 @@ export const photonify = (link: string) => {
|
||||
return `/c/${match?.[3]}@${match?.[1]}`
|
||||
}
|
||||
}
|
||||
|
||||
export function subSupscriptExtension(tokensExtractor: any): any {
|
||||
return {
|
||||
name: 'subscriptSuperscript',
|
||||
level: 'inline',
|
||||
start(src: string) {
|
||||
return src.match(/[~^]/)?.index
|
||||
},
|
||||
tokenizer(src: string, tokens: any[]): any {
|
||||
const subscriptRule = /^~([^~\s](?:[^~]*[^~\s])?)~/
|
||||
const superscriptRule = /^\^([^\^\s](?:[^\^]*[^\^\s])?)\^/
|
||||
|
||||
let match
|
||||
|
||||
if ((match = subscriptRule.exec(src))) {
|
||||
return tokensExtractor({
|
||||
type: 'subscript',
|
||||
content: match[1],
|
||||
raw: match[0],
|
||||
lexer: this.lexer,
|
||||
})
|
||||
}
|
||||
|
||||
if ((match = superscriptRule.exec(src))) {
|
||||
return tokensExtractor({
|
||||
type: 'superscript',
|
||||
content: match[1],
|
||||
raw: match[0],
|
||||
lexer: this.lexer,
|
||||
})
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user