In HTML to MFM, use angle bracket if needed (#6817)
This commit is contained in:
parent
a8776002f3
commit
27d0ac3d75
3 changed files with 43 additions and 3 deletions
|
@ -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\/:%#@$&?!()\[\]~.,=+\-]+$/;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue