summaryrefslogtreecommitdiff
path: root/src/mfm/parse/elements
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-11-16 21:57:19 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-11-16 21:57:19 +0900
commit0ff390ed80be8fa64c1ba1d6a7cbc671b0156931 (patch)
treeb41d77d715f28640c123032c31b6b230019b5dcb /src/mfm/parse/elements
parent[MFM] Better URL parsing (diff)
downloadmisskey-0ff390ed80be8fa64c1ba1d6a7cbc671b0156931.tar.gz
misskey-0ff390ed80be8fa64c1ba1d6a7cbc671b0156931.tar.bz2
misskey-0ff390ed80be8fa64c1ba1d6a7cbc671b0156931.zip
[MFM] Improve various parsing
Resolve #2779 Resolve #3053
Diffstat (limited to 'src/mfm/parse/elements')
-rw-r--r--src/mfm/parse/elements/hashtag.ts4
-rw-r--r--src/mfm/parse/elements/mention.ts3
-rw-r--r--src/mfm/parse/elements/quote.ts4
-rw-r--r--src/mfm/parse/elements/title.ts4
-rw-r--r--src/mfm/parse/elements/url.ts3
5 files changed, 13 insertions, 5 deletions
diff --git a/src/mfm/parse/elements/hashtag.ts b/src/mfm/parse/elements/hashtag.ts
index 7005dbe09b..df07de6645 100644
--- a/src/mfm/parse/elements/hashtag.ts
+++ b/src/mfm/parse/elements/hashtag.ts
@@ -8,7 +8,9 @@ export type TextElementHashtag = {
hashtag: string;
};
-export default function(text: string, isBegin: boolean) {
+export default function(text: string, before: string) {
+ const isBegin = before == '';
+
if (!(/^\s#[^\s\.,!\?#]+/.test(text) || (isBegin && /^#[^\s\.,!\?#]+/.test(text)))) return null;
const isHead = text.startsWith('#');
const hashtag = text.match(/^\s?#[^\s\.,!\?#]+/)[0];
diff --git a/src/mfm/parse/elements/mention.ts b/src/mfm/parse/elements/mention.ts
index 832a97c62d..7a609e5d34 100644
--- a/src/mfm/parse/elements/mention.ts
+++ b/src/mfm/parse/elements/mention.ts
@@ -12,9 +12,10 @@ export type TextElementMention = {
host: string;
};
-export default function(text: string) {
+export default function(text: string, before: string) {
const match = text.match(/^@[a-z0-9_]+(?:@[a-z0-9\.\-]+[a-z0-9])?/i);
if (!match) return null;
+ if (/[a-zA-Z0-9]$/.test(before)) return null;
const mention = match[0];
const { username, host } = parseAcct(mention.substr(1));
const canonical = host != null ? `@${username}@${toUnicode(host)}` : mention;
diff --git a/src/mfm/parse/elements/quote.ts b/src/mfm/parse/elements/quote.ts
index 5f8c9c7fc6..969c1fb4a9 100644
--- a/src/mfm/parse/elements/quote.ts
+++ b/src/mfm/parse/elements/quote.ts
@@ -8,7 +8,9 @@ export type TextElementQuote = {
quote: string;
};
-export default function(text: string, isBegin: boolean) {
+export default function(text: string, before: string) {
+ const isBegin = before == '';
+
const match = text.match(/^"([\s\S]+?)\n"/) || text.match(/^\n>([\s\S]+?)(\n\n|$)/) ||
(isBegin ? text.match(/^>([\s\S]+?)(\n\n|$)/) : null);
diff --git a/src/mfm/parse/elements/title.ts b/src/mfm/parse/elements/title.ts
index d67236aa78..a9922c8aca 100644
--- a/src/mfm/parse/elements/title.ts
+++ b/src/mfm/parse/elements/title.ts
@@ -8,7 +8,9 @@ export type TextElementTitle = {
title: string;
};
-export default function(text: string, isBegin: boolean) {
+export default function(text: string, before: string) {
+ const isBegin = before == '';
+
const match = isBegin ? text.match(/^(【|\[)(.+?)(】|])\n/) : text.match(/^\n(【|\[)(.+?)(】|])\n/);
if (!match) return null;
return {
diff --git a/src/mfm/parse/elements/url.ts b/src/mfm/parse/elements/url.ts
index 411f2ebfad..a16f67f2c2 100644
--- a/src/mfm/parse/elements/url.ts
+++ b/src/mfm/parse/elements/url.ts
@@ -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,