Skip to content

Add a rewrite callback to Editable.getContent() #238

Open
@jenstroeger

Description

First, I think the call to extractContent() in the Editable.getContent() function

return content.extractContent(element)

should actually be

return content.extractContent(element, false)

to ensure that the argument keepUiElements is a boolean as defined in the function’s documentation:

// @param {Boolean} Flag whether to keep ui elements like spellchecking highlights.

Technically, undefined is a falsey value, but it’s just not clean 🤓

Request

I’d like to modify/clean up the content of the host element before it’s serialized to HTML by passing in a callback function. Without it, getContent() returns a serialized HTML which I need to parse into a DOM element, clean it up, and serialize it again… which isn’t great.

So, for example:

const content = editable.getContent(elem, function(e) { 
    // Modify and clean up `e`  where `e` is the cloned and scrubbed `elem`.
});

If you’re interested in adding a callback function parameter to getContent() then I can open a PR. (It’s not a big change, but quite useful!)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions