diff options
| author | MeiMei <30769358+mei23@users.noreply.github.com> | 2020-04-03 22:51:38 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-03 22:51:38 +0900 |
| commit | 99fc77b6787bf16e772d46493067de75ea219bb7 (patch) | |
| tree | 25c4ce00f3b827805f4fa36efc529abcc7735a47 /src/mfm | |
| parent | APIリファレンスのカテゴリ処理の修正 (#6218) (diff) | |
| download | sharkey-99fc77b6787bf16e772d46493067de75ea219bb7.tar.gz sharkey-99fc77b6787bf16e772d46493067de75ea219bb7.tar.bz2 sharkey-99fc77b6787bf16e772d46493067de75ea219bb7.zip | |
APメンションはaudienceじゃなくてtagを参照するなど (#6128)
* APメンションはaudienceじゃなくてtagを参照するなど
* AP/tag/Mentionではurlじゃなくてuriを提示する
* createPersonでaliasが入力された場合に対応
* AP HTMLパースでMention/Hashtag判定にtagを使うように
* fix
* indent
* use hashtag name
* fix
* URLエンコード不要だったら<>を使わないの条件が消えたたのを修正
Diffstat (limited to 'src/mfm')
| -rw-r--r-- | src/mfm/fromHtml.ts | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/src/mfm/fromHtml.ts b/src/mfm/fromHtml.ts index 0ffae014ae..8c6ca337ea 100644 --- a/src/mfm/fromHtml.ts +++ b/src/mfm/fromHtml.ts @@ -1,7 +1,7 @@ import { parseFragment, DefaultTreeDocumentFragment } from 'parse5'; import { urlRegex } from './prelude'; -export function fromHtml(html: string): string { +export function fromHtml(html: string, hashtagNames?: string[]): string { const dom = parseFragment(html) as DefaultTreeDocumentFragment; let text = ''; @@ -36,12 +36,10 @@ export function fromHtml(html: string): string { const txt = getText(node); const rel = node.attrs.find((x: any) => x.name == 'rel'); const href = node.attrs.find((x: any) => x.name == 'href'); - const _class = node.attrs.find((x: any) => x.name == 'class'); - const isHashtag = rel?.value?.match('tag') || _class?.value?.match('hashtag'); - // ハッシュタグ / hrefがない / txtがURL - if (isHashtag || !href || href.value == txt) { - text += isHashtag || txt.match(urlRegex) ? txt : `<${txt}>`; + // ハッシュタグ + if (hashtagNames && href && hashtagNames.map(x => x.toLowerCase()).includes(txt.toLowerCase())) { + text += txt; // メンション } else if (txt.startsWith('@') && !(rel && rel.value.match(/^me /))) { const part = txt.split('@'); @@ -56,7 +54,7 @@ export function fromHtml(html: string): string { } // その他 } else { - text += `[${txt}](${href.value})`; + text += (!href || (txt === href.value && txt.match(urlRegex))) ? txt : `[${txt}](${href.value})`; } break; |