u
This commit is contained in:
@@ -9,7 +9,7 @@ import {
|
||||
TABLE_HEADER_PAIR,
|
||||
byMode,
|
||||
} from '../../colors';
|
||||
import { VfsAttachmentLink, parseAttachmentTag } from './ChatAttachmentItems';
|
||||
import { VfsAttachmentLink, parseAttachmentTag, classifyLinkTarget } from './ChatAttachmentItems';
|
||||
|
||||
/**
|
||||
* Healing markdown renderer.
|
||||
@@ -550,21 +550,35 @@ function parseInline(src, keyPrefix = 'i') {
|
||||
const label = src.slice(i + 1, close);
|
||||
if (src[close + 1] === '(') {
|
||||
const endUrl = src.indexOf(')', close + 2);
|
||||
const url = (endUrl === -1 ? src.slice(close + 2) : src.slice(close + 2, endUrl)).trim();
|
||||
const rawUrl = (endUrl === -1 ? src.slice(close + 2) : src.slice(close + 2, endUrl)).trim();
|
||||
const k = key();
|
||||
if (endUrl !== -1 && SAFE_URL.test(url)) {
|
||||
if (/^https?:\/\//i.test(url)) {
|
||||
if (endUrl !== -1) {
|
||||
const classified = classifyLinkTarget(rawUrl);
|
||||
if (classified.kind === 'web') {
|
||||
push(
|
||||
<WebLinkCard key={k} url={url} label={label}>
|
||||
<WebLinkCard key={k} url={classified.url} label={label}>
|
||||
{parseInline(label, k)}
|
||||
</WebLinkCard>,
|
||||
);
|
||||
} else {
|
||||
} else if (classified.kind === 'nav') {
|
||||
push(
|
||||
<a key={k} href={url} target="_blank" rel="noopener noreferrer">
|
||||
<a key={k} href={classified.url} target="_blank" rel="noopener noreferrer">
|
||||
{parseInline(label, k)}
|
||||
</a>,
|
||||
);
|
||||
} else if (classified.kind === 'vfs') {
|
||||
const filename = classified.path.split('/').pop() || 'datei';
|
||||
push(
|
||||
<VfsAttachmentLink
|
||||
key={k}
|
||||
name={filename}
|
||||
path={classified.path}
|
||||
label={parseInline(label, k)}
|
||||
isUser={false}
|
||||
/>,
|
||||
);
|
||||
} else {
|
||||
push(<span key={k}>{parseInline(label, k)}</span>);
|
||||
}
|
||||
} else {
|
||||
// Half-typed (or unsafe) link: show the label only.
|
||||
|
||||
Reference in New Issue
Block a user