public string HTML2Markup(string html) { _lastNewLines = 0; _currentNode = null; //replace type junk with their actual chars or textile representations of them. html = ProcessGlyphs(html); //add a div as the root node or the SGML lib only will process the first element! html = string.Format("<div>{0}</div>", html); StringReader rdr = new StringReader(html); _output = new StringBuilder(); _sgmlReader.InputStream = rdr; MemorySgmlReader memRdr = new MemorySgmlReader(_sgmlReader); foreach(ParserNode n in memRdr.Nodes) { _currentNode = n; switch (n.NodeType) { case XmlNodeType.Element: HandleElementStart(n); break; case XmlNodeType.EndElement: HandleElementEnd(n); break; case XmlNodeType.Text: HandleText(n); break; } } return _output.ToString(); }
protected virtual void HandleElementStart(ParserNode node) { }
protected virtual void HandleText(ParserNode node) { }
protected virtual void HandleElementEnd(ParserNode node) { }