I’ve created a custom Node using PM and tip for handling inline icons on our text editor. I was able to get it working well for ion-icons and font awesome. I’m struggling with the Material design icons as they follow a slightly different formatting:
a common icon for the html would be:
<i class=""></i>"
but material icons is as follows:
<i class="material-icons">{{class name}}</i>
my command function is as follows:
commands({ type }) {
return (attrs) => {
if (attrs && attrs.icon.family && attrs.icon.id) {
attrs.iconType = attrs.icon.family;
attrs.iconId = attrs.icon.id;
}
return function (state, dispatch) {
let { $from, $to } = state.selection
if (!$from.parent.canReplaceWith($from, $to, type))
return
if (dispatch)
if (attrs.iconType == 'material') {
let { tr, schema } = state;
let body = schema.text(`${attrs.iconId}`);
let data = type.create(attrs, body);
console.log(data)
// dispatch(tr.insertText(attrs.iconId));
// state.setSelection($from, $from + attrs.iconId.length);
// wrapIn(type.create(attrs));
tr.replaceSelectionWith(type.create(attrs, data));
return dispatch(tr);
} else {
return dispatch(state.tr.replaceSelectionWith(type.create(attrs)))
}
}
};
}
The result for material icons is inserted into the correct place but is not populated with the icon class name in as text between the <i>
tags.