             let isMotorway = roadClasses?.contains(.motorway) ?? false
             
             if let name = name, let ref = ref, name != ref, !isMotorway {
-                wayName = phrase(named: .nameWithCode).replacingTokens(using: { (tokenType) -> String in
+                let attributedName = NSAttributedString(string: name, attributes: attrs)
+                let attributedRef = NSAttributedString(string: ref, attributes: attrs)
+                let phrase = NSAttributedString(string: self.phrase(named: .nameWithCode), attributes: attrs)
+                wayName = phrase.replacingTokens(using: { (tokenType) -> NSAttributedString in
                     switch tokenType {
                     case .wayName:
-                        return modifyValueByKey?(.wayName, name) ?? name
+                        return modifyValueByKey?(.wayName, attributedName) ?? attributedName
                     case .code:
-                        return modifyValueByKey?(.code, ref) ?? ref
+                        return modifyValueByKey?(.code, attributedRef) ?? attributedRef
                     default:
                         fatalError("Unexpected token type \(tokenType) in name-and-ref phrase")
                     }
                 })
             } else if let ref = ref, isMotorway, let decimalRange = ref.rangeOfCharacter(from: .decimalDigits), !decimalRange.isEmpty {
-                wayName = modifyValueByKey != nil ? "\(modifyValueByKey!(.code, ref))" : ref
+                let attributedRef = NSAttributedString(string: ref, attributes: attrs)
+                if let modifyValueByKey = modifyValueByKey {
+                    wayName = modifyValueByKey(.code, attributedRef)
+                } else {
+                    wayName = attributedRef
+                }
             } else if name == nil, let ref = ref {
-                wayName = modifyValueByKey != nil ? "\(modifyValueByKey!(.code, ref))" : ref
-            } else {
-                wayName = name != nil ? modifyValueByKey != nil ? "\(modifyValueByKey!(.wayName, name!))" : name! : ""
+                let attributedRef = NSAttributedString(string: ref, attributes: attrs)
+                if let modifyValueByKey = modifyValueByKey {
+                    wayName = modifyValueByKey(.code, attributedRef)
+                } else {
+                    wayName = attributedRef
+                }
+            } else if let name = name {
+                let attributedName = NSAttributedString(string: name, attributes: attrs)
+                if let modifyValueByKey = modifyValueByKey {
+                    wayName = modifyValueByKey(.wayName, attributedName)
+                } else {
+                    wayName = attributedName
+                }
+            } else {
+                wayName = NSAttributedString()
             }
         }
 

     - returns: An instruction as a `String`.
     */
    public func string(for obj: Any?, legIndex: Int?, numberOfLegs: Int?, roadClasses: RoadClasses? = RoadClasses([]), modifyValueByKey: ((TokenType, String) -> String)?) -> String? {
        guard let step = obj as? RouteStep else {
            return nil
        }

                fatalError("Unexpected token type \(tokenType) in individual instruction")
            }
            if tokenType == .wayName {
                return wayName // already modified above
            } else {
                let attributedReplacement = NSAttributedString(string: replacement, attributes: attrs)
                return modifyValueByKey?(tokenType, attributedReplacement) ?? attributedReplacement
            }
        }
        
