summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortamaina <tamaina@hotmail.co.jp>2018-09-01 22:45:27 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2018-09-01 22:45:27 +0900
commitffb345ccb5680df4f28bd9ad3c3d1ab8480c99ba (patch)
treead06cf550f9f6f6f7f7cf07fabff9822c524afee /src
parentMerge pull request #2573 from syuilo/refactor-mfm (diff)
downloadsharkey-ffb345ccb5680df4f28bd9ad3c3d1ab8480c99ba.tar.gz
sharkey-ffb345ccb5680df4f28bd9ad3c3d1ab8480c99ba.tar.bz2
sharkey-ffb345ccb5680df4f28bd9ad3c3d1ab8480c99ba.zip
fix #2315 (#2339)
* improve MFM to html * improve html to MFM * missing semicolon * missing semicolon * fix html to MFM タグのリンクは解除するように * fix bug * misssing semicolon * Update html-to-mfm.ts * Update html-to-mfm.ts
Diffstat (limited to 'src')
-rw-r--r--src/mfm/html-to-mfm.ts17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/mfm/html-to-mfm.ts b/src/mfm/html-to-mfm.ts
index daa228ec51..e2681f5447 100644
--- a/src/mfm/html-to-mfm.ts
+++ b/src/mfm/html-to-mfm.ts
@@ -33,15 +33,19 @@ export default function(html: string): string {
case 'a':
const txt = getText(node);
+ const rel = node.attrs.find((x: any) => x.name == 'rel');
+ const href = node.attrs.find((x: any) => x.name == 'href');
+ // ハッシュタグ / hrefがない / txtがURL
+ if ((rel && rel.value.match('tag') !== null) || !href || href.value == txt) {
+ text += txt;
// メンション
- if (txt.startsWith('@')) {
+ } else if (txt.startsWith('@')) {
const part = txt.split('@');
if (part.length == 2) {
//#region ホスト名部分が省略されているので復元する
- const href = new URL(node.attrs.find((x: any) => x.name == 'href').value);
- const acct = txt + '@' + href.hostname;
+ const acct = txt + '@' + (new URL(href.value)).hostname;
text += acct;
break;
//#endregion
@@ -49,10 +53,9 @@ export default function(html: string): string {
text += txt;
break;
}
- }
-
- if (node.childNodes) {
- node.childNodes.forEach((n: any) => analyze(n));
+ // その他
+ } else {
+ text += `[${txt}](${href.value})`;
}
break;