react-native-markdown-renderer icon indicating copy to clipboard operation
react-native-markdown-renderer copied to clipboard

Blockquote text style

Open mi5q opened this issue 7 years ago • 2 comments
trafficstars

Is it possible to style Text inside the blockquote?

mi5q avatar Aug 30 '18 12:08 mi5q

👍 Need that too

p-grzelczak avatar Aug 30 '18 14:08 p-grzelczak

This is really quick and dirty but I used this rule:

let styleChildren = function(child, style){
   let grandChildren = []
   let childStyle = {}
   if(_.isNil(child)){
     return child
   }
   if('props' in child && 'children' in child.props){
     if(typeof(child.props.children) != 'object'){
       grandChildren = child.props.children
     }else{
       grandChildren = _.map(child.props.children, (grandChild) => {
         return this.styleChildren(grandChild, style)
       })
     }
     if(child.props.style){
      childStyle = child.props.style
    }
   }
   
   return React.cloneElement(child, {
     key: getUniqueID(),
     style: {...childStyle, ...style},
     children: grandChildren
   })
 }

Then apply that like so

<Markdown rules={rules}>
{myMarkDown}
</Markdown>

Probably has a tonne of knock on effects by overriding all the style of all the child objects, but it's working for me so far! _ is of course lodash so you'll need import _ 'lodash'; or to replace the map function.

Sam-Martin avatar May 19 '19 16:05 Sam-Martin