Code/Dependencies/DotNetGraph/Attributes/DotLabelAttribute.cs
using System.Threading.Tasks;
using Nodebox.Dependencies.DotNetGraph.Compilation;
using Nodebox.Dependencies.DotNetGraph.Extensions;

namespace Nodebox.Dependencies.DotNetGraph.Attributes {
    public class DotLabelAttribute : IDotAttribute {
        public string Value { get; set; }

        public bool IsHtml { get; set; }

        public DotLabelAttribute(string value, bool isHtml = false) {
            Value = value;
            IsHtml = isHtml;
        }

        public async Task CompileAsync(CompilationContext context) {
            if (IsHtml) {
                await context.TextWriter.WriteAsync($"<{Value}>");
                return;
            }

            var value = context.Options.AutomaticEscapedCharactersFormat ? Value.FormatGraphvizEscapedCharacters() : Value;
            await context.TextWriter.WriteAsync($"\"{value}\"");
        }

        public static implicit operator DotLabelAttribute(string value) => new DotLabelAttribute(value);
    }
}