Skip to content

Dealing with nested tags #5

@rayrw

Description

@rayrw

Hello! I am trying your library inside an IOS playground in Swift 3

The following is my code

import BBCodeString
import BBCodeParser

class MyParser: NSObject, BBCodeStringDelegate {
    func getSupportedTags() -> [Any]! {
        return [
            "b",
            "large"
        ]
    }

   func getAttributesFor(_ element: BBElement!) -> [AnyHashable : Any]! {
        if element.tag == "b" {
            return [NSForegroundColorAttributeName: UIColor.red]
        }

        if element.tag == "large" {
            return [NSFontAttributeName: UIFont.systemFont(ofSize: 20)]
        }

        return [:]
    }
}

var str = NSString(string: "[large][b]Test1[/b][/large] [b][large]Test2[/large][/b] Test3")
var bbCodeString = BBCodeString(bbCode: str as String!, andLayoutProvider: MyParser())
var myString = bbCodeString?.attributedString

print(myString!)

The output is:

Test1 is in red color
Test2 is large
Test3 is normal

What I expect is both Test1 and Test2 are red and large.
When I print out the element.tag inside getAttributesFor, I can only see one tag of them.
I have taken a look at the pull request of this project. It seems to support nested tags.

How to fix it?
Thanks a lot !!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions