Skip to content


A string that allows you to set attributes for text ranges. Attributed strings are commonly used to apply formatting to a string.


namespace bdn {
    class AttributedString


To create an instance of AttributedString simply call std::make_shared<AttributedString>(). A special implementation of std::make_shared will create the platform specific version of an AttributedString.


  • virtual bool fromHTML(const std::string &html)

    Replaces the contents of the AttributedString with the given html markup code.

  • virtual std::string toHTML() const

    Returns the contents as a string containing HTML markup code.


  • void fromJSON(const bdn::json& json)

    Replaces the contents of the string with the data from json.

    HTML form:

    {"html" : <html-string>}

    Raw form:

    {"string" : <raw string>,
     "ranges" : [
        "start" : <int>,
        "length" : <int>,
        attributes: { <name> : <value>, ... }
  • bdn::json toJSON() const

    Returns the output of toHTML() wrapped in a json object.


  • virtual void addAttribute(std::string attributeName, std::any value, Range range)

    Adds an attribute to the specified range. The value is converted using the types fromAny function.

    Attribute Name Type
    foreground-color  Color
    font  Font
    link  std::string
    baseline-offset  float
  • virtual void addAttributes(AttributeMap attributes, Range range)

    Adds all attributes in attributes to the specified range.


  • CreatorStack

    A GlobalStack used to create platform specific versions of AttributedString.