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,
|
MdImage,
|
||||||
MdLink,
|
MdLink,
|
||||||
MdQuote,
|
MdQuote,
|
||||||
MdText,
|
|
||||||
MdList,
|
MdList,
|
||||||
MdTable,
|
MdTable,
|
||||||
MdTableBody,
|
MdTableBody,
|
||||||
@@ -16,17 +15,21 @@
|
|||||||
MdTableCell,
|
MdTableCell,
|
||||||
MdTableHead,
|
MdTableHead,
|
||||||
MdTableRow,
|
MdTableRow,
|
||||||
|
MdParagraph,
|
||||||
|
MdListItem,
|
||||||
|
MdSubscript,
|
||||||
|
MdSuperscript,
|
||||||
} from './renderers/index'
|
} from './renderers/index'
|
||||||
import { linkify } from './renderers/plugins'
|
import { linkify, subSupscriptExtension } from './renderers/plugins'
|
||||||
import containerExtension from './renderers/spoiler/spoiler'
|
import containerExtension from './renderers/spoiler/spoiler'
|
||||||
|
|
||||||
marked.setOptions({
|
export const options: any = {
|
||||||
pedantic: false,
|
|
||||||
// @ts-ignore
|
|
||||||
mangle: false,
|
mangle: false,
|
||||||
// @ts-ignore
|
|
||||||
headerIds: false,
|
headerIds: false,
|
||||||
})
|
pedantic: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
marked.setOptions(options)
|
||||||
|
|
||||||
marked.use(linkify, {
|
marked.use(linkify, {
|
||||||
extensions: [
|
extensions: [
|
||||||
@@ -41,6 +44,23 @@
|
|||||||
}
|
}
|
||||||
return null
|
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,
|
blockquote: MdQuote,
|
||||||
hr: MdHr,
|
hr: MdHr,
|
||||||
html: MdHtml,
|
html: MdHtml,
|
||||||
text: MdText,
|
|
||||||
code: MdCode,
|
code: MdCode,
|
||||||
list: MdList,
|
list: MdList,
|
||||||
del: MdText,
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
spoiler: MdSpoiler,
|
spoiler: MdSpoiler,
|
||||||
table: MdTable,
|
table: MdTable,
|
||||||
@@ -62,11 +80,10 @@
|
|||||||
tablecell: MdTableCell,
|
tablecell: MdTableCell,
|
||||||
tablehead: MdTableHead,
|
tablehead: MdTableHead,
|
||||||
tablerow: MdTableRow,
|
tablerow: MdTableRow,
|
||||||
}
|
paragraph: MdParagraph,
|
||||||
|
listitem: MdListItem,
|
||||||
export const options: any = {
|
subscript: MdSubscript,
|
||||||
mangle: false,
|
superscript: MdSuperscript,
|
||||||
headerIds: false,
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<script>
|
||||||
|
export let tokens
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
<slot />
|
||||||
|
</li>
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
function extractTitle(text: string) {
|
function extractTitle(text: string) {
|
||||||
const spoilerRegex = /^::: ?spoiler (.+)\n([\s\S]+?)\n:::/gm
|
const spoilerRegex = /^::: ?spoiler (.+)\n([\s\S]+?)\n:::/gm
|
||||||
|
|
||||||
const result = spoilerRegex.exec(text)
|
const result = spoilerRegex.exec(text)
|
||||||
|
|
||||||
if (!result?.[1] || !result?.[2])
|
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">
|
<slot />
|
||||||
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}
|
|
||||||
@@ -5,7 +5,6 @@ import MdQuote from './MdQuote.svelte'
|
|||||||
import MdHr from './MdHr.svelte'
|
import MdHr from './MdHr.svelte'
|
||||||
import MdCode from './MdCode.svelte'
|
import MdCode from './MdCode.svelte'
|
||||||
import MdHtml from './MdHtml.svelte'
|
import MdHtml from './MdHtml.svelte'
|
||||||
import MdText from './MdText.svelte'
|
|
||||||
import MdList from './MdList.svelte'
|
import MdList from './MdList.svelte'
|
||||||
import MdSpoiler from './MdSpoiler.svelte'
|
import MdSpoiler from './MdSpoiler.svelte'
|
||||||
import MdTable from './table/MdTable.svelte'
|
import MdTable from './table/MdTable.svelte'
|
||||||
@@ -14,6 +13,9 @@ import MdTableCell from './table/MdTableCell.svelte'
|
|||||||
import MdTableHead from './table/MdTableHead.svelte'
|
import MdTableHead from './table/MdTableHead.svelte'
|
||||||
import MdTableRow from './table/MdTableRow.svelte'
|
import MdTableRow from './table/MdTableRow.svelte'
|
||||||
import MdParagraph from './MdParagraph.svelte'
|
import MdParagraph from './MdParagraph.svelte'
|
||||||
|
import MdListItem from './MdListItem.svelte'
|
||||||
|
import MdSubscript from './MdSubscript.svelte'
|
||||||
|
import MdSuperscript from './MdSuperscript.svelte'
|
||||||
|
|
||||||
export {
|
export {
|
||||||
MdCode,
|
MdCode,
|
||||||
@@ -23,7 +25,6 @@ export {
|
|||||||
MdImage,
|
MdImage,
|
||||||
MdLink,
|
MdLink,
|
||||||
MdQuote,
|
MdQuote,
|
||||||
MdText,
|
|
||||||
MdList,
|
MdList,
|
||||||
MdSpoiler,
|
MdSpoiler,
|
||||||
MdTable,
|
MdTable,
|
||||||
@@ -32,4 +33,7 @@ export {
|
|||||||
MdTableHead,
|
MdTableHead,
|
||||||
MdTableRow,
|
MdTableRow,
|
||||||
MdParagraph,
|
MdParagraph,
|
||||||
|
MdListItem,
|
||||||
|
MdSubscript,
|
||||||
|
MdSuperscript,
|
||||||
}
|
}
|
||||||
@@ -119,3 +119,37 @@ export const photonify = (link: string) => {
|
|||||||
return `/c/${match?.[3]}@${match?.[1]}`
|
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