feat: easier mention syntax
This commit is contained in:
parent
d0493b51df
commit
9e2db05eff
|
|
@ -42,7 +42,7 @@ export const CharacterFloatCard: React.FC<{
|
|||
|
||||
return (
|
||||
<>
|
||||
<div ref={refs.setReference} {...getReferenceProps()}>
|
||||
<div className="inline" ref={refs.setReference} {...getReferenceProps()}>
|
||||
{children}
|
||||
</div>
|
||||
{isMounted && (
|
||||
|
|
|
|||
|
|
@ -2,21 +2,39 @@ import React from "react"
|
|||
import { CharacterFloatCard } from "../common/CharacterFloatCard"
|
||||
import { UniLink } from "./UniLink"
|
||||
import { getSiteLink } from "~/lib/helpers"
|
||||
import { useGetSite } from "~/queries/site"
|
||||
|
||||
export const Mention: React.FC<{
|
||||
id: string
|
||||
}> = ({ id }) => {
|
||||
const siteId = id?.replace(/^user-content-/, "")
|
||||
return (
|
||||
<CharacterFloatCard siteId={siteId}>
|
||||
<UniLink
|
||||
href={getSiteLink({
|
||||
subdomain: siteId,
|
||||
})}
|
||||
className="inline-block"
|
||||
>
|
||||
@{siteId}
|
||||
</UniLink>
|
||||
</CharacterFloatCard>
|
||||
)
|
||||
children?: any
|
||||
}> = ({ id, children }) => {
|
||||
let siteId
|
||||
if (
|
||||
children?.[0] &&
|
||||
typeof children[0] === "string" &&
|
||||
children[0].startsWith("@")
|
||||
) {
|
||||
siteId = children[0].replace(/^@/, "")
|
||||
} else if (id) {
|
||||
siteId = id.replace(/^user-content-/, "")
|
||||
}
|
||||
|
||||
const site = useGetSite(siteId)
|
||||
|
||||
if (siteId && site.data) {
|
||||
return (
|
||||
<CharacterFloatCard siteId={siteId}>
|
||||
<UniLink
|
||||
href={getSiteLink({
|
||||
subdomain: siteId,
|
||||
})}
|
||||
className="inline-block"
|
||||
>
|
||||
@{siteId}
|
||||
</UniLink>
|
||||
</CharacterFloatCard>
|
||||
)
|
||||
} else {
|
||||
return <>{children}</>
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,6 @@ export const Mention: ICommand = {
|
|||
label: "Mention",
|
||||
icon: "i-mingcute:at-line",
|
||||
execute: ({ view }) => {
|
||||
wrapExecute({ view, prepend: "::mention{#", append: "}" })
|
||||
wrapExecute({ view, prepend: "@", append: "" })
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,6 +70,8 @@ export const renderPageContent = (
|
|||
tree: null,
|
||||
}
|
||||
|
||||
content = content.replace(/(@\w+)/g, "<mention>$1</mention>")
|
||||
|
||||
let contentHTML = ""
|
||||
let result: any = null
|
||||
try {
|
||||
|
|
|
|||
Loading…
Reference in New Issue