summaryrefslogtreecommitdiff
path: root/src/mfm
diff options
context:
space:
mode:
authorMeiMei <30769358+mei23@users.noreply.github.com>2020-11-08 00:38:50 +0900
committerGitHub <noreply@github.com>2020-11-08 00:38:50 +0900
commit27d0ac3d750f82888703c707ff2bf54db2531a67 (patch)
tree0be3f8f449c8573862c263c16e4e8e7111b0d10e /src/mfm
parentImprove readability (diff)
downloadmisskey-27d0ac3d750f82888703c707ff2bf54db2531a67.tar.gz
misskey-27d0ac3d750f82888703c707ff2bf54db2531a67.tar.bz2
misskey-27d0ac3d750f82888703c707ff2bf54db2531a67.zip
In HTML to MFM, use angle bracket if needed (#6817)
Diffstat (limited to 'src/mfm')
-rw-r--r--src/mfm/from-html.ts8
-rw-r--r--src/mfm/prelude.ts3
2 files changed, 8 insertions, 3 deletions
diff --git a/src/mfm/from-html.ts b/src/mfm/from-html.ts
index 1eca3fc6ce..4c27c2cbba 100644
--- a/src/mfm/from-html.ts
+++ b/src/mfm/from-html.ts
@@ -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;
diff --git a/src/mfm/prelude.ts b/src/mfm/prelude.ts
index e18625bc7d..a8b52eb315 100644
--- a/src/mfm/prelude.ts
+++ b/src/mfm/prelude.ts
@@ -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\/:%#@$&?!()\[\]~.,=+\-]+$/;