In HTML to MFM, use angle bracket if needed (#6817)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { parseFragment, DefaultTreeDocumentFragment } from 'parse5';
|
||||
import { urlRegex } from './prelude';
|
||||
import { urlRegexFull } from './prelude';
|
||||
|
||||
export function fromHtml(html: string, hashtagNames?: string[]): string {
|
||||
const dom = parseFragment(html) as DefaultTreeDocumentFragment;
|
||||
@@ -54,7 +54,11 @@ export function fromHtml(html: string, hashtagNames?: string[]): string {
|
||||
}
|
||||
// その他
|
||||
} else {
|
||||
text += (!href || (txt === href.value && txt.match(urlRegex))) ? txt : `[${txt}](${href.value})`;
|
||||
text += !href ? txt
|
||||
: txt === href.value
|
||||
? txt.match(urlRegexFull) ? txt
|
||||
: `<${txt}>`
|
||||
: `[${txt}](${href.value})`;
|
||||
}
|
||||
break;
|
||||
|
||||
|
@@ -36,4 +36,5 @@ export function createTree(type: string, children: MfmForest, props: any): MfmTr
|
||||
return T.createTree({ type, props }, children);
|
||||
}
|
||||
|
||||
export const urlRegex = /^https?:\/\/[\w\/:%#@$&?!()\[\]~.,=+\-]+/;
|
||||
export const urlRegex = /^https?:\/\/[\w\/:%#@$&?!()\[\]~.,=+\-]+/;
|
||||
export const urlRegexFull = /^https?:\/\/[\w\/:%#@$&?!()\[\]~.,=+\-]+$/;
|
||||
|
Reference in New Issue
Block a user