public MarkdownWriter(System.IO.TextWriter writer)
        {
            _characterStream = new MarkdownCharacterStream(writer)
            {
                State = MarkdownStates.ParagraphBreak
            };

            _textWriter = new TextWriter(_characterStream);
        }
        public void Parse(
            TextReader reader,
            Func <IDocumentElement, bool> onBeginProcessElement,
            Func <IDocumentElement, bool> onEndProcessElement)
        {
            _onBeginProcessElement = onBeginProcessElement;
            _onEndProcessElement   = onEndProcessElement;

            _characterStream = new MarkdownCharacterStream(reader)
            {
                State = MarkdownStates.ParagraphBreak
            };
            _stringParser   = new TextParser(_stringBuilderFactory, _characterStream);
            _elementStack   = new Core.Collections.LinkedList <StackedElement>();
            _references     = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
            _anchorsToFixup = new List <AnchorElement>();

            _document = new DocumentElement
            {
                MimeType         = "application/x-markdown",
                ConformanceLevel = 1.0f
            };

            PushElement(_document);

            var line = _stringBuilderFactory.Create();

            while (!_characterStream.Eof)
            {
                line.Clear();
                _stringParser.TakeUntil(line, 1024, '\n', false);
                AddLine(line.ToString());
            }

            while (!(_elementStack.Last().Element is DocumentElement))
            {
                PopElement();
            }

            FixUpReferences();

            End(_document);
        }