public IList <string> GetCssStyles() { var attrs = _op.Attributes; var result = new List <string>(); Action <InlineStyleType, string, string> convert = (converter, value, name) => { if (!String.IsNullOrEmpty(value)) { if (converter != null) { var converted = converter(value, _op); if (!String.IsNullOrEmpty(converted)) { result.Add(converted); } } else { result.Add($"{name}:{value}"); } } }; var iss = _options.InlineStyles; convert(iss?.Color ?? DEFAULT_INLINE_STYLES.Color, attrs.Color, "color"); if (iss != null || !_options.AllowBackgroundClasses.HasValue || !_options.AllowBackgroundClasses.Value) { convert(iss?.Background ?? DEFAULT_INLINE_STYLES.Background, attrs.Background, "background-color"); } if (iss != null) { if (attrs.Indent.HasValue) { convert(iss.Indent ?? DEFAULT_INLINE_STYLES.Indent, attrs.Indent.Value.ToString(), "indent"); } convert(iss.Align ?? DEFAULT_INLINE_STYLES.Align, AlignConverter.GetStringValue(attrs.Align), "text-align"); convert(iss.Direction ?? DEFAULT_INLINE_STYLES.Direction, DirectionConverter.GetStringValue(attrs.Direction), "direction"); convert(iss.Font ?? DEFAULT_INLINE_STYLES.Font, attrs.Font, "font-family"); convert(iss.Size ?? DEFAULT_INLINE_STYLES.Size, attrs.Size, "size"); } return(result); }
public IList <string> GetCssClasses() { var attrs = _op.Attributes; if (_options.InlineStyles != null) { return(new string[0]); } var classes = new List <string>(); if (attrs.Indent > 0) { classes.Add(PrefixClass($"indent-{attrs.Indent.Value}")); } if (attrs.Align.HasValue) { classes.Add(PrefixClass($"align-{AlignConverter.GetStringValue(attrs.Align)}")); } if (attrs.Direction.HasValue) { string dirnValue = DirectionConverter.GetStringValue(attrs.Direction); classes.Add(PrefixClass($"direction-{dirnValue}")); } if (!String.IsNullOrEmpty(attrs.Font)) { classes.Add(PrefixClass($"font-{attrs.Font}")); } if (!String.IsNullOrEmpty(attrs.Size)) { classes.Add(PrefixClass($"size-{attrs.Size}")); } if (_options.AllowBackgroundClasses == true && !String.IsNullOrEmpty(attrs.Background) && OpAttributeSanitizer.IsValidColorLiteral(attrs.Background)) { classes.Add(PrefixClass($"background-{attrs.Background}")); } if (_op.IsFormula()) { classes.Add(PrefixClass("formula")); } if (_op.IsVideo()) { classes.Add(PrefixClass("video")); } if (_op.IsImage()) { classes.Add(PrefixClass("image")); } return(classes); }