iamacup / react-native-markdown-display

React Native 100% compatible CommonMark renderer
MIT License
608 stars 173 forks source link

Line break issue #140

Closed ankidulol closed 11 months ago

ankidulol commented 3 years ago

Hello, I'm having an issue with line breaks. When I try to add a line break on top of the header it will create a new line but the backlash will also be rendered on top of the header. Line breaks are working fine when added around paragraphs though.

Relevant code:

const content = `# Header
\\
# Another Header
\\
paragraph
\\
\\
paragraph
`;

<Markdown
  rules={{
  paragraph: (node, children, parent, styles) => (
    <Text>                                                                                                                                                                                                                            
      {children}                                                                                                                                                                                                                     
    </Text>                                                                                                                                                                                                                          
  ),                                                                                                                                                                                                                                 
  heading1: (node, children, parent, styles) => (                                                                                                                                                                                    
    <Text>                                                                                                                                                                  
      {children}                                                                                                                                                                                                                     
    </Text>                                                                                                                                                                                                                          
  )
}}>                                                                                                                                                                                                                                      
  {content}
</Markdown>   

Renders:

markdown-issue-1

Here is the result from debugPrintTree

body                                                                                                                                                                                                                                           
 -heading1                                                                                                                                                                                                                                     
 --textgroup                                                                                                                                                                                                                                   
 ---text                                                                                                                                                                                                                                       
 -paragraph                            // --hardbreak should be here ?                                                                                                                                                                                                                             
 --textgroup                                                                                                                                                                                                                                   
 ---text                                                                                                                                                                                                                                       
-heading1                                                                                                                                                                                                                                      
--textgroup                                                                                                                                                                                                                                    
 ---text                                                                                                                                                                                                                                       
 -paragraph                                                                                                                                                                                                                                    
 --hardbreak                                                                                                                                                                                                                                   
 --textgroup                                                                                                                                                                                                                                   
 ---text                                                                                                                                                                                                                                       
 ---softbreak                                                                                                                                                                                                                                  
 --hardbreak
 --hardbreak                                                                                                                                                                                                                                    
 --textgroup                                                                                                                                                                                                                                   
 ---text
Thorugoh commented 3 years ago

Probably at this time you already solved it, but what is happening is that your string is coming with \\\ instead of \\, I saw this happen with \n \r, what I did to solve it was put a .replace(/\\n/g, "\n") in the string

abirchall commented 2 years ago

Is the original intent of the line break to add spacing between the headers? If so, this may be the same as #157