question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a rewrite callback to Editable.getContent()

See original GitHub issue

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

https://github.com/livingdocsIO/editable.js/blob/58f9a24e39b21a6c501c9fb28ef837d8ca018edc/src/core.js#L270

should actually be

return content.extractContent(element, false)

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

https://github.com/livingdocsIO/editable.js/blob/58f9a24e39b21a6c501c9fb28ef837d8ca018edc/src/content.js#L80

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!)

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jenstroegercommented, Sep 28, 2021

I think working with a fragment is more in line with other code in this package (which works with fragments) and it avoids creating elements that have no other purpose than wrapping the fragment — in my use case I’d only unwrap the fragment again.

Either way, the boolean function parameter to content.extractContent() should be fixed.

1reaction
marcbachmanncommented, Sep 28, 2021

@peyerluk what do you think here? Return a div, which is easier to operate on or return a DocumentFragment, which supports easy insertion into the dom?

… Or just use the transform callback 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I change the EditText text without triggering the Text ...
Short answer. You can check which View currently has the focus to distinguish between user and program triggered events. EditText myEditText = (EditText) ......
Read more >
Creating a dynamic editable column - Oracle Communities
I was trying to make my dynamic columns as editable. The problem is my dynamic columns are nested columns.
Read more >
Stencil Utils Reference | BigCommerce Dev Center
The getContent method allows your code to display the cart contents in customized ways. It takes the form utils.api.cart.getContent(options, callback); .
Read more >
EditText - Android Developers
When you define an edit text widget, you must specify the R.styleable. ... android:bufferType, Determines the minimum type that getText() will return.
Read more >
API - Quill Rich Text Editor
Insert embedded content into the editor, returning a Delta representing the change. Source may be "user" , "api" , or "silent" . Calls...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found