NSAttributedString from html with blockquote
I have a simple HTML with a blockquote tag that I would like to show in UILabel
(which is inside UITableViewCell
, so I don't think using UIWebView
is the solution to my problem).
I decided to convert it to NSAttributedString
and everything worked fine, but what I got was quoted text that looks exactly like unquoted text (no indentation, no block mark).
I would like to ask if there is a way to achieve something like the modern quote mentioned here? Or at least some indentation and prefix before each line of the paragraph with a quote (i.e. >
like an oldschool email quote) using NSAttributedString
?
source to share
I realize you asked about this in Obj-C, but I just clicked and noticed that three years have passed and there are no answers and I did it elsewhere, so I might as well share.
let parsedCommentHTML = html.replacingOccurrences(of: "<blockquote>\n", with: "<blockquote>\n<k style=\"color:#ccc; font-size: 2em; font-family: 'Copperplate'\">"</k>")
let blockQuoteCSS = "\nblockquote > p {color:#808080; display: inline;} \n blockquote { background: #f9f9f9;}"
let pCSS = "p {margin-bottom: 0px;}"
let cssStyle = "\(blockQuoteCSS)\n\(pCSS)\n"
return try NSAttributedString(data: ("<html><head><style>\(cssStyle)</style></head><span style=\"font-family: HelveticaNeue-Thin; font-size: 17\">\(parsedCommentHTML)</span></html>").data(using: String.Encoding.unicode)!, options: [NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType], documentAttributes: nil)
source to share