public capex.text.RichTextBlockParagraph readBlockParagraph(string id, cape.LineReader pr)
        {
            var    sb   = new cape.StringBuilder();
            string line = null;

            while (!(object.Equals(line = pr.readLine(), null)))
            {
                if (cape.String.startsWith(line, "--") && cape.String.endsWith(line, "--"))
                {
                    var lid = cape.String.subString(line, 2, cape.String.getLength(line) - 4);
                    if (!(object.Equals(lid, null)))
                    {
                        lid = cape.String.strip(lid);
                    }
                    if (cape.String.isEmpty(id))
                    {
                        if (cape.String.isEmpty(lid))
                        {
                            break;
                        }
                    }
                    else if (cape.String.equals(id, lid))
                    {
                        break;
                    }
                }
                sb.append(line);
                sb.append('\n');
            }
            return(new capex.text.RichTextBlockParagraph().setId(id).setText(sb.toString()));
        }
        public string skipEmptyLines(cape.LineReader pr)
        {
            string line = null;

            while (!(object.Equals(line = pr.readLine(), null)))
            {
                line = cape.String.strip(line);
                if (!(object.Equals(line, null)) && cape.String.startsWith(line, "#"))
                {
                    continue;
                }
                if (cape.String.isEmpty(line) == false)
                {
                    break;
                }
            }
            return(line);
        }
        public bool processInput(cape.LineReader pr, capex.text.RichTextDocument doc)
        {
            var line = skipEmptyLines(pr);

            if (object.Equals(line, null))
            {
                return(false);
            }
            if (object.Equals(line, "-"))
            {
                doc.addParagraph((capex.text.RichTextParagraph) new capex.text.RichTextSeparatorParagraph());
                return(true);
            }
            if (cape.String.startsWith(line, "@content "))
            {
                var id = cape.String.subString(line, 9);
                if (!(object.Equals(id, null)))
                {
                    id = cape.String.strip(id);
                }
                doc.addParagraph((capex.text.RichTextParagraph) new capex.text.RichTextContentParagraph().setContentId(id));
                return(true);
            }
            if (cape.String.startsWith(line, "@image "))
            {
                var @ref = cape.String.subString(line, 7);
                if (!(object.Equals(@ref, null)))
                {
                    @ref = cape.String.strip(@ref);
                }
                doc.addParagraph((capex.text.RichTextParagraph) new capex.text.RichTextImageParagraph().setFilename(@ref));
                return(true);
            }
            if (cape.String.startsWith(line, "@image100 "))
            {
                var ref1 = cape.String.subString(line, 10);
                if (!(object.Equals(ref1, null)))
                {
                    ref1 = cape.String.strip(ref1);
                }
                doc.addParagraph((capex.text.RichTextParagraph) new capex.text.RichTextImageParagraph().setFilename(ref1));
                return(true);
            }
            if (cape.String.startsWith(line, "@image75 "))
            {
                var ref2 = cape.String.subString(line, 9);
                if (!(object.Equals(ref2, null)))
                {
                    ref2 = cape.String.strip(ref2);
                }
                doc.addParagraph((capex.text.RichTextParagraph) new capex.text.RichTextImageParagraph().setFilename(ref2).setWidth(75));
                return(true);
            }
            if (cape.String.startsWith(line, "@image50 "))
            {
                var ref3 = cape.String.subString(line, 9);
                if (!(object.Equals(ref3, null)))
                {
                    ref3 = cape.String.strip(ref3);
                }
                doc.addParagraph((capex.text.RichTextParagraph) new capex.text.RichTextImageParagraph().setFilename(ref3).setWidth(50));
                return(true);
            }
            if (cape.String.startsWith(line, "@image25 "))
            {
                var ref4 = cape.String.subString(line, 9);
                if (!(object.Equals(ref4, null)))
                {
                    ref4 = cape.String.strip(ref4);
                }
                doc.addParagraph((capex.text.RichTextParagraph) new capex.text.RichTextImageParagraph().setFilename(ref4).setWidth(25));
                return(true);
            }
            if (cape.String.startsWith(line, "@reference "))
            {
                var ref5 = cape.String.subString(line, 11);
                if (!(object.Equals(ref5, null)))
                {
                    ref5 = cape.String.strip(ref5);
                }
                var sq  = cape.String.quotedStringToVector(ref5, ' ');
                var rrf = cape.Vector.getAt(sq, 0);
                var txt = cape.Vector.getAt(sq, 1);
                doc.addParagraph((capex.text.RichTextParagraph) new capex.text.RichTextReferenceParagraph().setReference(rrf).setText(txt));
                return(true);
            }
            if (cape.String.startsWith(line, "@set "))
            {
                var link = cape.String.subString(line, 5);
                if (!(object.Equals(link, null)))
                {
                    link = cape.String.strip(link);
                }
                var sq1 = cape.String.quotedStringToVector(link, ' ');
                var key = cape.Vector.getAt(sq1, 0);
                var val = cape.Vector.getAt(sq1, 1);
                if (cape.String.isEmpty(key))
                {
                    return(true);
                }
                doc.setMetadata(key, val);
                return(true);
            }
            if (cape.String.startsWith(line, "@link "))
            {
                var link1 = cape.String.subString(line, 6);
                if (!(object.Equals(link1, null)))
                {
                    link1 = cape.String.strip(link1);
                }
                var sq2   = cape.String.quotedStringToVector(link1, ' ');
                var url   = cape.Vector.getAt(sq2, 0);
                var txt1  = cape.Vector.getAt(sq2, 1);
                var flags = cape.Vector.getAt(sq2, 2);
                if (cape.String.isEmpty(txt1))
                {
                    txt1 = url;
                }
                var v = new capex.text.RichTextLinkParagraph();
                v.setLink(url);
                v.setText(txt1);
                if (cape.String.equals("internal", flags))
                {
                    v.setPopup(false);
                }
                else
                {
                    v.setPopup(true);
                }
                doc.addParagraph((capex.text.RichTextParagraph)v);
                return(true);
            }
            if (cape.String.startsWith(line, "---") && cape.String.endsWith(line, "---"))
            {
                var id1 = cape.String.subString(line, 3, cape.String.getLength(line) - 6);
                if (!(object.Equals(id1, null)))
                {
                    id1 = cape.String.strip(id1);
                }
                if (cape.String.isEmpty(id1))
                {
                    id1 = null;
                }
                doc.addParagraph((capex.text.RichTextParagraph)readPreformattedParagraph(id1, pr));
                return(true);
            }
            if (cape.String.startsWith(line, "--") && cape.String.endsWith(line, "--"))
            {
                var id2 = cape.String.subString(line, 2, cape.String.getLength(line) - 4);
                if (!(object.Equals(id2, null)))
                {
                    id2 = cape.String.strip(id2);
                }
                if (cape.String.isEmpty(id2))
                {
                    id2 = null;
                }
                doc.addParagraph((capex.text.RichTextParagraph)readBlockParagraph(id2, pr));
                return(true);
            }
            var sb = new cape.StringBuilder();
            var pc = (char)0;

            do
            {
                line = cape.String.strip(line);
                if (cape.String.isEmpty(line))
                {
                    break;
                }
                if (cape.String.startsWith(line, "#") == false)
                {
                    var it = cape.String.iterate(line);
                    var c  = ' ';
                    if (sb.count() > 0 && pc != ' ')
                    {
                        sb.append(' ');
                        pc = ' ';
                    }
                    while ((c = it.getNextChar()) > 0)
                    {
                        if (c == ' ' || c == '\t' || c == '\r' || c == '\n')
                        {
                            if (pc == ' ')
                            {
                                continue;
                            }
                            c = ' ';
                        }
                        sb.append(c);
                        pc = c;
                    }
                }
            }while(!(object.Equals(line = pr.readLine(), null)));
            var s = sb.toString();

            if (cape.String.isEmpty(s))
            {
                return(false);
            }
            doc.addParagraph((capex.text.RichTextParagraph)capex.text.RichTextStyledParagraph.forString(s));
            return(true);
        }