re-apply markdown when saving a message

This commit is contained in:
Bruno Windels 2019-05-21 17:59:54 +02:00
parent 5373007301
commit 53b6586986
2 changed files with 17 additions and 6 deletions

View file

@ -15,21 +15,31 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
export function htmlSerialize(model) {
import Markdown from '../Markdown';
export function mdSerialize(model) {
return model.parts.reduce((html, part) => {
switch (part.type) {
case "newline":
return html + "<br />";
return html + "\n";
case "plain":
case "pill-candidate":
return html + part.text;
case "room-pill":
case "user-pill":
return html + `<a href="https://matrix.to/#/${part.resourceId}">${part.text}</a>`;
return html + `[${part.text}](https://matrix.to/#/${part.resourceId})`;
}
}, "");
}
export function htmlSerializeIfNeeded(model) {
const md = mdSerialize(model);
const parser = new Markdown(md);
if (!parser.isPlainText()) {
return parser.toHTML();
}
}
export function textSerialize(model) {
return model.parts.reduce((text, part) => {
switch (part.type) {