public void Replay(IDocumentConsumer con) { int f = 0; for (int b = 0; b < blocks.Count; b++) { while (f < blocks[b].FragmentIndex) con.PushFragment(fragments[f++]); con.PushBlock(blocks[b].Content); } while (f < fragments.Count) con.PushFragment(fragments[f++]); con.Close(); }
public static void ParseStream(Stream s, IDocumentConsumer con) { var parser = new XHTMLParser(con); parser.Parse(s); }
public XHTMLParser(IDocumentConsumer c) { consumer = c; }
static void PrintEntry(TableOfContents toc, IDocumentConsumer doc, int ent, int depth, int depthLimit) { if ((depthLimit >= 0) && (depth > depthLimit)) return; doc.PushBlock(new Block() { Indent = depth }); doc.PushFragment(new Fragment() { Attr = Fragment.Attributes.Heading, Text = toc.GetName(ent), Linkref = toc.GetLinkref(ent) }); for (int i = toc.FirstChild(ent); i >= 0; i = toc.NextSibling(i)) PrintEntry(toc, doc, i, depth + 1, depthLimit); }
public static void PrintToc(TableOfContents toc, IDocumentConsumer doc, int depthLimit = -1) { doc.PushBlock(new Block()); doc.PushFragment(new Fragment() { Attr = Fragment.Attributes.Heading, Text = toc.Title }); for (int i = toc.FirstRoot(); i >= 0; i = toc.NextSibling(i)) PrintEntry(toc, doc, i, 0, depthLimit); doc.Close(); }
public void ProduceDocument(string path, IDocumentConsumer con) { path = EPath.GetPath(path); con = new NormalizeWhitespace(con); con = new ShiftLinks(path, con); using (Stream s = GetContent(path)) XHTMLParser.ParseStream(s, con); }
public void ProduceBook(IDocumentConsumer con) { for (int i = 0; i < Spine.Count; i++) { OPFManifest.Item item = Manifest.GetById(Spine[i]); IDocumentConsumer filter = new NamespaceAnchors(item.Linkref + "#", con); con.PushFragment(new Fragment() { Attr = Fragment.Attributes.AnchorName, Text = item.Linkref }); ProduceDocument(item.Linkref, filter); } }
public ShiftLinks(string p, IDocumentConsumer con) { basePath = p; next = con; }
public ReflowParagraphs(IDocumentConsumer next, int tw = 79, int indent = 4) { consumer = next; targetWidth = tw; indentPerLevel = indent; }
public NormalizeWhitespace(IDocumentConsumer next) { consumer = next; }
public NamespaceAnchors(string p, IDocumentConsumer con) { basePath = p; next = con; }
public IndentText(IDocumentConsumer next, int indent = 4) { consumer = next; indentPerLevel = indent; }