Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
forked fromelk-zone/elk

Commit3109dab

Browse files
userquindanielroe
authored and
zenghawtin
committed
feat: add LTR/RTL in hashtags and mentions support (elk-zone#2541)
Co-authored-by: Daniel Roe <daniel@roe.dev>
1 parent87e6999 commit3109dab

File tree

6 files changed

+202
-106
lines changed

6 files changed

+202
-106
lines changed

‎components/tag/TagCard.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ function go(evt: MouseEvent | KeyboardEvent) {
3939
<div>
4040
<h4flexitems-centertext-size-baseleading-normalfont-mediumline-clamp-1break-allws-pre-wrap>
4141
<TagActionButton:tag="tag" />
42-
<span>#</span>
43-
<spanhover:underline>{{ tag.name }}</span>
42+
<bdi>
43+
<span>#</span>
44+
<spanhover:underline>{{ tag.name }}</span>
45+
</bdi>
4446
</h4>
4547
<CommonTrendingv-if="tag.history":history="tag.history"text-smtext-secondaryline-clamp-1ws-pre-wrapbreak-all />
4648
</div>

‎composables/content-parse.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ const sanitizer = sanitize({
7272
/**
7373
* Parse raw HTML form Mastodon server to AST,
7474
* with interop of custom emojis and inline Markdown syntax
75+
*@param html The content to parse
76+
*@param options The parsing options
7577
*/
7678
exportfunctionparseMastodonHTML(
7779
html:string,
@@ -140,6 +142,8 @@ export function parseMastodonHTML(
140142

141143
/**
142144
* Converts raw HTML form Mastodon server to HTML for Tiptap editor
145+
*@param html The content to parse
146+
*@param customEmojis The custom emojis to use
143147
*/
144148
exportfunctionconvertMastodonHTML(html:string,customEmojis:Record<string,mastodon.v1.CustomEmoji>={}){
145149
consttree=parseMastodonHTML(html,{

‎composables/content-render.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import{TEXT_NODE}from'ultrahtml'
2-
importtype{Node}from'ultrahtml'
1+
import{ELEMENT_NODE,TEXT_NODE}from'ultrahtml'
2+
importtype{ElementNode,Node}from'ultrahtml'
33
import{Fragment,h,isVNode}from'vue'
44
importtype{VNode}from'vue'
55
import{RouterLink}from'vue-router'
@@ -98,6 +98,23 @@ function treeToVNode(
9898
returnnull
9999
}
100100

101+
functionaddBdiNode(node:Node){
102+
if(node.children.length===1&&node.children[0].type===ELEMENT_NODE&&node.children[0].name==='bdi')
103+
return
104+
105+
constchildren=node.children.splice(0,node.children.length)
106+
constbdi={
107+
name:'bdi',
108+
parent:node,
109+
loc:node.loc,
110+
type:ELEMENT_NODE,
111+
attributes:{},
112+
children,
113+
}satisfiesElementNode
114+
children.forEach((n:Node)=>n.parent=bdi)
115+
node.children.push(bdi)
116+
}
117+
101118
functionhandleMention(el:Node){
102119
// Redirect mentions to the user page
103120
if(el.name==='a'&&el.attributes.class?.includes('mention')){
@@ -108,11 +125,13 @@ function handleMention(el: Node) {
108125
const[,server,username]=matchUser
109126
consthandle=`${username}@${server.replace(/(.+\.)(.+\..+)/,'$2')}`
110127
el.attributes.href=`/${server}/@${username}`
128+
addBdiNode(el)
111129
returnh(AccountHoverWrapper,{ handle,class:'inline-block'},()=>nodeToVNode(el))
112130
}
113131
constmatchTag=href.match(TagLinkRE)
114132
if(matchTag){
115133
const[,,name]=matchTag
134+
addBdiNode(el)
116135
el.attributes.href=`/${currentServer.value}/tags/${name}`
117136
}
118137
}

‎pages/[[server]]/tags/[tag].vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ onReactivated(() => {
2828
<template>
2929
<MainContentback>
3030
<template #title>
31-
<spantext-lgfont-bold>#{{ tagName }}</span>
31+
<bditext-lgfont-bold>#{{ tagName }}</bdi>
3232
</template>
3333

3434
<template #actions>

‎tests/nuxt/__snapshots__/content-rich.test.ts.snap

Lines changed: 149 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ exports[`content-rich > code frame 2 1`] = `
4444
class="u-url mention"
4545
rel="nofollow noopener noreferrer"
4646
to="/webtoo.ls/@antfu"
47-
></a
48-
></span>
47+
><bdi>@<span>antfu</span></bdi></a
48+
></span
49+
>
4950
Testing<br />
5051
<preclass="code-block">const a = hello</pre>
5152
</p>
@@ -56,6 +57,62 @@ exports[`content-rich > code frame empty 1`] = `"<p><pre class="code-block"></pr
5657
5758
exports[`content-rich > code frame no lang 1`] = `"<p><preclass="code-block">hello world</pre><br>no lang</p>"`;
5859
60+
exports[`content-rich > collapse mentions 1`] = `
61+
"<p>
62+
<spanclass="h-card"
63+
><a
64+
class="u-url mention"
65+
rel="nofollow noopener noreferrer"
66+
to="/m.webtoo.ls/@elk"
67+
><bdi>@<span>elk</span></bdi></a
68+
></span
69+
>
70+
<spanclass="h-card"
71+
><a
72+
class="u-url mention"
73+
rel="nofollow noopener noreferrer"
74+
to="/m.webtoo.ls/@elk"
75+
><bdi>@<span>elk</span></bdi></a
76+
></span
77+
>
78+
content
79+
<spanclass="h-card"
80+
><a
81+
class="u-url mention"
82+
rel="nofollow noopener noreferrer"
83+
to="/m.webtoo.ls/@antfu"
84+
><bdi>@<span>antfu</span></bdi></a
85+
></span
86+
>
87+
<spanclass="h-card"
88+
><a
89+
class="u-url mention"
90+
rel="nofollow noopener noreferrer"
91+
to="/mastodon.roe.dev/@daniel"
92+
><bdi>@<span>daniel</span></bdi></a
93+
></span
94+
>
95+
<spanclass="h-card"
96+
><a
97+
class="u-url mention"
98+
rel="nofollow noopener noreferrer"
99+
to="/m.webtoo.ls/@sxzz"
100+
><bdi>@<span>sxzz</span></bdi></a
101+
></span
102+
>
103+
<spanclass="h-card"
104+
><a
105+
class="u-url mention"
106+
rel="nofollow noopener noreferrer"
107+
to="/m.webtoo.ls/@patak"
108+
><bdi>@<span>patak</span></bdi></a
109+
></span
110+
>
111+
content
112+
</p>
113+
"
114+
`;
115+
59116
exports[`content-rich > custom emoji 1`] = `
60117
"Daniel Roe
61118
<pictureclass="custom-emoji"alt=":nuxt:"data-emoji-id="nuxt"title="nuxt"
@@ -81,8 +138,13 @@ exports[`content-rich > group mention > html 1`] = `
81138
class="u-url mention"
82139
rel="nofollow noopener noreferrer"
83140
to="/m.webtoo.ls/@pilipinas@lemmy.ml"
84-
></a
85-
></span>
141+
><bdi
142+
><spandata-type="mention"data-id="pilipinas@lemmy.ml"
143+
>@pilipinas</span
144+
></bdi
145+
></a
146+
></span
147+
>
86148
</p>
87149
"
88150
`;
@@ -115,6 +177,39 @@ exports[`content-rich > handles html within code blocks 1`] = `
115177
"
116178
`;
117179
180+
exports[`content-rich > hashtag adds bdi 1`] = `
181+
"<p>
182+
Testing bdi is added
183+
<a
184+
class="mention hashtag"
185+
rel="nofollow noopener noreferrer"
186+
to="/m.webtoo.ls/tags/turkey"
187+
><bdi>#<span>turkey</span></bdi></a
188+
>
189+
</p>
190+
<p></p>
191+
"
192+
`;
193+
194+
exports[`content-rich > hashtag doesn't add 2 bdi 1`] = `
195+
"<p>
196+
Testing bdi not added
197+
<a
198+
class="mention hashtag"
199+
rel="nofollow noopener noreferrer"
200+
to="/m.webtoo.ls/tags/turkey"
201+
><bdi></bdi
202+
></a>
203+
</p>
204+
<p></p>
205+
"
206+
`;
207+
208+
exports[`content-rich > hides collapsed mentions 1`] = `
209+
"<p>content</p>
210+
"
211+
`;
212+
118213
exports[`content-rich > inline code with link 1`] = `
119214
"<p>
120215
Inline code with link:
@@ -139,8 +234,9 @@ exports[`content-rich > link + mention 1`] = `
139234
class="u-url mention"
140235
rel="nofollow noopener noreferrer"
141236
to="/webtoo.ls/@vitest"
142-
></a
143-
></span>
237+
><bdi>@<span>vitest</span></bdi></a
238+
></span
239+
>
144240
(migrated from chai+mocha)
145241
<a
146242
href="https://github.com/ayoayco/astro-reactive-library/pull/203"
@@ -159,6 +255,53 @@ exports[`content-rich > plain text 1`] = `
159255
"
160256
`;
161257
258+
exports[`content-rich > shows some collapsed mentions grouped 1`] = `
259+
"<p>
260+
<mention-group
261+
><spanclass="h-card"
262+
><a
263+
class="u-url mention"
264+
rel="nofollow noopener noreferrer"
265+
to="/m.webtoo.ls/@antfu"
266+
><bdi>@<span>antfu</span></bdi></a
267+
></span
268+
>
269+
<spanclass="h-card"
270+
><a
271+
class="u-url mention"
272+
rel="nofollow noopener noreferrer"
273+
to="/m.webtoo.ls/@patak"
274+
><bdi>@<span>patak</span></bdi></a
275+
></span
276+
>
277+
<spanclass="h-card"
278+
><a
279+
class="u-url mention"
280+
rel="nofollow noopener noreferrer"
281+
to="/m.webtoo.ls/@sxzz"
282+
><bdi>@<span>sxzz</span></bdi></a
283+
></span
284+
></mention-group
285+
>content
286+
</p>
287+
"
288+
`;
289+
290+
exports[`content-rich > shows some collapsed mentions inline 1`] = `
291+
"<p>
292+
<spanclass="h-card"
293+
><a
294+
class="u-url mention"
295+
rel="nofollow noopener noreferrer"
296+
to="/m.webtoo.ls/@antfu"
297+
><bdi>@<span>antfu</span></bdi></a
298+
></span
299+
>
300+
content
301+
</p>
302+
"
303+
`;
304+
162305
exports[`editor > transform mentions 1`] = `
163306
"
164307
@elk Hello"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp