inlne code
+// code block+public class HtmlMessageBuilder +{ + record struct BuilderState(TextStyle Style, string? Url = null, long? UserId = null, string? CodeLang = null) + { + public void Reset() + { + Style = TextStyle.PlainText; + Url = null; + UserId = null; + CodeLang = null; + } + } + + private BuilderState _state=new(TextStyle.PlainText); + StringBuilder _plainText=new(); + StringBuilder _html=new(); + + protected void ReplaceHtmlReservedChar(char c) => + _html.Append(c switch + { + '<'=>"<", + '>'=>">", + '&'=>"&apm", + '"'=>""", + '\''=>"&apos", + _ => c + }); + + protected void ReplaceHtmlReservedChars(ReadOnlySpan
");
+ if (0!=(_state.Style & TextStyle.CodeBlock))
+ {
+ _html.Append("');
+ }
+ }
+
+ /// closes opened html tags
+ protected void CloseTags()
+ {
+ if(_state.Style==TextStyle.PlainText)
+ return;
+
+ // the order of fields is very importang, it must be in reversed in CloseTags()
+ if (0!=(_state.Style & TextStyle.CodeBlock)) _html.Append("");
+ if (0!=(_state.Style & TextStyle.CodeLine)) _html.Append("");
+ if (0!=(_state.Style & TextStyle.Link)) _html.Append("");
+ if (0!=(_state.Style & TextStyle.Spoiler)) _html.Append("