File tree Expand file tree Collapse file tree
android/src/main/java/com/richtext Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import com.richtext.spans.RichTextLinkSpan
66import com.richtext.spans.RichTextHeadingSpan
77import com.richtext.spans.RichTextParagraphSpan
88import com.richtext.spans.RichTextTextSpan
9+ import com.richtext.utils.addSpacing
910import org.commonmark.node.*
1011
1112interface NodeRenderer {
@@ -56,7 +57,7 @@ class ParagraphRenderer : NodeRenderer {
5657 )
5758 }
5859
59- builder.append( " \n " )
60+ builder.addSpacing( )
6061 }
6162}
6263
@@ -84,7 +85,8 @@ class HeadingRenderer : NodeRenderer {
8485 android.text.SpannableString .SPAN_EXCLUSIVE_EXCLUSIVE
8586 )
8687 }
87- builder.append(" \n " )
88+
89+ builder.addSpacing()
8890 }
8991}
9092
Original file line number Diff line number Diff line change 1+ package com.richtext.utils
2+
3+ import android.text.SpannableStringBuilder
4+
5+ /* *
6+ * Adds Zero Width Space spacing between markdown elements.
7+ *
8+ * Uses \u200B (Zero Width Space) characters for spacing because:
9+ * - Invisible but takes up space, providing consistent visual spacing
10+ * - Doesn't interfere with text rendering or font metrics
11+ */
12+ fun SpannableStringBuilder.addSpacing () {
13+ append(" \u200B \n \u200B \n " )
14+ }
Original file line number Diff line number Diff line change 22#import " NodeRenderer.h"
33#import " RenderContext.h"
44#import " MarkdownASTNode.h"
5+ #import " SpacingUtils.h"
56
67@interface ParagraphRenderer : NSObject <NodeRenderer>
78@end
@@ -59,15 +60,8 @@ - (void)renderNodeRecursive:(MarkdownASTNode *)node
5960 for (NSUInteger i = 0 ; i < node.children .count ; i++) {
6061 MarkdownASTNode *child = node.children [i];
6162 [self renderNodeRecursive: child into: out font: font color: color context: context isTopLevel: NO ];
62- // Add spacing between paragraphs (MD4C doesn't provide empty lines between blocks)
63- // This is intentional rendering behavior to match markdown visual expectations
6463 if (child.type == MarkdownNodeTypeParagraph && i < node.children .count - 1 ) {
65- NSAttributedString *spacing = [[NSAttributedString alloc ]
66- initWithString: @" \n\n "
67- attributes: @{
68- NSFontAttributeName : font,
69- NSForegroundColorAttributeName : color
70- }];
64+ NSAttributedString *spacing = createSpacing ();
7165 [out appendAttributedString: spacing];
7266 }
7367 }
@@ -255,12 +249,7 @@ - (void)renderNode:(MarkdownASTNode *)node
255249 }
256250 }
257251
258- NSAttributedString *spacing = [[NSAttributedString alloc ]
259- initWithString: @" \n\n "
260- attributes: @{
261- NSFontAttributeName : font,
262- NSForegroundColorAttributeName : color
263- }];
252+ NSAttributedString *spacing = createSpacing ();
264253 [output appendAttributedString: spacing];
265254}
266255@end
Original file line number Diff line number Diff line change 1+ #import < Foundation/Foundation.h>
2+ #import < UIKit/UIKit.h>
3+
4+ NS_ASSUME_NONNULL_BEGIN
5+
6+ /* *
7+ * Creates NSAttributedString with Zero Width Space spacing.
8+ *
9+ * Uses \u200B (Zero Width Space) characters for spacing because:
10+ * - Invisible but takes up space, providing consistent visual spacing
11+ * - Doesn't interfere with text rendering or font metrics
12+ */
13+ extern NSAttributedString *createSpacing (void );
14+
15+ NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change 1+ #import " SpacingUtils.h"
2+
3+ NSAttributedString *createSpacing (void ) {
4+ return [[NSAttributedString alloc ] initWithString: @" \u200B\n\u200B\n " ];
5+ }
You can’t perform that action at this time.
0 commit comments