Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Revert "MD-escape URLs/alises/user IDs prior to parsing markdown" #1694

Merged
merged 1 commit into from
Jan 7, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 1 addition & 20 deletions src/Markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,33 +55,14 @@ function is_multi_line(node) {
return par.firstChild != par.lastChild;
}

import linkifyMatrix from './linkify-matrix';
import * as linkify from 'linkifyjs';
linkifyMatrix(linkify);

// Thieved from draft-js-export-markdown
function escapeMarkdown(s) {
return s.replace(/[*_`]/g, '\\$&');
}

// Replace URLs, room aliases and user IDs with md-escaped URLs
function linkifyMarkdown(s) {
const links = linkify.find(s);
links.forEach((l) => {
// This may replace several instances of `l.value` at once, but that's OK
s = s.replace(l.value, escapeMarkdown(l.value));
});
return s;
}

/**
* Class that wraps commonmark, adding the ability to see whether
* a given message actually uses any markdown syntax or whether
* it's plain text.
*/
export default class Markdown {
constructor(input) {
this.input = linkifyMarkdown(input);
this.input = input;

const parser = new commonmark.Parser();
this.parsed = parser.parse(this.input);
Expand Down