Comments (7)
Just pushed a new beta version to npm with a new api for a flatter render. If you don't mind some testing and feedback would be awesome! A simple how-to is included in the updated readme. You can install using the next tag ie. npm install redraft@next
from redraft.
Hey, I'm very glad you like it.
When I was building redraft, I was aiming to be able to render semantically correct output from draft raw. That means that rather than <span style={ { fontStyle: 'italic' } }>
it would render <em>
and that also includes nesting those tags.
I might look into allowing redraft to support an api which is more similar to what draft.js uses as per #20 so I'll keep this in mind as well. Not sure when though so any PRs are also welcome.
It also might be possible to hack a flatter render using react children API, but it will probably only work if the style ranges align.
Check the child type and if its same type and the only child merge those styles and only render the child's children to remove the nested wrapper. Finally use the same component in redraft to render different inline styles passing props for each style. (Did that make any sense?)
from redraft.
Thanks for the suggestion! I 100% understand not getting to PRs promptly, as I’m only responding 3 weeks after your comment. I’m going to explore hacking together a flatter render for cases where style ranges align, because in practical terms, that seems to be the case quite often for our users, so should help clean up the markup considerably in a lot of cases. I’ll post a code snippet here when I have something that works well.
from redraft.
Wasn’t too tricky after all. This code snippet assumes you have a customStyleMap
(API reference) object.
const renderInlineStyle = (style, children, { key }) => {
let elementChild;
const hasSingleElementChild = children.every((child) => {
if (React.isValidElement(child) && !elementChild) {
elementChild = child;
return true;
}
return false;
});
if (hasSingleElementChild && elementChild) {
return React.cloneElement(elementChild, {
style: { ...elementChild.props.style, ...style },
});
}
return (
<span key={ key } style={ style }>
{ children }
</span>
);
};
const renderers = {
/**
* These callbacks will be called recursively to render a nested structure
*/
inline: _.map(customStyleMap, (style, key) => renderInlineStyle.bind(null, style)),
...
};
const Renderer = (props) => (
<div>{ redraft(props.raw, renderers) }</div>
);
from redraft.
I’ll definitely try it out! It’ll take a bit of time before I can get to it, but shouldn’t be too long.
If you want to see our app to see where we are redraft + draft, sign up at https://app.brandcast.io/signup, then go through the first part of the get started flow (the 2nd lesson introduces text editing).
from redraft.
Closing this, as I went ahead and published 0.8.0
from redraft.
Sorry I didn’t follow up back in March and April. Thought I’d mention now that we’ve been using the new flatter rendering in 0.8.0 for a couple months now without issue, and it has helped us greatly with the issues I described in the top of this issue. Thanks again!
from redraft.
Related Issues (20)
- fixed render entities
- [Question] How do I retain inline styles of HTML tags?
- Ignore `.babelrc` in `.npmignore`
- Issue with style renderer and collision in style key HOT 3
- Support complex decorators HOT 8
- Add support for draft-js-plugins HOT 7
- PrismDecorator doesn't work HOT 7
- Decorators incorrectly handle emojis HOT 2
- ReactNative support HOT 7
- Persist multiple spaces between text? HOT 4
- Node styles being treated as equal when having the same amount
- Content Style Not Being Applied Correctly HOT 9
- Commas added to each tag when outputting to string HOT 2
- rendering empty line as `<br />` HOT 2
- Accept customStyleFn similar to draft-js HOT 1
- Just question
- entities block key
- How to get the HTML output after ```convertToRaw()```
- Redraft keeps duplicating entities when entity is copy-pasted from editor HOT 2
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 redraft.