-
Notifications
You must be signed in to change notification settings - Fork 406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhance documentation of modifyBlocks #263
Comments
More/better documentation would be great! Also happy to replace the demo if you want to do a better one with your integration. Regarding your question, I would do this: Squire.prototype.changeBlockType = function ( tag, attrs ) {
if ( !tag ) {
var config = this._config;
tag = config.blockTag;
attrs = config.blockAttributes;
}
return this.modifyBlocks( function ( frag ) {
var walker = Squire.getBlockWalker( frag, this._root );
var output = this.getDocument().createDocumentFragment();
var node;
while ( node = walker.nextNode() ) {
output.appendChild( this.createElement( tag, attrs, [
Squire.empty( node )
]));
}
return output;
});
}; Then to "make heading", call something like |
That works perfectly, thanks! I'll gebt back to you regarding the docs and demo. |
@neilj Your example of using |
For anyone stumbling here in some 6 years later, this seems to do the trick for making headings with Squire v2.0.2: function toggleBlockType(tag: string) {
editor.modifyBlocks(function (frag): Node {
if (frag.children.length != 1) {
return frag;
}
const orig = frag.firstElementChild;
if (orig === null) {
return frag;
}
const tagName = orig.tagName == tag ? "DIV" : tag;
const elem = frag.ownerDocument.createElement(tagName);
while (orig.firstChild !== null) {
elem.append(orig.firstChild);
}
return elem;
});
} For Svelte, you do something like
|
@neilj, Squire is by far the most elegant, clean and flexible RTE I have worked with. The documentation though needs some examples and guides, especially on extending Squire. I'll be happy to open a PR for that, since I did some really heavy integration work and can provide several howtos:
One thing I am trying to figure out is how to remove entire block formats, in other words realizing "make headline" and "unmake headline". I managed to wrap the selection into a bock tag. Could you provide an example of removing a tag from a fragment:
The text was updated successfully, but these errors were encountered: