macosx: Parse HTML descriptions in addons manager
authorMarvin Scholz <epirat07@gmail.com>
Thu, 7 Jul 2016 01:29:47 +0000 (03:29 +0200)
committerMarvin Scholz <epirat07@gmail.com>
Thu, 7 Jul 2016 12:28:27 +0000 (14:28 +0200)
With this commit, HTML descriptions in the addons manager
are parsed correctly and formatting is applied using a
NSAttributedString and a little bit of CSS to make it use
the system font.

modules/gui/macosx/AddonsWindowController.m

index b770a32..784ade3 100644 (file)
@@ -205,7 +205,13 @@ static void addonsEventsCallback( const vlc_event_t *event, void *data )
     [_name setStringValue:[currentItem name]];
     [_author setStringValue:[currentItem author]];
     [_version setStringValue:[currentItem version]];
-    [_description setString:[currentItem description]];
+
+    // Parse HTML description properly
+    NSMutableString *htmlDescription = [NSMutableString stringWithFormat:@"<style>body{ font-family: -apple-system-body, -apple-system, HelveticaNeue, Arial, sans-serif; }</style>%@", [currentItem description]];
+    [htmlDescription replaceOccurrencesOfString:@"\n" withString:@"<br />" options:NSLiteralSearch range:NSMakeRange(0, [htmlDescription length])];
+    NSAttributedString *attributedDescription = [[NSAttributedString alloc] initWithHTML:[htmlDescription dataUsingEncoding:NSUTF8StringEncoding]
+                                                                      documentAttributes:NULL];
+    [[_description textStorage] setAttributedString:attributedDescription];
 
     [self updateInstallButton:[currentItem isInstalled]];
 }