Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
M
matrix-appservice-discord
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Wiki externe
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Extraits de code
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de paquets
Registre de conteneurs
Registre de modèles
Opération
Environnements
Modules Terraform
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté GitLab
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
salixor
matrix-appservice-discord
Validations
c3bb2360
Non vérifiée
Valider
c3bb2360
rédigé
21 déc. 2018
par
Sorunome
Parcourir les fichiers
Options
Téléchargements
Plain Diff
Merge remote-tracking branch 'origin/soru/links' into soru/html-to-markdown
parents
27c3adf6
56e5f65c
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
2
Afficher les modifications d'espaces
En ligne
Côte à côte
Affichage de
2 fichiers modifiés
src/matrixmessageprocessor.ts
+20
-5
20 ajouts, 5 suppressions
src/matrixmessageprocessor.ts
test/test_matrixmessageprocessor.ts
+37
-2
37 ajouts, 2 suppressions
test/test_matrixmessageprocessor.ts
avec
57 ajouts
et
7 suppressions
src/matrixmessageprocessor.ts
+
20
−
5
Voir le fichier @
c3bb2360
...
...
@@ -62,9 +62,15 @@ export class MatrixMessageProcessor {
}
msg
=
msg
.
replace
(
/@room/g
,
"
@here
"
);
const
escapeChars
=
[
"
\\
"
,
"
*
"
,
"
_
"
,
"
~
"
,
"
`
"
];
msg
=
msg
.
split
(
"
"
).
map
((
s
)
=>
{
if
(
s
.
match
(
/^https
?
:
\/\/
/
))
{
return
s
;
}
escapeChars
.
forEach
((
char
)
=>
{
msg
=
msg
.
replace
(
new
RegExp
(
"
\\
"
+
char
,
"
g
"
),
"
\\
"
+
char
);
s
=
s
.
replace
(
new
RegExp
(
"
\\
"
+
char
,
"
g
"
),
"
\\
"
+
char
);
});
return
s
;
}).
join
(
"
"
);
return
msg
;
}
...
...
@@ -109,10 +115,19 @@ export class MatrixMessageProcessor {
return
`<#
${
match
[
1
]}
>`
;
}
private
async
parseLinkContent
(
node
:
Parser
.
HTMLElement
):
Promise
<
string
>
{
const
attrs
=
node
.
attributes
;
const
content
=
await
this
.
walkChildNodes
(
node
);
if
(
!
attrs
.
href
||
content
===
attrs
.
href
)
{
return
content
;
}
return
`[
${
content
}
](
${
attrs
.
href
}
)`
;
}
private
async
parsePillContent
(
node
:
Parser
.
HTMLElement
):
Promise
<
string
>
{
const
attrs
=
node
.
attributes
;
if
(
!
attrs
.
href
||
!
attrs
.
href
.
startsWith
(
MATRIX_TO_LINK
))
{
return
await
this
.
walkChildNodes
(
node
);
return
await
this
.
parseLinkContent
(
node
);
}
const
id
=
attrs
.
href
.
replace
(
MATRIX_TO_LINK
,
""
);
let
reply
=
""
;
...
...
@@ -126,7 +141,7 @@ export class MatrixMessageProcessor {
break
;
}
if
(
!
reply
)
{
return
await
this
.
walkChildNodes
(
node
);
return
await
this
.
parseLinkContent
(
node
);
}
return
reply
;
}
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
test/test_matrixmessageprocessor.ts
+
37
−
2
Voir le fichier @
c3bb2360
...
...
@@ -73,6 +73,13 @@ describe("MatrixMessageProcessor", () => {
const
result
=
await
mp
.
FormatMessage
(
msg
,
guild
as
any
);
expect
(
result
).
is
.
equal
(
"
hey @here
"
);
});
it
(
"
doesn't discord-escape links
"
,
async
()
=>
{
const
mp
=
new
MatrixMessageProcessor
(
bot
,
opts
);
const
guild
=
new
MockGuild
(
"
1234
"
);
const
msg
=
getPlainMessage
(
"
http://example.com/_test_/
"
);
const
result
=
await
mp
.
FormatMessage
(
msg
,
guild
as
any
);
expect
(
result
).
is
.
equal
(
"
http://example.com/_test_/
"
);
});
});
describe
(
"
FormatMessage / formatted_body / simple
"
,
()
=>
{
it
(
"
leaves blank stuff untouched
"
,
async
()
=>
{
...
...
@@ -200,6 +207,34 @@ code
const
result
=
await
mp
.
FormatMessage
(
msg
,
guild
as
any
);
expect
(
result
).
is
.
equal
(
"
test reply
"
);
});
it
(
"
parses links
"
,
async
()
=>
{
const
mp
=
new
MatrixMessageProcessor
(
bot
,
opts
);
const
guild
=
new
MockGuild
(
"
1234
"
);
const
msg
=
getHtmlMessage
(
"
<a href=
\"
http://example.com
\"
>link</a>
"
);
const
result
=
await
mp
.
FormatMessage
(
msg
,
guild
as
any
);
expect
(
result
).
is
.
equal
(
"
[link](http://example.com)
"
);
});
it
(
"
parses links with same content
"
,
async
()
=>
{
const
mp
=
new
MatrixMessageProcessor
(
bot
,
opts
);
const
guild
=
new
MockGuild
(
"
1234
"
);
const
msg
=
getHtmlMessage
(
"
<a href=
\"
http://example.com
\"
>http://example.com</a>
"
);
const
result
=
await
mp
.
FormatMessage
(
msg
,
guild
as
any
);
expect
(
result
).
is
.
equal
(
"
http://example.com
"
);
});
it
(
"
doesn't discord-escape links
"
,
async
()
=>
{
const
mp
=
new
MatrixMessageProcessor
(
bot
,
opts
);
const
guild
=
new
MockGuild
(
"
1234
"
);
const
msg
=
getHtmlMessage
(
"
<a href=
\"
http://example.com/_blah_/
\"
>link</a>
"
);
const
result
=
await
mp
.
FormatMessage
(
msg
,
guild
as
any
);
expect
(
result
).
is
.
equal
(
"
[link](http://example.com/_blah_/)
"
);
});
it
(
"
doesn't discord-escape links with same content
"
,
async
()
=>
{
const
mp
=
new
MatrixMessageProcessor
(
bot
,
opts
);
const
guild
=
new
MockGuild
(
"
1234
"
);
const
msg
=
getHtmlMessage
(
"
<a href=
\"
http://example.com/_blah_/
\"
>http://example.com/_blah_/</a>
"
);
const
result
=
await
mp
.
FormatMessage
(
msg
,
guild
as
any
);
expect
(
result
).
is
.
equal
(
"
http://example.com/_blah_/
"
);
});
});
describe
(
"
FormatMessage / formatted_body / discord
"
,
()
=>
{
it
(
"
Parses user pills
"
,
async
()
=>
{
...
...
@@ -218,7 +253,7 @@ code
guild
.
members
.
set
(
"
12345
"
,
member
);
const
msg
=
getHtmlMessage
(
"
<a href=
\"
https://matrix.to/#/@_discord_789:localhost
\"
>TestUsername</a>
"
);
const
result
=
await
mp
.
FormatMessage
(
msg
,
guild
as
any
);
expect
(
result
).
is
.
equal
(
"
TestUsername
"
);
expect
(
result
).
is
.
equal
(
"
[
TestUsername
](https://matrix.to/#/@_discord_789:localhost)
"
);
});
it
(
"
Parses channel pills
"
,
async
()
=>
{
const
mp
=
new
MatrixMessageProcessor
(
bot
,
opts
);
...
...
@@ -258,7 +293,7 @@ code
const
guild
=
new
MockGuild
(
"
1234
"
);
const
msg
=
getHtmlMessage
(
"
<a href=
\"
http://example.com
\"
><em>yay?</em></a>
"
);
const
result
=
await
mp
.
FormatMessage
(
msg
,
guild
as
any
);
expect
(
result
).
is
.
equal
(
"
*yay?*
"
);
expect
(
result
).
is
.
equal
(
"
[
*yay?*
](http://example.com)
"
);
});
it
(
"
Converts @room to @here
"
,
async
()
=>
{
const
mp
=
new
MatrixMessageProcessor
(
bot
,
opts
);
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Please
se connecter
to comment