|
6 | 6 |
|
7 | 7 | namespace Bunit.Diffing |
8 | 8 | { |
9 | | - // /// <summary> |
10 | | - // /// A markup formatter, that skips any special Blazor attributes added by the <see cref="TestRenderer"/>/<see cref="Htmlizer"/>. |
11 | | - // /// </summary> |
12 | | - //public class DiffMarkupFormatter : PrettyMarkupFormatter, IMarkupFormatter |
13 | | - //{ |
14 | | - // /// <summary> |
15 | | - // /// Gets an instance of the <see cref="DiffMarkupFormatter"/>. |
16 | | - // /// </summary> |
17 | | - // public new static readonly DiffMarkupFormatter Instance = new DiffMarkupFormatter(); |
18 | | - |
19 | | - // /// <summary> |
20 | | - // /// Creates an instance of the <see cref="DiffMarkupFormatter"/>. |
21 | | - // /// </summary> |
22 | | - // public DiffMarkupFormatter() |
23 | | - // { |
24 | | - // NewLine = Environment.NewLine; |
25 | | - // Indentation = " "; |
26 | | - // } |
27 | | - |
28 | | - // /// <summary> |
29 | | - // /// Creates the string representation of the attribute. |
30 | | - // /// </summary> |
31 | | - // /// <param name="attr">The attribute to serialize.</param> |
32 | | - // /// <returns>The string representation.</returns> |
33 | | - // public string ConvertToString(IAttr attr) => base.Attribute(attr); |
34 | | - |
35 | | - // /// <summary> |
36 | | - // /// Creates the string representation of the attribute. |
37 | | - // /// If it is a special Blazor renderer attribute, then it is ignored. |
38 | | - // /// </summary> |
39 | | - // /// <param name="attr">The attribute to serialize.</param> |
40 | | - // /// <returns>The string representation.</returns> |
41 | | - // protected override string Attribute(IAttr attr) |
42 | | - // { |
43 | | - // return Htmlizer.IsBlazorAttribute(attr?.Name ?? string.Empty) |
44 | | - // ? string.Empty |
45 | | - // : base.Attribute(attr); |
46 | | - // } |
47 | | - //} |
48 | | - |
49 | 9 | /// <summary> |
50 | 10 | /// A markup formatter, that skips any special Blazor attributes added by the <see cref="TestRenderer"/>/<see cref="Htmlizer"/>. |
51 | 11 | /// </summary> |
52 | | - public class DiffMarkupFormatter : IMarkupFormatter |
| 12 | + public class DiffMarkupFormatter : PrettyMarkupFormatter, IMarkupFormatter |
53 | 13 | { |
54 | | - private readonly IMarkupFormatter _formatter = new PrettyMarkupFormatter() |
55 | | - { |
56 | | - NewLine = Environment.NewLine, |
57 | | - Indentation = " " |
58 | | - }; |
| 14 | + /// <summary> |
| 15 | + /// Gets an instance of the <see cref="DiffMarkupFormatter"/>. |
| 16 | + /// </summary> |
| 17 | + public new static readonly DiffMarkupFormatter Instance = new DiffMarkupFormatter(); |
59 | 18 |
|
60 | | - public static readonly DiffMarkupFormatter Instance = new DiffMarkupFormatter(); |
| 19 | + /// <summary> |
| 20 | + /// Creates an instance of the <see cref="DiffMarkupFormatter"/>. |
| 21 | + /// </summary> |
| 22 | + public DiffMarkupFormatter() |
| 23 | + { |
| 24 | + NewLine = Environment.NewLine; |
| 25 | + Indentation = " "; |
| 26 | + } |
61 | 27 |
|
62 | 28 | /// <summary> |
63 | | - /// Creates the string representation of the attribute. |
| 29 | + /// Creates the string representation of the attribute. |
64 | 30 | /// </summary> |
65 | 31 | /// <param name="attr">The attribute to serialize.</param> |
66 | 32 | /// <returns>The string representation.</returns> |
67 | | - public string ConvertToString(IAttr attr) => _formatter.Attribute(attr); |
68 | | - |
69 | | - /// <inheritdoc /> |
70 | | - public string Attribute(IAttr attribute) |
71 | | - => Htmlizer.IsBlazorAttribute(attribute?.Name ?? string.Empty) |
72 | | - ? string.Empty |
73 | | - : _formatter.Attribute(attribute); |
74 | | - |
75 | | - /// <inheritdoc /> |
76 | | - public string CloseTag(IElement element, bool selfClosing) => _formatter.CloseTag(element, selfClosing); |
| 33 | + public string ConvertToString(IAttr attr) => base.Attribute(attr); |
77 | 34 |
|
78 | | - /// <inheritdoc /> |
79 | | - public string Comment(IComment comment) => _formatter.Comment(comment); |
80 | | - |
81 | | - /// <inheritdoc /> |
82 | | - public string Doctype(IDocumentType doctype) => _formatter.Doctype(doctype); |
83 | | - |
84 | | - public string LiteralText(ICharacterData text) => throw new NotImplementedException(); |
85 | | - |
86 | | - /// <inheritdoc /> |
87 | | - public string OpenTag(IElement element, bool selfClosing) |
| 35 | + /// <summary> |
| 36 | + /// Creates the string representation of the attribute. |
| 37 | + /// If it is a special Blazor renderer attribute, then it is ignored. |
| 38 | + /// </summary> |
| 39 | + /// <param name="attr">The attribute to serialize.</param> |
| 40 | + /// <returns>The string representation.</returns> |
| 41 | + protected override string Attribute(IAttr attr) |
88 | 42 | { |
89 | | - if (element is null) |
90 | | - throw new ArgumentNullException(nameof(element)); |
91 | | - |
92 | | - var result = _formatter.OpenTag(element, selfClosing); |
93 | | - |
94 | | - foreach (var attr in element.Attributes) |
95 | | - { |
96 | | - if (Htmlizer.IsBlazorAttribute(attr.Name)) |
97 | | - { |
98 | | - var attrToRemove = " " + HtmlMarkupFormatter.Instance.Attribute(attr); |
99 | | - result = result.Replace(attrToRemove, "", StringComparison.Ordinal); |
100 | | - } |
101 | | - } |
102 | | - |
103 | | - return result; |
| 43 | + return Htmlizer.IsBlazorAttribute(attr?.Name ?? string.Empty) |
| 44 | + ? string.Empty |
| 45 | + : base.Attribute(attr); |
104 | 46 | } |
105 | | - |
106 | | - /// <inheritdoc /> |
107 | | - public string Processing(IProcessingInstruction processing) => _formatter.Processing(processing); |
108 | | - |
109 | | - /// <inheritdoc /> |
110 | | - public string Text(ICharacterData text) => _formatter.Text(text); |
111 | 47 | } |
112 | 48 | } |
0 commit comments