@expensify/react-native-live-markdown 0.1.209 → 0.1.211
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.
|
@@ -24,10 +24,15 @@
|
|
|
24
24
|
type:std::string([markdownRange.type UTF8String])
|
|
25
25
|
range:markdownRange.range
|
|
26
26
|
depth:markdownRange.depth
|
|
27
|
-
markdownStyle:markdownStyle
|
|
27
|
+
markdownStyle:markdownStyle
|
|
28
|
+
defaultTextAttributes:defaultTextAttributes];
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
[attributedString.string enumerateSubstringsInRange:NSMakeRange(0, attributedString.length)
|
|
32
|
+
options:NSStringEnumerationByLines | NSStringEnumerationSubstringNotRequired
|
|
33
|
+
usingBlock:^(NSString * _Nullable substring, NSRange substringRange, NSRange enclosingRange, BOOL * _Nonnull stop) {
|
|
34
|
+
RCTApplyBaselineOffset(attributedString, enclosingRange);
|
|
35
|
+
}];
|
|
31
36
|
|
|
32
37
|
[attributedString endEditing];
|
|
33
38
|
|
|
@@ -38,7 +43,9 @@
|
|
|
38
43
|
type:(const std::string)type
|
|
39
44
|
range:(const NSRange)range
|
|
40
45
|
depth:(const int)depth
|
|
41
|
-
markdownStyle:(nonnull RCTMarkdownStyle *)markdownStyle
|
|
46
|
+
markdownStyle:(nonnull RCTMarkdownStyle *)markdownStyle
|
|
47
|
+
defaultTextAttributes:(nonnull NSDictionary<NSAttributedStringKey, id> *)defaultTextAttributes
|
|
48
|
+
{
|
|
42
49
|
if (type == "bold" || type == "italic" || type == "code" || type == "pre" || type == "h1" || type == "emoji") {
|
|
43
50
|
UIFont *font = [attributedString attribute:NSFontAttributeName atIndex:range.location effectiveRange:NULL];
|
|
44
51
|
if (type == "bold") {
|
|
@@ -99,7 +106,8 @@
|
|
|
99
106
|
[attributedString addAttribute:NSForegroundColorAttributeName value:markdownStyle.linkColor range:range];
|
|
100
107
|
} else if (type == "blockquote") {
|
|
101
108
|
CGFloat indent = (markdownStyle.blockquoteMarginLeft + markdownStyle.blockquoteBorderWidth + markdownStyle.blockquotePaddingLeft) * depth;
|
|
102
|
-
|
|
109
|
+
NSParagraphStyle *defaultParagraphStyle = defaultTextAttributes[NSParagraphStyleAttributeName];
|
|
110
|
+
NSMutableParagraphStyle *paragraphStyle = defaultParagraphStyle != nil ? [defaultParagraphStyle mutableCopy] : [NSMutableParagraphStyle new];
|
|
103
111
|
paragraphStyle.firstLineHeadIndent = indent;
|
|
104
112
|
paragraphStyle.headIndent = indent;
|
|
105
113
|
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:range];
|
|
@@ -112,12 +120,12 @@
|
|
|
112
120
|
}
|
|
113
121
|
}
|
|
114
122
|
|
|
115
|
-
static void RCTApplyBaselineOffset(NSMutableAttributedString *attributedText)
|
|
123
|
+
static void RCTApplyBaselineOffset(NSMutableAttributedString *attributedText, NSRange attributedTextRange)
|
|
116
124
|
{
|
|
117
125
|
__block CGFloat maximumLineHeight = 0;
|
|
118
126
|
|
|
119
127
|
[attributedText enumerateAttribute:NSParagraphStyleAttributeName
|
|
120
|
-
inRange:
|
|
128
|
+
inRange:attributedTextRange
|
|
121
129
|
options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired
|
|
122
130
|
usingBlock:^(NSParagraphStyle *paragraphStyle, __unused NSRange range, __unused BOOL *stop) {
|
|
123
131
|
if (!paragraphStyle) {
|
|
@@ -135,7 +143,7 @@ static void RCTApplyBaselineOffset(NSMutableAttributedString *attributedText)
|
|
|
135
143
|
__block CGFloat maximumFontLineHeight = 0;
|
|
136
144
|
|
|
137
145
|
[attributedText enumerateAttribute:NSFontAttributeName
|
|
138
|
-
inRange:
|
|
146
|
+
inRange:attributedTextRange
|
|
139
147
|
options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired
|
|
140
148
|
usingBlock:^(UIFont *font, NSRange range, __unused BOOL *stop) {
|
|
141
149
|
if (!font) {
|
|
@@ -152,7 +160,7 @@ static void RCTApplyBaselineOffset(NSMutableAttributedString *attributedText)
|
|
|
152
160
|
CGFloat baseLineOffset = (maximumLineHeight - maximumFontLineHeight) / 2.0;
|
|
153
161
|
[attributedText addAttribute:NSBaselineOffsetAttributeName
|
|
154
162
|
value:@(baseLineOffset)
|
|
155
|
-
range:
|
|
163
|
+
range:attributedTextRange];
|
|
156
164
|
}
|
|
157
165
|
|
|
158
166
|
@end
|
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.211",
|
|
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",
|