Fix pills for CIDER too

This commit is contained in:
Travis Ralston
2019-09-30 20:37:24 -06:00
parent 2824f468d9
commit ce0a534db1
6 changed files with 27 additions and 7 deletions

View File

@@ -15,11 +15,9 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { MATRIXTO_URL_PATTERN } from '../linkify-matrix';
import { walkDOMDepthFirst } from "./dom";
import { checkBlockNode } from "../HtmlUtils";
const REGEX_MATRIXTO = new RegExp(MATRIXTO_URL_PATTERN);
import {getPrimaryPermalinkEntity} from "../utils/permalinks/RoomPermalinkCreator";
function parseAtRoomMentions(text, partCreator) {
const ATROOM = "@room";
@@ -41,9 +39,8 @@ function parseAtRoomMentions(text, partCreator) {
function parseLink(a, partCreator) {
const {href} = a;
const pillMatch = REGEX_MATRIXTO.exec(href) || [];
const resourceId = pillMatch[1]; // The room/user ID
const prefix = pillMatch[2]; // The first character of prefix
const resourceId = getPrimaryPermalinkEntity(href); // The room/user ID
const prefix = resourceId ? resourceId[0] : undefined; // First character of ID
switch (prefix) {
case "@":
return partCreator.userPill(a.textContent, resourceId);

View File

@@ -16,6 +16,7 @@ limitations under the License.
*/
import Markdown from '../Markdown';
import {makeGenericPermalink} from "../utils/permalinks/RoomPermalinkCreator";
export function mdSerialize(model) {
return model.parts.reduce((html, part) => {
@@ -29,7 +30,7 @@ export function mdSerialize(model) {
return html + part.text;
case "room-pill":
case "user-pill":
return html + `[${part.text}](https://matrix.to/#/${part.resourceId})`;
return html + `[${part.text}](${makeGenericPermalink(part.resourceId)})`;
}
}, "");
}