Skip to content

Commit dd22092

Browse files
committed
* Added support to skip NSLinkAttributeName for UILabel customization. [#45]
* Added partial support for remote image URL. [#16] * Added HeaderDoc support
1 parent da3aea3 commit dd22092

File tree

10 files changed

+247
-82
lines changed

10 files changed

+247
-82
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
44

55
---
66

7+
## [2.1.0](https://github.com/laptobbe/TSMarkdownParser/releases/tag/2.1.0) (2016/05/01)
8+
Released on 2016/05/01. All issues associated with this milestone can be found using this [filter](https://github.com/laptobbe/TSMarkdownParser/issues?q=milestone%3A2.1.0+is%3Aclosed).
9+
10+
#### Added
11+
* Added custom font for quote text for a better user experience [#47](https://github.com/laptobbe/TSMarkdownParser/pull/47)
12+
* Added support to skip NSLinkAttributeName for UILabel customization. [#45](https://github.com/laptobbe/TSMarkdownParser/issues/45)
13+
* Added partial support for remote image URL. [#16](https://github.com/laptobbe/TSMarkdownParser/issues/16)
14+
* Added HeaderDoc support
15+
16+
717
## [2.0.3](https://github.com/laptobbe/TSMarkdownParser/releases/tag/2.0.3) (2016/04/09)
818
Released on 2016/04/09. All issues associated with this milestone can be found using this [filter](https://github.com/laptobbe/TSMarkdownParser/issues?q=milestone%3A2.0.3+is%3Aclosed).
919

@@ -13,6 +23,7 @@ Released on 2016/04/09. All issues associated with this milestone can be found u
1323
#### Fixed
1424
* Fixed CodeEscaping [#46](https://github.com/laptobbe/TSMarkdownParser/issues/46)
1525

26+
1627
## [2.0.2](https://github.com/laptobbe/TSMarkdownParser/releases/tag/2.0.2) (2016/03/29)
1728
Released on 2016/03/29. All issues associated with this milestone can be found using this [filter](https://github.com/laptobbe/TSMarkdownParser/issues?q=milestone%3A2.0.2+is%3Aclosed).
1829

TSMarkdownParser.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "TSMarkdownParser"
3-
s.version = "2.0.3"
3+
s.version = "2.1.0"
44
s.summary = "A markdown to NSAttributedString parser for iOS and OSX"
55

66
s.description = <<-DESC

TSMarkdownParser.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,7 @@
10941094
CLANG_WARN_ENUM_CONVERSION = YES;
10951095
CLANG_WARN_INT_CONVERSION = YES;
10961096
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
1097+
CLANG_WARN_UNREACHABLE_CODE = YES_AGGRESSIVE;
10971098
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
10981099
COPY_PHASE_STRIP = NO;
10991100
ENABLE_TESTABILITY = YES;
@@ -1109,7 +1110,10 @@
11091110
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
11101111
GCC_WARN_UNDECLARED_SELECTOR = YES;
11111112
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
1113+
GCC_WARN_UNKNOWN_PRAGMAS = YES;
11121114
GCC_WARN_UNUSED_FUNCTION = YES;
1115+
GCC_WARN_UNUSED_LABEL = YES;
1116+
GCC_WARN_UNUSED_PARAMETER = YES;
11131117
GCC_WARN_UNUSED_VARIABLE = YES;
11141118
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
11151119
ONLY_ACTIVE_ARCH = YES;
@@ -1147,6 +1151,7 @@
11471151
CLANG_WARN_ENUM_CONVERSION = YES;
11481152
CLANG_WARN_INT_CONVERSION = YES;
11491153
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
1154+
CLANG_WARN_UNREACHABLE_CODE = YES_AGGRESSIVE;
11501155
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
11511156
COPY_PHASE_STRIP = YES;
11521157
ENABLE_NS_ASSERTIONS = NO;
@@ -1155,7 +1160,10 @@
11551160
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
11561161
GCC_WARN_UNDECLARED_SELECTOR = YES;
11571162
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
1163+
GCC_WARN_UNKNOWN_PRAGMAS = YES;
11581164
GCC_WARN_UNUSED_FUNCTION = YES;
1165+
GCC_WARN_UNUSED_LABEL = YES;
1166+
GCC_WARN_UNUSED_PARAMETER = YES;
11591167
GCC_WARN_UNUSED_VARIABLE = YES;
11601168
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
11611169
PRODUCT_BUNDLE_IDENTIFIER = "se.computertalk.$(PRODUCT_NAME:rfc1034identifier)";

TSMarkdownParser/TSBaseParser.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,21 @@ typedef void (^TSMarkdownParserMatchBlock)(NSTextCheckingResult *match, NSMutabl
1414

1515
@interface TSBaseParser : NSObject
1616

17-
/*
17+
/**
1818
Default attributes for `attributedStringFromMarkdown:`.
1919
*/
2020
@property (nonatomic, strong, nullable) NSDictionary<NSString *, id> *defaultAttributes;
2121

22-
/* Applies defaultAttributes then markdown */
22+
/// Applies defaultAttributes then markdown
2323
- (NSAttributedString *)attributedStringFromMarkdown:(NSString *)markdown;
2424

25-
/* Applies attributes then markdown */
25+
/// Applies attributes then markdown
2626
- (NSAttributedString *)attributedStringFromMarkdown:(NSString *)markdown attributes:(nullable NSDictionary<NSString *, id> *)attributes;
2727

28-
/* Applies markdown */
28+
/// Applies markdown
2929
- (NSAttributedString *)attributedStringFromAttributedMarkdownString:(NSAttributedString *)attributedString;
3030

31-
/*
32-
Adds a custom parsing rule to parser. Use `[TSMarkdownParser new]` for an empty parser.
33-
*/
31+
/// Adds a custom parsing rule to parser. Use `[TSMarkdownParser new]` for an empty parser.
3432
- (void)addParsingRuleWithRegularExpression:(NSRegularExpression *)regularExpression block:(TSMarkdownParserMatchBlock)block;
3533

3634
@end

TSMarkdownParser/TSBaseParser.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ - (NSAttributedString *)attributedStringFromMarkdown:(NSString *)markdown attrib
8080

8181
- (NSAttributedString *)attributedStringFromAttributedMarkdownString:(NSAttributedString *)attributedString {
8282
NSMutableAttributedString *mutableAttributedString = [[NSMutableAttributedString alloc] initWithAttributedString:attributedString];
83-
83+
// TODO: evaluate performances of `beginEditing`/`endEditing`
84+
//[mutableAttributedString beginEditing];
8485
@synchronized (self) {
8586
for (TSExpressionBlockPair *expressionBlockPair in self.parsingPairs) {
8687
NSTextCheckingResult *match;
@@ -93,6 +94,7 @@ - (NSAttributedString *)attributedStringFromAttributedMarkdownString:(NSAttribut
9394
}
9495
}
9596
}
97+
//[mutableAttributedString endEditing];
9698
return mutableAttributedString;
9799
}
98100

TSMarkdownParser/TSMarkdownParser.h

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ NS_ASSUME_NONNULL_BEGIN
1212

1313
typedef void (^TSMarkdownParserFormattingBlock)(NSMutableAttributedString *attributedString, NSRange range);
1414
typedef void (^TSMarkdownParserLevelFormattingBlock)(NSMutableAttributedString *attributedString, NSRange range, NSUInteger level);
15+
typedef void (^TSMarkdownParserLinkFormattingBlock)(NSMutableAttributedString *attributedString, NSRange range, NSString * _Nullable link);
1516

1617
@interface TSMarkdownParser : TSBaseParser
1718

@@ -26,8 +27,24 @@ typedef void (^TSMarkdownParserLevelFormattingBlock)(NSMutableAttributedString *
2627
@property (nonatomic, strong) NSDictionary<NSString *, id> *monospaceAttributes;
2728
@property (nonatomic, strong) NSDictionary<NSString *, id> *strongAttributes;
2829
@property (nonatomic, strong) NSDictionary<NSString *, id> *emphasisAttributes;
30+
/**
31+
* standardParser setting for NSLinkAttributeName
32+
*
33+
* When YES, references to URL are lost and you have freedom to customize the appearance of text.
34+
*
35+
* When NO, reference to URL are kept with NSLinkAttributeName and restrictions to customize the appearance of links apply:
36+
*
37+
* * UILabel is forcing all links to be displayed blue and underline, links aren't clickable
38+
*
39+
* * UITextView's tintColor property is controlling all links color, links are clickable
40+
*
41+
* * NSTextView's linkTextAttributes property is controlling all links attributes
42+
*
43+
* If you want clickable links with an UILabel subclass, you should leave skipLinkAttribute to NO and consider using KILabel, TTTAttributedLabel, FRHyperLabel, ... As a bonus, all will lift off the UILabel appearance restrictions for links.
44+
*/
45+
@property (nonatomic, assign) BOOL skipLinkAttribute;
2946

30-
/*
47+
/**
3148
Provides the following default parsing rules from below examples:
3249
* Escaping parsing
3350
* Code escaping parsing using monospaceAttributes
@@ -49,62 +66,72 @@ typedef void (^TSMarkdownParserLevelFormattingBlock)(NSMutableAttributedString *
4966

5067
/* 1. examples escaping parsing */
5168

52-
// accepts "`code`", "``code``", ...; ALWAYS use together with `addCodeUnescapingParsingWithFormattingBlock:`
69+
/// accepts "`code`", "``code``", ...; ALWAYS use together with `addCodeUnescapingParsingWithFormattingBlock:`
5370
- (void)addCodeEscapingParsing;
54-
// accepts "\."; ALWAYS use together with `addUnescapingParsing`
71+
/// accepts "\."; ALWAYS use together with `addUnescapingParsing`
5572
- (void)addEscapingParsing;
5673

5774
/* 2. examples regular block parsing: headers, lists and quotes */
5875

59-
// accepts "# text", "## text", ...
76+
/// accepts "# text", "## text", ...
6077
- (void)addHeaderParsingWithMaxLevel:(unsigned int)maxLevel leadFormattingBlock:(TSMarkdownParserLevelFormattingBlock)leadFormattingBlock textFormattingBlock:(nullable TSMarkdownParserLevelFormattingBlock)formattingBlock;
61-
// accepts "* text", "+ text", "- text", "** text", "++ text", "-- text", ...
78+
/// accepts "* text", "+ text", "- text", "** text", "++ text", "-- text", ...
6279
- (void)addListParsingWithMaxLevel:(unsigned int)maxLevel leadFormattingBlock:(TSMarkdownParserLevelFormattingBlock)leadFormattingBlock textFormattingBlock:(nullable TSMarkdownParserLevelFormattingBlock)formattingBlock;
63-
// accepts "> text", ">> text", ...
80+
/// accepts "> text", ">> text", ...
6481
- (void)addQuoteParsingWithMaxLevel:(unsigned int)maxLevel leadFormattingBlock:(TSMarkdownParserLevelFormattingBlock)leadFormattingBlock textFormattingBlock:(nullable TSMarkdownParserLevelFormattingBlock)formattingBlock;
6582

6683
/* 3. examples short block parsing: headers and lists */
6784
/* they are discouraged and not used by standardParser */
6885

69-
// accepts "#text", "##text", ...
70-
// (conflicts with inline parsing)
86+
/// accepts "#text", "##text", ...
87+
/// (conflicts with inline parsing)
7188
- (void)addShortHeaderParsingWithMaxLevel:(unsigned int)maxLevel leadFormattingBlock:(TSMarkdownParserLevelFormattingBlock)leadFormattingBlock textFormattingBlock:(nullable TSMarkdownParserLevelFormattingBlock)formattingBlock;
72-
// accepts "*text", "+text", "-text", "** text", "++ text", "-- text", ...
73-
// (conflicts with inline parsing)
89+
/// accepts "*text", "+text", "-text", "** text", "++ text", "-- text", ...
90+
/// (conflicts with inline parsing)
7491
- (void)addShortListParsingWithMaxLevel:(unsigned int)maxLevel leadFormattingBlock:(TSMarkdownParserLevelFormattingBlock)leadFormattingBlock textFormattingBlock:(nullable TSMarkdownParserLevelFormattingBlock)formattingBlock;
75-
// accepts ">text", ">>text", ...
76-
// (conflicts with inline parsing)
92+
/// accepts ">text", ">>text", ...
93+
/// (conflicts with inline parsing)
7794
- (void)addShortQuoteParsingWithMaxLevel:(unsigned int)maxLevel leadFormattingBlock:(TSMarkdownParserLevelFormattingBlock)leadFormattingBlock textFormattingBlock:(nullable TSMarkdownParserLevelFormattingBlock)formattingBlock;
7895

7996
/* 4. examples inline bracket parsing: images and links */
8097
/* text accepts newlines and non-bracket parsing */
8198

82-
// accepts "![text](image)"
83-
- (void)addImageParsingWithImageFormattingBlock:(TSMarkdownParserFormattingBlock)formattingBlock alternativeTextFormattingBlock:(TSMarkdownParserFormattingBlock)alternativeFormattingBlock;
84-
// accepts "[text](link)"
85-
- (void)addLinkParsingWithFormattingBlock:(TSMarkdownParserFormattingBlock)formattingBlock;
99+
/// accepts "![text](image)"
100+
- (void)addImageParsingWithImageFormattingBlock:(TSMarkdownParserFormattingBlock)formattingBlock alternativeTextFormattingBlock:(TSMarkdownParserFormattingBlock)alternativeFormattingBlock __attribute__((deprecated("use addImageParsingWithLinkFormattingBlock: instead")));
101+
/// accepts "[text](link)"
102+
- (void)addLinkParsingWithFormattingBlock:(TSMarkdownParserFormattingBlock)formattingBlock __attribute__((deprecated("use addLinkParsingWithLinkFormattingBlock: instead")));
103+
/// accepts "![text](image)"
104+
/// @note you can use formattingBlock to asynchronously download an image from link and replace range with an NSTextAttachment. Be careful of the range when the attributedString is altered.
105+
- (void)addImageParsingWithLinkFormattingBlock:(TSMarkdownParserLinkFormattingBlock)formattingBlock;
106+
/// accepts "[text](link)"
107+
/// @note you can use formattingBlock to add NSLinkAttributeName
108+
- (void)addLinkParsingWithLinkFormattingBlock:(TSMarkdownParserLinkFormattingBlock)formattingBlock;
86109

87110
/* 5. example autodetection parsing: links */
88111

89-
// adds links autodetection support to parser
90-
- (void)addLinkDetectionWithFormattingBlock:(TSMarkdownParserFormattingBlock)formattingBlock;
112+
/// adds links autodetection support to parser
113+
- (void)addLinkDetectionWithFormattingBlock:(TSMarkdownParserFormattingBlock)formattingBlock __attribute__((deprecated("use addLinkDetectionWithLinkFormattingBlock: instead")));
114+
/// adds links autodetection support to parser
115+
/// @note you can use formattingBlock to add NSLinkAttributeName
116+
- (void)addLinkDetectionWithLinkFormattingBlock:(TSMarkdownParserLinkFormattingBlock)formattingBlock;
91117

92118
/* 6. examples inline parsing: monospaced, strong, emphasis and link detection */
93119
/* text accepts newlines */
94120

95-
// accepts "`text`", "``text``", ... (conflicts with `addCodeEscapingParsing`)
121+
/// accepts "`text`", "``text``", ...
122+
/// (conflicts with `addCodeEscapingParsing`)
96123
- (void)addMonospacedParsingWithFormattingBlock:(TSMarkdownParserFormattingBlock)formattingBlock;
97-
// accepts "**text**", "__text__"
124+
/// accepts "**text**", "__text__"
98125
- (void)addStrongParsingWithFormattingBlock:(TSMarkdownParserFormattingBlock)formattingBlock;
99-
// accepts "*text*", "_text_"
126+
/// accepts "*text*", "_text_"
100127
- (void)addEmphasisParsingWithFormattingBlock:(TSMarkdownParserFormattingBlock)formattingBlock;
101128

102129
/* 7. examples unescaping parsing */
103130
/* to use together with `addEscapingParsing` or `addCodeEscapingParsing` */
104131

105-
// accepts "`hexa`", "``hexa``", ...; to use with `addCodeEscapingParsing`
132+
/// accepts "`hexa`", "``hexa``", ...; to use with `addCodeEscapingParsing`
106133
- (void)addCodeUnescapingParsingWithFormattingBlock:(TSMarkdownParserFormattingBlock)formattingBlock;
107-
// accepts "\hexa"; to use with `addEscapingParsing`
134+
/// accepts "\hexa"; to use with `addEscapingParsing`
108135
- (void)addUnescapingParsing;
109136

110137
@end

0 commit comments

Comments
 (0)