title: NSMutableAttributedString from HTML styles li bullets and numbers erroneously
body: <p>I have added a convenience constructor to <code>NSMutableAttributedString</code> to accept a <code>String</code> of HTML and a font.</p>
  
  <pre><code>extension NSMutableAttributedString {
  
      // Convert HTML, but override the font. This copies the symbolic traits from the source font, so things like
      // bold and italic are honored.
      convenience init?(html: String, font: UIFont) {
          guard let data = html.data(using: .utf16, allowLossyConversion: true) else {
              preconditionFailure("string-&gt;data can't fail when lossy conversion is allowed")
          }
  
          do {
              try self.init(data: data, options: [.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil)
  
              enumerateAttribute(.font, in: NSMakeRange(0, length), options: .longestEffectiveRangeNotRequired) { value, range, stop in
  
                  guard
                      let currentFont = value as? UIFont,
                      let newDescriptor = font.fontDescriptor.withSymbolicTraits(currentFont.fontDescriptor.symbolicTraits)
                  else {
                      return
                  }
  
                  let newFont = UIFont(descriptor: newDescriptor, size: font.pointSize)
  
                  addAttribute(.font, value: newFont, range: range)
              }
          } catch {
              return nil
          }
      }
  
  }
  </code></pre>
  
  <p>I'm running some HTML using <code>ol</code> and <code>ul</code> tags through this and placing them on a label.</p>
  
  <pre><code>    let html = [
          "&lt;ul&gt;",
              "&lt;li&gt;not a link&lt;/li&gt;",
              "&lt;li&gt;",
                  "&lt;a href=\"https://www.google.com\"&gt;link&lt;/a&gt;",
              "&lt;/li&gt;",
              "&lt;li&gt;",
                  "&lt;strong&gt;&lt;a href=\"https://www.google.com\"&gt;bold link&lt;/a&gt;&lt;/strong&gt;",
              "&lt;/li&gt;",
              "&lt;li&gt;",
                  "&lt;em&gt;&lt;a href=\"https://www.google.com\"&gt;italic link&lt;/a&gt;&lt;/em&gt;",
              "&lt;/li&gt;",
          "&lt;/ul&gt;",
          "&lt;ol&gt;",
              "&lt;li&gt;not a link&lt;/li&gt;",
              "&lt;li&gt;",
                  "&lt;a href=\"https://www.google.com\"&gt;link&lt;/a&gt;",
              "&lt;/li&gt;",
              "&lt;li&gt;",
                  "&lt;strong&gt;&lt;a href=\"https://www.google.com\"&gt;bold link&lt;/a&gt;&lt;/strong&gt;",
              "&lt;/li&gt;",
              "&lt;li&gt;",
                  "&lt;em&gt;&lt;a href=\"https://www.google.com\"&gt;italic link&lt;/a&gt;&lt;/em&gt;",
              "&lt;/li&gt;",
          "&lt;/ol&gt;",
      ].joined(separator: "\n")
  
      guard let string = NSMutableAttributedString(html: html, font: UIFont.systemFont(ofSize: 18)) else {
          fatalError()
      }
  
      label.attributedText = string
  </code></pre>
  
  <p>When I place this into the label the bullets and numbers are bold, italic, and blue links, even though the <code>strong</code>, <code>em</code>, and <code>a</code> tags are inside the <code>li</code>.</p>
  
  <p><a href="https://i.stack.imgur.com/pvohn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pvohn.png" alt="Display of UILabel with attributed text"></a></p>
  
  <p>I'm guessing this is a bug in <code>NS(Mutable)AttributedString</code> and am prepared to file a radar, but I wanted to see if StackOverflow can find a bug in my code first.</p>