From 5a0ee3e5ce46e374eb09674a1aa18fc5176e3ee1 Mon Sep 17 00:00:00 2001 From: Mihai Balint Date: Thu, 29 Mar 2018 13:44:46 +0300 Subject: [PATCH 1/2] Add basic support of numbered lists in IOS --- .../Bypass/Bypass/BPAttributedStringConverter.m | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/platform/ios/Bypass/Bypass/BPAttributedStringConverter.m b/platform/ios/Bypass/Bypass/BPAttributedStringConverter.m index 7f7d62fb..1d882ac4 100644 --- a/platform/ios/Bypass/Bypass/BPAttributedStringConverter.m +++ b/platform/ios/Bypass/Bypass/BPAttributedStringConverter.m @@ -375,10 +375,19 @@ - (void)renderListItemElement:(BPElement *)element NSFontAttributeName : [_displaySettings monospaceFont], NSForegroundColorAttributeName : bulletColor }; - - NSAttributedString *attributedBullet; - attributedBullet = [[NSAttributedString alloc] initWithString:@"• " - attributes:bulletAttributes]; + + NSString *bullet = @"• "; + NSString *flags = [element.parentElement.attributes objectForKey: @"flags"]; + if (flags != nil && [flags isEqualToString: @"1"]) { + NSUInteger liNumber = 1 + [element.parentElement.childElements indexOfObject: element]; + bullet = [NSString stringWithFormat: @"%lu. ", (unsigned long)liNumber]; + bulletAttributes = @{ + NSFontAttributeName : [_displaySettings defaultFont], + NSForegroundColorAttributeName : [_displaySettings defaultColor] + }; + } + NSAttributedString *attributedBullet = [[NSAttributedString alloc] initWithString: bullet + attributes: bulletAttributes]; [target insertAttributedString:attributedBullet atIndex:effectiveRange.location]; From 368987836988930216943d89e3772e941ec268b7 Mon Sep 17 00:00:00 2001 From: Mihai Balint Date: Wed, 4 Apr 2018 11:43:10 +0300 Subject: [PATCH 2/2] Replicate libsoldout logic for interpreting list flags --- platform/ios/Bypass/Bypass/BPAttributedStringConverter.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/platform/ios/Bypass/Bypass/BPAttributedStringConverter.m b/platform/ios/Bypass/Bypass/BPAttributedStringConverter.m index 1d882ac4..35002e5c 100644 --- a/platform/ios/Bypass/Bypass/BPAttributedStringConverter.m +++ b/platform/ios/Bypass/Bypass/BPAttributedStringConverter.m @@ -22,6 +22,7 @@ #import "BPAttributedStringConverter.h" #import "BPDisplaySettings.h" #import "BPImageGetter.h" +#include "markdown.h" NSString *const BPLinkStyleAttributeName = @"NSLinkAttributeName"; @@ -377,8 +378,8 @@ - (void)renderListItemElement:(BPElement *)element }; NSString *bullet = @"• "; - NSString *flags = [element.parentElement.attributes objectForKey: @"flags"]; - if (flags != nil && [flags isEqualToString: @"1"]) { + NSString *flags = element.parentElement[@"flags"]; + if (flags != nil && ([flags integerValue] & MKD_LIST_ORDERED)) { NSUInteger liNumber = 1 + [element.parentElement.childElements indexOfObject: element]; bullet = [NSString stringWithFormat: @"%lu. ", (unsigned long)liNumber]; bulletAttributes = @{