Comments (7)
Hi @rpmonteiro - basically I realised that I don't need to inject a ELEM_ATTR_MAP - draft-js-import-element will now mirror any attributes you add to the entity, e.g.
Entity.create('LINK', 'MUTABLE', {
url: 'http://example.com',
target: '_blank',
'data-some-custom-attribute': '123'
});
I think this was added a few releases after I first started using the library so at first I hadn't realised that was possible. The only gotcha is to remember that draft maps url > href and vice versa but everything else is 1:1 mapping with draft-js-import-element. Hope that helps :)
from draft-js-import-element.
Looking at the code it seems this is only necessary to map attributes to different names, and anything else is just pulled through like for like, so this may be a non-issue
from draft-js-import-element.
Yes, I see that attributes flow in and out nicely (well, data-
attribs at least). Closing!
from draft-js-import-element.
Hey @afhole , I'm trying to achieve the same thing but I'm finding it very difficult. Would you mind just posting a little snippet on how you did it?
Cheers
from draft-js-import-element.
To be honest I still don't get it, but your help was very much appreciated. I might come back to this in a couple days and be like 'this was so simple'. Cheers
from draft-js-import-element.
Essentially if you are already creating link entities like here https://facebook.github.io/draft-js/docs/advanced-topics-entities.html#creating-and-retrieving-entities then you can just add whatever attributes you like alongside href
- obviously just make sure anything with a dash is quoted, e.g. {'data-my-attribute': '123'}
from draft-js-import-element.
I would also like to import a custom ELEM_ATTR_MAP, specifically to add classes to Link elements -- class does not seem to map onto the entity when created. Is there a way to pass this into options?
from draft-js-import-element.
Related Issues (16)
- Soft new lines (br tags) are not being being properly processed HOT 1
- can't handle <img> tag HOT 5
- IE11 receives undefined to `processElement` HOT 1
- Performance issue when converting HTML with many trailing space to editorState HOT 4
- Element class HOT 4
- block containing image cant be deleted
- Return inline elements before to block elements HOT 2
- Convert raw HTML containing datasets into a draftJS contentBlock and back again
- Entities
- Warning: DraftEntity.create will be deprecated soon. Please use "contentState.createEntity" instead. HOT 2
- customInlineFn? HOT 1
- customBlockFn can't get span HOT 2
- What is the difference between draft-js-import-html and draft-js-import-element? HOT 1
- Add CI for pull requests HOT 2
- Soft returns are suffixed with a space HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from draft-js-import-element.