public HtmlWriter(System.IO.TextWriter writer, bool fragment) { _fragment = fragment; _characterStream = new HtmlCharacterStream(writer); _characterStream.State = HtmlStates.Data; _textWriter = new TextWriter(_characterStream); _textWriter.LinePrefix = string.Empty; }
public void Parse( TextReader reader, Func <IDocumentElement, bool> onBeginProcessElement, Func <IDocumentElement, bool> onEndProcessElement) { _onBeginProcessElement = onBeginProcessElement; _onEndProcessElement = onEndProcessElement; _characterStream = new HtmlCharacterStream(reader) { State = HtmlStates.Data }; _stringParser = new TextParser(_stringBuilderFactory, _characterStream); _document = new DocumentElement { MimeType = "text/html", ConformanceLevel = 1.0f }; if (!Begin(_document)) { return; } Element currentElement = _document; while (!_characterStream.Eof) { currentElement = ProcessCurrentState(currentElement); } if (_document.Children == null || _document.Children.Count == 0) { _document.ConformanceLevel = 0; } else { var visibleChildren = _document.Children.Where(e => !e.SuppressOutput).ToList(); if (visibleChildren.Count == 0 || visibleChildren.All(e => e.ElementType == ElementTypes.RawText)) { _document.ConformanceLevel = 0; } } End(_document); }