Skip to content

Commit

Permalink
* Added support to skip NSLinkAttributeName for UILabel customization. [
Browse files Browse the repository at this point in the history
#45]

* Added partial support for remote image URL. [#16]
* Added HeaderDoc support
  • Loading branch information
Coeur committed May 1, 2016
1 parent da3aea3 commit dd22092
Show file tree
Hide file tree
Showing 10 changed files with 247 additions and 82 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.

---

## [2.1.0](https://github.com/laptobbe/TSMarkdownParser/releases/tag/2.1.0) (2016/05/01)
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).

#### Added
* Added custom font for quote text for a better user experience [#47](https://github.com/laptobbe/TSMarkdownParser/pull/47)
* Added support to skip NSLinkAttributeName for UILabel customization. [#45](https://github.com/laptobbe/TSMarkdownParser/issues/45)
* Added partial support for remote image URL. [#16](https://github.com/laptobbe/TSMarkdownParser/issues/16)
* Added HeaderDoc support


## [2.0.3](https://github.com/laptobbe/TSMarkdownParser/releases/tag/2.0.3) (2016/04/09)
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).

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


## [2.0.2](https://github.com/laptobbe/TSMarkdownParser/releases/tag/2.0.2) (2016/03/29)
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).

Expand Down
2 changes: 1 addition & 1 deletion TSMarkdownParser.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "TSMarkdownParser"
s.version = "2.0.3"
s.version = "2.1.0"
s.summary = "A markdown to NSAttributedString parser for iOS and OSX"

s.description = <<-DESC
Expand Down
8 changes: 8 additions & 0 deletions TSMarkdownParser.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,7 @@
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNREACHABLE_CODE = YES_AGGRESSIVE;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
ENABLE_TESTABILITY = YES;
Expand All @@ -1109,7 +1110,10 @@
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNKNOWN_PRAGMAS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_LABEL = YES;
GCC_WARN_UNUSED_PARAMETER = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -1147,6 +1151,7 @@
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNREACHABLE_CODE = YES_AGGRESSIVE;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = YES;
ENABLE_NS_ASSERTIONS = NO;
Expand All @@ -1155,7 +1160,10 @@
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNKNOWN_PRAGMAS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_LABEL = YES;
GCC_WARN_UNUSED_PARAMETER = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
PRODUCT_BUNDLE_IDENTIFIER = "se.computertalk.$(PRODUCT_NAME:rfc1034identifier)";
Expand Down
12 changes: 5 additions & 7 deletions TSMarkdownParser/TSBaseParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,21 @@ typedef void (^TSMarkdownParserMatchBlock)(NSTextCheckingResult *match, NSMutabl

@interface TSBaseParser : NSObject

/*
/**
Default attributes for `attributedStringFromMarkdown:`.
*/
@property (nonatomic, strong, nullable) NSDictionary<NSString *, id> *defaultAttributes;

/* Applies defaultAttributes then markdown */
/// Applies defaultAttributes then markdown
- (NSAttributedString *)attributedStringFromMarkdown:(NSString *)markdown;

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

/* Applies markdown */
/// Applies markdown
- (NSAttributedString *)attributedStringFromAttributedMarkdownString:(NSAttributedString *)attributedString;

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

@end
Expand Down
4 changes: 3 additions & 1 deletion TSMarkdownParser/TSBaseParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ - (NSAttributedString *)attributedStringFromMarkdown:(NSString *)markdown attrib

- (NSAttributedString *)attributedStringFromAttributedMarkdownString:(NSAttributedString *)attributedString {
NSMutableAttributedString *mutableAttributedString = [[NSMutableAttributedString alloc] initWithAttributedString:attributedString];

// TODO: evaluate performances of `beginEditing`/`endEditing`
//[mutableAttributedString beginEditing];
@synchronized (self) {
for (TSExpressionBlockPair *expressionBlockPair in self.parsingPairs) {
NSTextCheckingResult *match;
Expand All @@ -93,6 +94,7 @@ - (NSAttributedString *)attributedStringFromAttributedMarkdownString:(NSAttribut
}
}
}
//[mutableAttributedString endEditing];
return mutableAttributedString;
}

Expand Down
73 changes: 50 additions & 23 deletions TSMarkdownParser/TSMarkdownParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ NS_ASSUME_NONNULL_BEGIN

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

@interface TSMarkdownParser : TSBaseParser

Expand All @@ -26,8 +27,24 @@ typedef void (^TSMarkdownParserLevelFormattingBlock)(NSMutableAttributedString *
@property (nonatomic, strong) NSDictionary<NSString *, id> *monospaceAttributes;
@property (nonatomic, strong) NSDictionary<NSString *, id> *strongAttributes;
@property (nonatomic, strong) NSDictionary<NSString *, id> *emphasisAttributes;
/**
* standardParser setting for NSLinkAttributeName
*
* When YES, references to URL are lost and you have freedom to customize the appearance of text.
*
* When NO, reference to URL are kept with NSLinkAttributeName and restrictions to customize the appearance of links apply:
*
* * UILabel is forcing all links to be displayed blue and underline, links aren't clickable
*
* * UITextView's tintColor property is controlling all links color, links are clickable
*
* * NSTextView's linkTextAttributes property is controlling all links attributes
*
* 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.
*/
@property (nonatomic, assign) BOOL skipLinkAttribute;

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

/* 1. examples escaping parsing */

// accepts "`code`", "``code``", ...; ALWAYS use together with `addCodeUnescapingParsingWithFormattingBlock:`
/// accepts "`code`", "``code``", ...; ALWAYS use together with `addCodeUnescapingParsingWithFormattingBlock:`
- (void)addCodeEscapingParsing;
// accepts "\."; ALWAYS use together with `addUnescapingParsing`
/// accepts "\."; ALWAYS use together with `addUnescapingParsing`
- (void)addEscapingParsing;

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

// accepts "# text", "## text", ...
/// accepts "# text", "## text", ...
- (void)addHeaderParsingWithMaxLevel:(unsigned int)maxLevel leadFormattingBlock:(TSMarkdownParserLevelFormattingBlock)leadFormattingBlock textFormattingBlock:(nullable TSMarkdownParserLevelFormattingBlock)formattingBlock;
// accepts "* text", "+ text", "- text", "** text", "++ text", "-- text", ...
/// accepts "* text", "+ text", "- text", "** text", "++ text", "-- text", ...
- (void)addListParsingWithMaxLevel:(unsigned int)maxLevel leadFormattingBlock:(TSMarkdownParserLevelFormattingBlock)leadFormattingBlock textFormattingBlock:(nullable TSMarkdownParserLevelFormattingBlock)formattingBlock;
// accepts "> text", ">> text", ...
/// accepts "> text", ">> text", ...
- (void)addQuoteParsingWithMaxLevel:(unsigned int)maxLevel leadFormattingBlock:(TSMarkdownParserLevelFormattingBlock)leadFormattingBlock textFormattingBlock:(nullable TSMarkdownParserLevelFormattingBlock)formattingBlock;

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

// accepts "#text", "##text", ...
// (conflicts with inline parsing)
/// accepts "#text", "##text", ...
/// (conflicts with inline parsing)
- (void)addShortHeaderParsingWithMaxLevel:(unsigned int)maxLevel leadFormattingBlock:(TSMarkdownParserLevelFormattingBlock)leadFormattingBlock textFormattingBlock:(nullable TSMarkdownParserLevelFormattingBlock)formattingBlock;
// accepts "*text", "+text", "-text", "** text", "++ text", "-- text", ...
// (conflicts with inline parsing)
/// accepts "*text", "+text", "-text", "** text", "++ text", "-- text", ...
/// (conflicts with inline parsing)
- (void)addShortListParsingWithMaxLevel:(unsigned int)maxLevel leadFormattingBlock:(TSMarkdownParserLevelFormattingBlock)leadFormattingBlock textFormattingBlock:(nullable TSMarkdownParserLevelFormattingBlock)formattingBlock;
// accepts ">text", ">>text", ...
// (conflicts with inline parsing)
/// accepts ">text", ">>text", ...
/// (conflicts with inline parsing)
- (void)addShortQuoteParsingWithMaxLevel:(unsigned int)maxLevel leadFormattingBlock:(TSMarkdownParserLevelFormattingBlock)leadFormattingBlock textFormattingBlock:(nullable TSMarkdownParserLevelFormattingBlock)formattingBlock;

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

// accepts "![text](image)"
- (void)addImageParsingWithImageFormattingBlock:(TSMarkdownParserFormattingBlock)formattingBlock alternativeTextFormattingBlock:(TSMarkdownParserFormattingBlock)alternativeFormattingBlock;
// accepts "[text](link)"
- (void)addLinkParsingWithFormattingBlock:(TSMarkdownParserFormattingBlock)formattingBlock;
/// accepts "![text](image)"
- (void)addImageParsingWithImageFormattingBlock:(TSMarkdownParserFormattingBlock)formattingBlock alternativeTextFormattingBlock:(TSMarkdownParserFormattingBlock)alternativeFormattingBlock __attribute__((deprecated("use addImageParsingWithLinkFormattingBlock: instead")));
/// accepts "[text](link)"
- (void)addLinkParsingWithFormattingBlock:(TSMarkdownParserFormattingBlock)formattingBlock __attribute__((deprecated("use addLinkParsingWithLinkFormattingBlock: instead")));
/// accepts "![text](image)"
/// @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.
- (void)addImageParsingWithLinkFormattingBlock:(TSMarkdownParserLinkFormattingBlock)formattingBlock;
/// accepts "[text](link)"
/// @note you can use formattingBlock to add NSLinkAttributeName
- (void)addLinkParsingWithLinkFormattingBlock:(TSMarkdownParserLinkFormattingBlock)formattingBlock;

/* 5. example autodetection parsing: links */

// adds links autodetection support to parser
- (void)addLinkDetectionWithFormattingBlock:(TSMarkdownParserFormattingBlock)formattingBlock;
/// adds links autodetection support to parser
- (void)addLinkDetectionWithFormattingBlock:(TSMarkdownParserFormattingBlock)formattingBlock __attribute__((deprecated("use addLinkDetectionWithLinkFormattingBlock: instead")));
/// adds links autodetection support to parser
/// @note you can use formattingBlock to add NSLinkAttributeName
- (void)addLinkDetectionWithLinkFormattingBlock:(TSMarkdownParserLinkFormattingBlock)formattingBlock;

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

// accepts "`text`", "``text``", ... (conflicts with `addCodeEscapingParsing`)
/// accepts "`text`", "``text``", ...
/// (conflicts with `addCodeEscapingParsing`)
- (void)addMonospacedParsingWithFormattingBlock:(TSMarkdownParserFormattingBlock)formattingBlock;
// accepts "**text**", "__text__"
/// accepts "**text**", "__text__"
- (void)addStrongParsingWithFormattingBlock:(TSMarkdownParserFormattingBlock)formattingBlock;
// accepts "*text*", "_text_"
/// accepts "*text*", "_text_"
- (void)addEmphasisParsingWithFormattingBlock:(TSMarkdownParserFormattingBlock)formattingBlock;

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

// accepts "`hexa`", "``hexa``", ...; to use with `addCodeEscapingParsing`
/// accepts "`hexa`", "``hexa``", ...; to use with `addCodeEscapingParsing`
- (void)addCodeUnescapingParsingWithFormattingBlock:(TSMarkdownParserFormattingBlock)formattingBlock;
// accepts "\hexa"; to use with `addEscapingParsing`
/// accepts "\hexa"; to use with `addEscapingParsing`
- (void)addUnescapingParsing;

@end
Expand Down
Loading

0 comments on commit dd22092

Please sign in to comment.