Fix pills for CIDER too
This commit is contained in:
parent
2824f468d9
commit
ce0a534db1
6 changed files with 27 additions and 7 deletions
|
@ -15,11 +15,9 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { MATRIXTO_URL_PATTERN } from '../linkify-matrix';
|
|
||||||
import { walkDOMDepthFirst } from "./dom";
|
import { walkDOMDepthFirst } from "./dom";
|
||||||
import { checkBlockNode } from "../HtmlUtils";
|
import { checkBlockNode } from "../HtmlUtils";
|
||||||
|
import {getPrimaryPermalinkEntity} from "../utils/permalinks/RoomPermalinkCreator";
|
||||||
const REGEX_MATRIXTO = new RegExp(MATRIXTO_URL_PATTERN);
|
|
||||||
|
|
||||||
function parseAtRoomMentions(text, partCreator) {
|
function parseAtRoomMentions(text, partCreator) {
|
||||||
const ATROOM = "@room";
|
const ATROOM = "@room";
|
||||||
|
@ -41,9 +39,8 @@ function parseAtRoomMentions(text, partCreator) {
|
||||||
|
|
||||||
function parseLink(a, partCreator) {
|
function parseLink(a, partCreator) {
|
||||||
const {href} = a;
|
const {href} = a;
|
||||||
const pillMatch = REGEX_MATRIXTO.exec(href) || [];
|
const resourceId = getPrimaryPermalinkEntity(href); // The room/user ID
|
||||||
const resourceId = pillMatch[1]; // The room/user ID
|
const prefix = resourceId ? resourceId[0] : undefined; // First character of ID
|
||||||
const prefix = pillMatch[2]; // The first character of prefix
|
|
||||||
switch (prefix) {
|
switch (prefix) {
|
||||||
case "@":
|
case "@":
|
||||||
return partCreator.userPill(a.textContent, resourceId);
|
return partCreator.userPill(a.textContent, resourceId);
|
||||||
|
|
|
@ -16,6 +16,7 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Markdown from '../Markdown';
|
import Markdown from '../Markdown';
|
||||||
|
import {makeGenericPermalink} from "../utils/permalinks/RoomPermalinkCreator";
|
||||||
|
|
||||||
export function mdSerialize(model) {
|
export function mdSerialize(model) {
|
||||||
return model.parts.reduce((html, part) => {
|
return model.parts.reduce((html, part) => {
|
||||||
|
@ -29,7 +30,7 @@ export function mdSerialize(model) {
|
||||||
return html + part.text;
|
return html + part.text;
|
||||||
case "room-pill":
|
case "room-pill":
|
||||||
case "user-pill":
|
case "user-pill":
|
||||||
return html + `[${part.text}](https://matrix.to/#/${part.resourceId})`;
|
return html + `[${part.text}](${makeGenericPermalink(part.resourceId)})`;
|
||||||
}
|
}
|
||||||
}, "");
|
}, "");
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,10 @@ export default class PermalinkConstructor {
|
||||||
throw new Error("Not implemented");
|
throw new Error("Not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
forEntity(entityId: string): string {
|
||||||
|
throw new Error("Not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
isPermalinkHost(host: string): boolean {
|
isPermalinkHost(host: string): boolean {
|
||||||
throw new Error("Not implemented");
|
throw new Error("Not implemented");
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,16 @@ export default class RiotPermalinkConstructor extends PermalinkConstructor {
|
||||||
return `${this._riotUrl}/#/group/${groupId}`;
|
return `${this._riotUrl}/#/group/${groupId}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
forEntity(entityId: string): string {
|
||||||
|
if (entityId[0] === '!' || entityId[0] === '#') {
|
||||||
|
return this.forRoom(entityId);
|
||||||
|
} else if (entityId[0] === '@') {
|
||||||
|
return this.forUser(entityId);
|
||||||
|
} else if (entityId[0] === '+') {
|
||||||
|
return this.forGroup(entityId);
|
||||||
|
} else throw new Error("Unrecognized entity");
|
||||||
|
}
|
||||||
|
|
||||||
isPermalinkHost(testHost: string): boolean {
|
isPermalinkHost(testHost: string): boolean {
|
||||||
const parsedUrl = new URL(this._riotUrl);
|
const parsedUrl = new URL(this._riotUrl);
|
||||||
return testHost === (parsedUrl.host || parsedUrl.hostname); // one of the hosts should match
|
return testHost === (parsedUrl.host || parsedUrl.hostname); // one of the hosts should match
|
||||||
|
|
|
@ -253,6 +253,10 @@ export class RoomPermalinkCreator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function makeGenericPermalink(entityId: string): string {
|
||||||
|
return getPermalinkConstructor().forEntity(entityId);
|
||||||
|
}
|
||||||
|
|
||||||
export function makeUserPermalink(userId) {
|
export function makeUserPermalink(userId) {
|
||||||
return getPermalinkConstructor().forUser(userId);
|
return getPermalinkConstructor().forUser(userId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,10 @@ export default class SpecPermalinkConstructor extends PermalinkConstructor {
|
||||||
return `${baseUrl}/#/${groupId}`;
|
return `${baseUrl}/#/${groupId}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
forEntity(entityId: string): string {
|
||||||
|
return `${baseUrl}/#/${entityId}`;
|
||||||
|
}
|
||||||
|
|
||||||
isPermalinkHost(testHost: string): boolean {
|
isPermalinkHost(testHost: string): boolean {
|
||||||
return testHost === host;
|
return testHost === host;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue