NSAttributedString 不显示段落缩进

NSAttributedString not showing paragraph indentation

我从 HTML 创建了一个 NSAttributedString,就像这样。

decodedString = [[NSAttributedString alloc] initWithData:[encodedString dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: [NSNumber numberWithInt:NSUTF8StringEncoding]} documentAttributes:nil error:nil];

当我在 UITextView 中显示字符串时,除了段落缩进外,一切都显示得很好。

正在转换为 NSAttributedString 的 HTML 是。

"<div><div class=\"article-content\">\n\t\t\t\t\t<p class=\"p1\"><a href=\"http://9to5mac.com/2015/04/08/apple-watch-ship-times-4-to-6-weeks-may-for-edition/apple_watch_liefer1/\" rel=\"attachment wp-att-373515\"><img title=\"Apple online store leaks Watch ship times: 4-6 weeks for some Watch models, &#x2018;May&#x2019; for Edition\" class=\"alignnone size-full wp-image-373515\" src=\"https://9to5mac.files.wordpress.com/2015/04/apple_watch_liefer1.jpg?w=704\" alt=\"apple_watch_liefer1\" width=\"320.000000\"></a></p>\n<p class=\"p1\"><span class=\"s1\">Apple Watch goes up for preorder on April 10 and becomes available April 24 through retail stores and online, but some of Apple&#x2019;s online stores are listing ship dates ranging from April 24th to sometime in May depending on the model. </span></p>\n<p class=\"p1\"><span class=\"s1\">Earlier today some of Apple&#x2019;s online stores, including its German and UK stores, listed various shipping dates for the device for those willing to do a little digging on the site. While the Sport models and Apple Watch with classic leather strap and Milanese bracelet are listed as shipping between April 24th and May 8th, other models are listed as shipping in 4-6 weeks or simply in &#x201C;May&#x201D;. </span></p>\n<p class=\"p1\"><span class=\"s2\"><a href=\"http://macerkopf.de\">macerkopf.de</a></span><span class=\"s1\"> first spotted the shipping dates on the German Apple online store and we later spotted the same dates on the UK and other international stores:</span>\n\t\t\t</p>\n\t\t\n\n<p>Apple Watch Sport: Usually ships &#x201C;24.04. to 5.8. &#x201D;<br>\nApple Watch with modern leather bracelet: Usually ships in &#x201C;4 to 6 weeks&#x201D;<br>\nApple Watch Link Watch: Usually ships in &#x201C;4 to 6 weeks&#x201D;<br>\nApple Watch with leather strap with loop: Usually ships in &#x201C;4 to 6 weeks&#x201D;<br>\nApple Watch with classic leather strap: Usually ships &#x201C;24.04. to 5.8. &#x201D;<br>\nApple Watch with Milanese bracelet: Usually ships &#x201C;24.04. to 5.8. &#x201D;<br>\nApple Watch with Sport Armband: Usually ships</p>\n<p class=\"p1\"><span class=\"s1\">It&#x2019;s unclear if these dates will apply to the US or just international markets, but it&#x2019;s not surprising considering we&#x2019;ve heard Apple Watch stock could be limited at launch. In addition to limiting stock of the gold Watch Edition and the <a href=\"http://9to5mac.com/2015/03/30/apple-watch-faq-preorders-try-on-appointments/\" target=\"_blank\">number of units customers can buy from each collection</a>, we reported earlier this month that <a href=\"http://9to5mac.com/2015/04/03/applecare-for-apple-watch-999-for-edition-79-for-watch-59-for-sport/\"><span class=\"s2\">supplies of the rose gold Edition models will be very tight</span></a> as Apple continues to work out discoloration issues.</span></p>\n<p class=\"p1\">You can get all the details on how preordering and purchasing the Apple Watch will work <a href=\"http://9to5mac.com/2015/03/30/apple-watch-faq-preorders-try-on-appointments/\" target=\"_blank\">in our FAQ here</a>.</p>\n<div id=\"jp-post-flair\" class=\"sharedaddy sd-like-enabled\"><div class=\"sharedaddy sd-block sd-like jetpack-likes-widget-wrapper jetpack-likes-widget-unloaded\" id=\"like-post-wrapper-22754319-373514-55255999c6ac5\"><h3 class=\"sd-title\">Like this:</h3><p class=\"likes-widget-placeholder post-likes-widget-placeholder\"><span class=\"button\"><span>Like</span></span> <span class=\"loading\">Loading...</span></p><a class=\"sd-link-color\"></a></div></div>\n\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\n\n\t\n\n\t\n\n\t\n\n\t\t\t\t</div>\n\t\t\t</div>"

通过一些研究,我了解到 </p> 代码用于段落前后的 space 页边距。我猜 AttributedString 不是 "understanding" 这个或其他东西。

NSAttributedString应该理解</p>

为什么会这样?

我该如何解决?

谢谢!

<p> 标签只是定义文本段落。如果您指的是首行缩进,它们不会格式化段落。

这是您的 HTML 的示例,请注意段落没有缩进。

示例:

https://jsfiddle.net/yoegpuxe/

尝试在每个段落前输入 \t,如果这是您要查找的内容。