@expensify/react-native-live-markdown 0.1.197 → 0.1.198
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5,34 +5,27 @@
|
|
|
5
5
|
- (void)drawBackgroundForGlyphRange:(NSRange)glyphsToShow atPoint:(CGPoint)origin {
|
|
6
6
|
[super drawBackgroundForGlyphRange:glyphsToShow atPoint:origin];
|
|
7
7
|
|
|
8
|
+
NSTextStorage *textStorage = self.textStorage;
|
|
9
|
+
|
|
8
10
|
[self enumerateLineFragmentsForGlyphRange:glyphsToShow usingBlock:^(CGRect rect, CGRect usedRect, NSTextContainer * _Nonnull textContainer, NSRange glyphRange, BOOL * _Nonnull stop) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
NSNumber *depth = [textStorage attribute:RCTLiveMarkdownBlockquoteDepthAttributeName atIndex:glyphRange.location effectiveRange:nil];
|
|
12
|
+
if (depth == nil) {
|
|
13
|
+
return; // not a blockquote
|
|
14
|
+
}
|
|
15
|
+
|
|
11
16
|
RCTMarkdownUtils *markdownUtils = [self valueForKey:@"markdownUtils"];
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
CGFloat paddingLeft = origin.x;
|
|
25
|
-
CGFloat paddingTop = origin.y;
|
|
26
|
-
CGFloat y = paddingTop + rect.origin.y;
|
|
27
|
-
CGFloat width = markdownUtils.markdownStyle.blockquoteBorderWidth;
|
|
28
|
-
CGFloat height = rect.size.height;
|
|
29
|
-
CGFloat shift = markdownUtils.markdownStyle.blockquoteMarginLeft + markdownUtils.markdownStyle.blockquoteBorderWidth + markdownUtils.markdownStyle.blockquotePaddingLeft;
|
|
30
|
-
for (int level = 0; level < currentDepth; level++) {
|
|
31
|
-
CGFloat x = paddingLeft + (level * shift) + markdownUtils.markdownStyle.blockquoteMarginLeft;
|
|
32
|
-
CGRect lineRect = CGRectMake(x, y, width, height);
|
|
33
|
-
[markdownUtils.markdownStyle.blockquoteBorderColor setFill];
|
|
34
|
-
UIRectFill(lineRect);
|
|
35
|
-
}
|
|
17
|
+
CGFloat paddingLeft = origin.x;
|
|
18
|
+
CGFloat paddingTop = origin.y;
|
|
19
|
+
CGFloat y = paddingTop + rect.origin.y;
|
|
20
|
+
CGFloat width = markdownUtils.markdownStyle.blockquoteBorderWidth;
|
|
21
|
+
CGFloat height = rect.size.height;
|
|
22
|
+
CGFloat shift = markdownUtils.markdownStyle.blockquoteMarginLeft + markdownUtils.markdownStyle.blockquoteBorderWidth + markdownUtils.markdownStyle.blockquotePaddingLeft;
|
|
23
|
+
|
|
24
|
+
for (NSUInteger level = 0; level < [depth unsignedIntValue]; level++) {
|
|
25
|
+
CGFloat x = paddingLeft + (level * shift) + markdownUtils.markdownStyle.blockquoteMarginLeft;
|
|
26
|
+
CGRect lineRect = CGRectMake(x, y, width, height);
|
|
27
|
+
[markdownUtils.markdownStyle.blockquoteBorderColor setFill];
|
|
28
|
+
UIRectFill(lineRect);
|
|
36
29
|
}
|
|
37
30
|
}];
|
|
38
31
|
}
|
package/apple/RCTMarkdownUtils.h
CHANGED
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
|
|
4
4
|
NS_ASSUME_NONNULL_BEGIN
|
|
5
5
|
|
|
6
|
+
const NSAttributedStringKey RCTLiveMarkdownBlockquoteDepthAttributeName = @"RCTLiveMarkdownBlockquoteDepth";
|
|
7
|
+
|
|
6
8
|
@interface RCTMarkdownUtils : NSObject
|
|
7
9
|
|
|
8
10
|
@property (nonatomic) RCTMarkdownStyle *markdownStyle;
|
|
9
11
|
@property (nonatomic) NSNumber *parserId;
|
|
10
|
-
@property (nonatomic) NSMutableArray<NSDictionary *> *blockquoteRangesAndLevels;
|
|
11
12
|
|
|
12
13
|
- (NSAttributedString *)parseMarkdown:(nullable NSAttributedString *)input withAttributes:(nullable NSDictionary<NSAttributedStringKey, id>*)attributes;
|
|
13
14
|
|
|
@@ -46,8 +46,6 @@
|
|
|
46
46
|
// This is a workaround that applies the NSUnderlineStyleNone to the string before iterating over ranges which resolves this problem.
|
|
47
47
|
[attributedString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleNone] range:NSMakeRange(0, attributedString.length)];
|
|
48
48
|
|
|
49
|
-
_blockquoteRangesAndLevels = [NSMutableArray new];
|
|
50
|
-
|
|
51
49
|
for (MarkdownRange *markdownRange in markdownRanges) {
|
|
52
50
|
[self applyRangeToAttributedString:attributedString
|
|
53
51
|
type:std::string([markdownRange.type UTF8String])
|
|
@@ -134,10 +132,7 @@
|
|
|
134
132
|
paragraphStyle.firstLineHeadIndent = indent;
|
|
135
133
|
paragraphStyle.headIndent = indent;
|
|
136
134
|
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:range];
|
|
137
|
-
[
|
|
138
|
-
@"range": [NSValue valueWithRange:range],
|
|
139
|
-
@"depth": @(depth)
|
|
140
|
-
}];
|
|
135
|
+
[attributedString addAttribute:RCTLiveMarkdownBlockquoteDepthAttributeName value:@(depth) range:range];
|
|
141
136
|
} else if (type == "pre") {
|
|
142
137
|
[attributedString addAttribute:NSForegroundColorAttributeName value:_markdownStyle.preColor range:range];
|
|
143
138
|
NSRange rangeForBackground = [[attributedString string] characterAtIndex:range.location] == '\n' ? NSMakeRange(range.location + 1, range.length - 1) : range;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expensify/react-native-live-markdown",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.198",
|
|
4
4
|
"description": "Drop-in replacement for React Native's TextInput component with Markdown formatting.",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|