add pill and emoji serialisation to Md

pull/21833/head
Matthew Hodgson 2018-05-20 03:17:51 +01:00
parent a0d88a829d
commit e9cabf0e85
1 changed files with 23 additions and 3 deletions

View File

@ -177,7 +177,22 @@ export default class MessageComposerInput extends React.Component {
this.plainWithMdPills = new PlainWithPillsSerializer({ pillFormat: 'md' });
this.plainWithIdPills = new PlainWithPillsSerializer({ pillFormat: 'id' });
this.plainWithPlainPills = new PlainWithPillsSerializer({ pillFormat: 'plain' });
this.md = new Md();
this.md = new Md({
rules: [
{
serialize: (obj, children) => {
switch (obj.type) {
case 'pill':
return `[${ obj.data.get('completion') }](${ obj.data.get('href') })`;
case 'emoji':
return obj.data.get('emojiUnicode');
}
}
}
]
});
this.html = new Html({
rules: [
{
@ -567,8 +582,13 @@ export default class MessageComposerInput extends React.Component {
if (enabled) {
// for simplicity when roundtripping, we use slate-md-serializer rather than commonmark
const markdown = this.plainWithMdPills.serialize(this.state.editorState);
if (markdown !== '') {
// weirdly, the Md serializer can't deserialize '' to a valid Value...
if (markdown !== '') {
// FIXME: the MD deserializer doesn't know how to deserialize pills
// and gives no hooks for doing so, so we should manually fix up
// the editorState first in order to preserve them.
editorState = this.md.deserialize(markdown);
}
else {