@expensify/react-native-live-markdown 0.1.196 → 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/MarkdownParser.mm
CHANGED
|
@@ -46,6 +46,10 @@
|
|
|
46
46
|
const auto &length = static_cast<int>(item.getProperty(rt, "length").asNumber());
|
|
47
47
|
const auto &depth = item.hasProperty(rt, "depth") ? static_cast<int>(item.getProperty(rt, "depth").asNumber()) : 1;
|
|
48
48
|
|
|
49
|
+
if (length == 0 || start + length > text.length) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
|
|
49
53
|
NSRange range = NSMakeRange(start, length);
|
|
50
54
|
MarkdownRange *markdownRange = [[MarkdownRange alloc] initWithType:@(type.c_str()) range:range depth:depth];
|
|
51
55
|
[markdownRanges addObject:markdownRange];
|
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])
|
|
@@ -70,10 +68,6 @@
|
|
|
70
68
|
}
|
|
71
69
|
|
|
72
70
|
- (void)applyRangeToAttributedString:(NSMutableAttributedString *)attributedString type:(const std::string)type range:(NSRange)range depth:(const int)depth {
|
|
73
|
-
if (range.length == 0 || range.location + range.length > attributedString.length) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
71
|
if (type == "bold" || type == "italic" || type == "code" || type == "pre" || type == "h1" || type == "emoji") {
|
|
78
72
|
UIFont *font = [attributedString attribute:NSFontAttributeName atIndex:range.location effectiveRange:NULL];
|
|
79
73
|
if (type == "bold") {
|
|
@@ -138,10 +132,7 @@
|
|
|
138
132
|
paragraphStyle.firstLineHeadIndent = indent;
|
|
139
133
|
paragraphStyle.headIndent = indent;
|
|
140
134
|
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:range];
|
|
141
|
-
[
|
|
142
|
-
@"range": [NSValue valueWithRange:range],
|
|
143
|
-
@"depth": @(depth)
|
|
144
|
-
}];
|
|
135
|
+
[attributedString addAttribute:RCTLiveMarkdownBlockquoteDepthAttributeName value:@(depth) range:range];
|
|
145
136
|
} else if (type == "pre") {
|
|
146
137
|
[attributedString addAttribute:NSForegroundColorAttributeName value:_markdownStyle.preColor range:range];
|
|
147
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",
|