[MFM] Improve various parsing

Resolve #2779
Resolve #3053
This commit is contained in:
syuilo 2018-11-16 21:57:19 +09:00
parent e3b8495431
commit 0ff390ed80
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69
7 changed files with 79 additions and 46 deletions

View file

@ -8,12 +8,13 @@ export type TextElementUrl = {
url: string;
};
export default function(text: string) {
export default function(text: string, before: string) {
const match = text.match(/^https?:\/\/[\w\/:%#@\$&\?!\(\)\[\]~\.,=\+\-]+/);
if (!match) return null;
let url = match[0];
if (url.endsWith('.')) url = url.substr(0, url.lastIndexOf('.'));
if (url.endsWith(',')) url = url.substr(0, url.lastIndexOf(','));
if (url.endsWith(')') && before.endsWith('(')) url = url.substr(0, url.lastIndexOf(')'));
return {
type: 'url',
content: url,