Example #1
0
        public virtual void FlushLine(Out fout, int indent)
        {
            int i;

            if (linelen > 0)
            {
                if (indent + linelen >= _options.WrapLen)
                {
                    WrapLine(fout, indent);
                }

                if (!inAttVal || _options.IndentAttributes)
                {
                    for (i = 0; i < indent; ++i)
                    {
                        fout.Outc((int) ' ');
                    }
                }

                for (i = 0; i < linelen; ++i)
                {
                    fout.Outc(linebuf[i]);
                }
            }

            fout.Newline();
            linelen = 0;
            wraphere = 0;
            inAttVal = false;
        }
Example #2
0
        /*
        Called from printTree to print the content of a slide from
        the node slidecontent. On return slidecontent points to the
        node starting the next slide or null. The variables slide
        and count are used to customise the navigation bar.
        */
        public virtual void PrintSlide(Out fout, int mode, int indent, Lexer lexer)
        {
            Node content, last;
            TagTable tt = _options.tt;

            /* insert div for onclick handler */
            string s;
            s = "<div onclick=\"document.location='slide" + (slide < count?slide + 1:1).ToString() + ".html'\">";
            PrintString(fout, indent, s);
            CondFlushLine(fout, indent);

            /* first print the h2 element and navbar */
            if (slidecontent.Tag == tt.TagH2)
            {
                PrintNavBar(fout, indent);

                /* now print an hr after h2 */

                AddC('<', linelen++);

                AddC((int) Lexer.FoldCase('h', _options.UpperCaseTags, _options.XmlTags), linelen++);
                AddC((int) Lexer.FoldCase('r', _options.UpperCaseTags, _options.XmlTags), linelen++);

                if (_options.XmlOut == true)
                {
                    PrintString(fout, indent, " />");
                }
                else
                {
                    AddC('>', linelen++);
                }

                if (_options.IndentContent == true)
                {
                    CondFlushLine(fout, indent);
                }

                /* PrintVertSpacer(fout, indent); */

                /*CondFlushLine(fout, indent); */

                /* print the h2 element */
                PrintTree(fout, mode, (_options.IndentContent?indent + _options.Spaces:indent), lexer, slidecontent);

                slidecontent = slidecontent.Next;
            }

            /* now continue until we reach the next h2 */

            last = null;
            content = slidecontent;

            for (; content != null; content = content.Next)
            {
                if (content.Tag == tt.TagH2)
                {
                    break;
                }

                /* kludge for naked text before block level tag */
                if (last != null && !_options.IndentContent && last.Type == Node.TextNode && content.Tag != null && (content.Tag.Model & ContentModel.Block) != 0)
                {
                    FlushLine(fout, indent);
                    FlushLine(fout, indent);
                }

                PrintTree(fout, mode, (_options.IndentContent?indent + _options.Spaces:indent), lexer, content);

                last = content;
            }

            slidecontent = content;

            /* now print epilog */

            CondFlushLine(fout, indent);

            PrintString(fout, indent, "<br clear=\"all\">");
            CondFlushLine(fout, indent);

            AddC('<', linelen++);

            AddC((int) Lexer.FoldCase('h', _options.UpperCaseTags, _options.XmlTags), linelen++);
            AddC((int) Lexer.FoldCase('r', _options.UpperCaseTags, _options.XmlTags), linelen++);

            if (_options.XmlOut == true)
            {
                PrintString(fout, indent, " />");
            }
            else
            {
                AddC('>', linelen++);
            }

            if (_options.IndentContent == true)
            {
                CondFlushLine(fout, indent);
            }

            PrintNavBar(fout, indent);

            /* end tag for div */
            PrintString(fout, indent, "</div>");
            CondFlushLine(fout, indent);
        }
Example #3
0
 /*
 inserts a space gif called "dot.gif" to ensure
 that the  slide is at least n pixels high
 */
 private void PrintVertSpacer(Out fout, int indent)
 {
     CondFlushLine(fout, indent);
     PrintString(fout, indent, "<img width=\"0\" height=\"0\" hspace=\"1\" src=\"dot.gif\" vspace=\"%d\" align=\"left\">");
     CondFlushLine(fout, indent);
 }
Example #4
0
        private void WrapLine(Out fout, int indent)
        {
            int i, p, q;

            if (wraphere == 0)
            {
                return;
            }

            for (i = 0; i < indent; ++i)
            {
                fout.Outc((int) ' ');
            }

            for (i = 0; i < wraphere; ++i)
            {
                fout.Outc(linebuf[i]);
            }

            if (InString)
            {
                fout.Outc((int) ' ');
                fout.Outc((int) '\\');
            }

            fout.Newline();

            if (linelen > wraphere)
            {
                p = 0;

                if (linebuf[wraphere] == ' ')
                {
                    ++wraphere;
                }

                q = wraphere;
                AddC('\x0000', linelen);

                while (true)
                {
                    linebuf[p] = linebuf[q];
                    if (linebuf[q] == 0)
                    {
                        break;
                    }
                    p++;
                    q++;
                }
                linelen -= wraphere;
            }
            else
            {
                linelen = 0;
            }

            wraphere = 0;
        }
Example #5
0
        private void PrintAttrValue(Out fout, int indent, string val, int delim, bool wrappable)
        {
            int c;
            MutableInteger ci = new MutableInteger();
            bool wasinstring = false;
            byte[] valueChars = null;
            int i;
            int mode = (wrappable?(int) (NORMAL | ATTRIBVALUE):(int) (PREFORMATTED | ATTRIBVALUE));

            if (val != null)
            {
                valueChars = Lexer.GetBytes(val);
            }

            /* look for ASP, Tango or PHP instructions for computed attribute value */
            if (valueChars != null && valueChars.Length >= 5 && valueChars[0] == '<')
            {
                char[] tmpChar;
                tmpChar = new char[valueChars.Length];
                valueChars.CopyTo(tmpChar, 0);
                if (valueChars[1] == '%' || valueChars[1] == '@' || (new string(tmpChar, 0, 5)).Equals("<?php"))
                    mode |= CDATA;
            }

            if (delim == 0)
            {
                delim = '"';
            }

            AddC('=', linelen++);

            /* don't wrap after "=" for xml documents */
            if (!_options.XmlOut)
            {
                if (indent + linelen < _options.WrapLen)
                {
                    wraphere = linelen;
                }

                if (indent + linelen >= _options.WrapLen)
                {
                    WrapLine(fout, indent);
                }

                if (indent + linelen < _options.WrapLen)
                {
                    wraphere = linelen;
                }
                else
                {
                    CondFlushLine(fout, indent);
                }
            }

            AddC(delim, linelen++);

            if (val != null)
            {
                InString = false;

                i = 0;
                while (i < valueChars.Length)
                {
                    c = ((int) valueChars[i]) & 0xFF; // Convert to unsigned.

                    if (wrappable && c == ' ' && indent + linelen < _options.WrapLen)
                    {
                        wraphere = linelen;
                        wasinstring = InString;
                    }

                    if (wrappable && wraphere > 0 && indent + linelen >= _options.WrapLen)
                        WrapAttrVal(fout, indent, wasinstring);

                    if (c == delim)
                    {
                        string entity;

                        entity = (c == '"'?"&quot;":"&#39;");

                        for (int j = 0; j < entity.Length; j++)
                        {
                            AddC(entity[j], linelen++);
                        }

                        ++i;
                        continue;
                    }
                    else if (c == '"')
                    {
                        if (_options.QuoteMarks)
                        {
                            AddC('&', linelen++);
                            AddC('q', linelen++);
                            AddC('u', linelen++);
                            AddC('o', linelen++);
                            AddC('t', linelen++);
                            AddC(';', linelen++);
                        }
                        else
                        {
                            AddC('"', linelen++);
                        }

                        if (delim == '\'')
                        {
                            InString = !InString;
                        }

                        ++i;
                        continue;
                    }
                    else if (c == '\'')
                    {
                        if (_options.QuoteMarks)
                        {
                            AddC('&', linelen++);
                            AddC('#', linelen++);
                            AddC('3', linelen++);
                            AddC('9', linelen++);
                            AddC(';', linelen++);
                        }
                        else
                        {
                            AddC('\'', linelen++);
                        }

                        if (delim == '"')
                        {
                            InString = !InString;
                        }

                        ++i;
                        continue;
                    }

                    /* look for UTF-8 multibyte character */
                    if (c > 0x7F)
                    {
                        i += GetUTF8(valueChars, i, ci);
                        c = ci.Val;
                    }

                    ++i;

                    if (c == '\n')
                    {
                        FlushLine(fout, indent);
                        continue;
                    }

                    PrintChar(c, mode);
                }
            }

            InString = false;
            AddC(delim, linelen++);
        }
Example #6
0
        /*
        The line buffer is uint not char so we can
        hold Unicode values unencoded. The translation
        to UTF-8 is deferred to the outc routine called
        to flush the line buffer.
        */
        private void PrintText(Out fout, int mode, int indent, byte[] textarray, int start, int end)
        {
            int i, c;
            MutableInteger ci = new MutableInteger();

            for (i = start; i < end; ++i)
            {
                if (indent + linelen >= _options.WrapLen)
                {
                    WrapLine(fout, indent);
                }

                c = ((int) textarray[i]) & 0xFF; // Convert to unsigned.

                /* look for UTF-8 multibyte character */
                if (c > 0x7F)
                {
                    i += GetUTF8(textarray, i, ci);
                    c = ci.Val;
                }

                if (c == '\n')
                {
                    FlushLine(fout, indent);
                    continue;
                }

                PrintChar(c, mode);
            }
        }
Example #7
0
        private void PrintPI(Out fout, int indent, Node node)
        {
            if (indent + linelen < _options.WrapLen)
            {
                wraphere = linelen;
            }

            AddC('<', linelen++);
            AddC('?', linelen++);

            /* set CDATA to pass < and > unescaped */
            PrintText(fout, CDATA, indent, node.Textarray, node.Start, node.End);

            if (node.Textarray[node.End - 1] != (byte) '?')
            {
                AddC('?', linelen++);
            }

            AddC('>', linelen++);
            CondFlushLine(fout, indent);
        }
Example #8
0
        /* note ASP and JSTE share <% ... %> syntax */
        private void PrintAsp(Out fout, int indent, Node node)
        {
            int savewraplen = _options.WrapLen;

            /* disable wrapping if so requested */

            if (!_options.WrapAsp || !_options.WrapJste)
            {
                _options.WrapLen = 0xFFFFFF;
            }
            /* a very large number */

            AddC('<', linelen++);
            AddC('%', linelen++);

            PrintText(fout, (_options.WrapAsp?CDATA:COMMENT), indent, node.Textarray, node.Start, node.End);

            AddC('%', linelen++);
            AddC('>', linelen++);

            /* CondFlushLine(fout, indent); */
            _options.WrapLen = savewraplen;
        }
Example #9
0
        private void PrintEndTag(Out fout, int mode, int indent, Node node)
        {
            string p;

            /*
            Netscape ignores SGML standard by not ignoring a
            line break before </A> or </U> etc. To avoid rendering
            this as an underlined space, I disable line wrapping
            before inline end tags by the #if 0 ... #endif
            */
            //if (false)
            //{
            //	if (indent + linelen < _options.WrapLen && !((mode & NOWRAP) != 0))
            //		wraphere = linelen;
            //}

            AddC('<', linelen++);
            AddC('/', linelen++);

            p = node.Element;
            for (int i = 0; i < p.Length; i++)
            {
                AddC((int) Lexer.FoldCase(p[i], _options.UpperCaseTags, _options.XmlTags), linelen++);
            }

            AddC('>', linelen++);
        }
Example #10
0
        private void PrintNavBar(Out fout, int indent)
        {
            string buf;

            CondFlushLine(fout, indent);
            PrintString(fout, indent, "<center><small>");

            if (slide > 1)
            {
                buf = "<a href=\"slide" + (slide - 1).ToString() + ".html\">previous</a> | ";
                PrintString(fout, indent, buf);
                CondFlushLine(fout, indent);

                if (slide < count)
                {
                    PrintString(fout, indent, "<a href=\"slide1.html\">start</a> | ");
                }
                else
                {
                    PrintString(fout, indent, "<a href=\"slide1.html\">start</a>");
                }

                CondFlushLine(fout, indent);
            }

            if (slide < count)
            {
                buf = "<a href=\"slide" + (slide + 1).ToString() + ".html\">next</a>";
                PrintString(fout, indent, buf);
            }

            PrintString(fout, indent, "</small></center>");
            CondFlushLine(fout, indent);
        }
Example #11
0
        private void PrintDocType(Out fout, int indent, Node node)
        {
            bool q = _options.QuoteMarks;

            _options.QuoteMarks = false;

            if (indent + linelen < _options.WrapLen)
            {
                wraphere = linelen;
            }

            CondFlushLine(fout, indent);

            AddC('<', linelen++);
            AddC('!', linelen++);
            AddC('D', linelen++);
            AddC('O', linelen++);
            AddC('C', linelen++);
            AddC('T', linelen++);
            AddC('Y', linelen++);
            AddC('P', linelen++);
            AddC('E', linelen++);
            AddC(' ', linelen++);

            if (indent + linelen < _options.WrapLen)
            {
                wraphere = linelen;
            }

            PrintText(fout, (short) 0, indent, node.Textarray, node.Start, node.End);

            if (linelen < _options.WrapLen)
            {
                wraphere = linelen;
            }

            AddC('>', linelen++);
            _options.QuoteMarks = q;
            CondFlushLine(fout, indent);
        }
Example #12
0
        private void PrintComment(Out fout, int indent, Node node)
        {
            if (indent + linelen < _options.WrapLen)
            {
                wraphere = linelen;
            }

            AddC('<', linelen++);
            AddC('!', linelen++);
            AddC('-', linelen++);
            AddC('-', linelen++);
            PrintText(fout, COMMENT, indent, node.Textarray, node.Start, node.End);
            // See Lexer.java: AQ 8Jul2000
            AddC('-', linelen++);
            AddC('-', linelen++);
            AddC('>', linelen++);

            if (node.Linebreak)
            {
                FlushLine(fout, indent);
            }
        }
Example #13
0
        private void PrintCDATA(Out fout, int indent, Node node)
        {
            int savewraplen = _options.WrapLen;

            CondFlushLine(fout, indent);

            /* disable wrapping */

            _options.WrapLen = 0xFFFFFF; /* a very large number */

            AddC('<', linelen++);
            AddC('!', linelen++);
            AddC('[', linelen++);
            AddC('C', linelen++);
            AddC('D', linelen++);
            AddC('A', linelen++);
            AddC('T', linelen++);
            AddC('A', linelen++);
            AddC('[', linelen++);

            PrintText(fout, COMMENT, indent, node.Textarray, node.Start, node.End);

            AddC(']', linelen++);
            AddC(']', linelen++);
            AddC('>', linelen++);
            CondFlushLine(fout, indent);
            _options.WrapLen = savewraplen;
        }
Example #14
0
        public virtual void PrintTree(Out fout, int mode, int indent, Lexer lexer, Node node)
        {
            Node content, last;
            TagTable tt = _options.tt;

            if (node == null)
                return;

            if (node.Type == Node.TextNode)
            {
                PrintText(fout, mode, indent, node.Textarray, node.Start, node.End);
            }
            else if (node.Type == Node.CommentTag)
            {
                PrintComment(fout, indent, node);
            }
            else if (node.Type == Node.RootNode)
            {
                for (content = node.Content; content != null; content = content.Next)
                {
                    PrintTree(fout, mode, indent, lexer, content);
                }
            }
            else if (node.Type == Node.DocTypeTag)
            {
                PrintDocType(fout, indent, node);
            }
            else if (node.Type == Node.ProcInsTag)
            {
                PrintPI(fout, indent, node);
            }
            else if (node.Type == Node.CDATATag)
            {
                PrintCDATA(fout, indent, node);
            }
            else if (node.Type == Node.SectionTag)
            {
                PrintSection(fout, indent, node);
            }
            else if (node.Type == Node.AspTag)
            {
                PrintAsp(fout, indent, node);
            }
            else if (node.Type == Node.JsteTag)
            {
                PrintJste(fout, indent, node);
            }
            else if (node.Type == Node.PhpTag)
            {
                PrintPhp(fout, indent, node);
            }
            else if ((node.Tag.Model & ContentModel.Empty) != 0 || node.Type == Node.StartEndTag)
            {
                if (!((node.Tag.Model & ContentModel.Inline) != 0))
                {
                    CondFlushLine(fout, indent);
                }

                if (node.Tag == tt.TagBr && node.Prev != null && node.Prev.Tag != tt.TagBr && _options.BreakBeforeBR)
                {
                    FlushLine(fout, indent);
                }

                if (_options.MakeClean && node.Tag == tt.TagWbr)
                {
                    PrintString(fout, indent, " ");
                }
                else
                {
                    PrintTag(lexer, fout, mode, indent, node);
                }

                if (node.Tag == tt.TagParam || node.Tag == tt.TagArea)
                {
                    CondFlushLine(fout, indent);
                }
                else if (node.Tag == tt.TagBr || node.Tag == tt.TagHr)
                {
                    FlushLine(fout, indent);
                }
            }
            else
            {
                /* some kind of container element */
                if (node.Tag != null && node.Tag.Parser == ParserImpl.ParsePre)
                {
                    CondFlushLine(fout, indent);

                    indent = 0;
                    CondFlushLine(fout, indent);
                    PrintTag(lexer, fout, mode, indent, node);
                    FlushLine(fout, indent);

                    for (content = node.Content; content != null; content = content.Next)
                    {
                        PrintTree(fout, (int) (mode | PREFORMATTED | NOWRAP), indent, lexer, content);
                    }

                    CondFlushLine(fout, indent);
                    PrintEndTag(fout, mode, indent, node);
                    FlushLine(fout, indent);

                    if (_options.IndentContent == false && node.Next != null)
                    {
                        FlushLine(fout, indent);
                    }
                }
                else if (node.Tag == tt.TagStyle || node.Tag == tt.TagScript)
                {
                    CondFlushLine(fout, indent);

                    indent = 0;
                    CondFlushLine(fout, indent);
                    PrintTag(lexer, fout, mode, indent, node);
                    FlushLine(fout, indent);

                    for (content = node.Content; content != null; content = content.Next)
                    {
                        PrintTree(fout, (int) (mode | PREFORMATTED | NOWRAP | CDATA), indent, lexer, content);
                    }

                    CondFlushLine(fout, indent);
                    PrintEndTag(fout, mode, indent, node);
                    FlushLine(fout, indent);

                    if (_options.IndentContent == false && node.Next != null)
                    {
                        FlushLine(fout, indent);
                    }
                }
                else if ((node.Tag.Model & ContentModel.Inline) != 0)
                {
                    if (_options.MakeClean)
                    {
                        /* discards <font> and </font> tags */
                        if (node.Tag == tt.TagFont)
                        {
                            for (content = node.Content; content != null; content = content.Next)
                            {
                                PrintTree(fout, mode, indent, lexer, content);
                            }
                            return;
                        }

                        /* replace <nobr>...</nobr> by &nbsp; or &#160; etc. */
                        if (node.Tag == tt.TagNobr)
                        {
                            for (content = node.Content; content != null; content = content.Next)
                            {
                                PrintTree(fout, (int) (mode | NOWRAP), indent, lexer, content);
                            }
                            return;
                        }
                    }

                    /* otherwise a normal inline element */

                    PrintTag(lexer, fout, mode, indent, node);

                    /* indent content for SELECT, TEXTAREA, MAP, OBJECT and APPLET */

                    if (ShouldIndent(node))
                    {
                        CondFlushLine(fout, indent);
                        indent += _options.Spaces;

                        for (content = node.Content; content != null; content = content.Next)
                        {
                            PrintTree(fout, mode, indent, lexer, content);
                        }

                        CondFlushLine(fout, indent);
                        indent -= _options.Spaces;
                        CondFlushLine(fout, indent);
                    }
                    else
                    {
                        for (content = node.Content; content != null; content = content.Next)
                        {
                            PrintTree(fout, mode, indent, lexer, content);
                        }
                    }

                    PrintEndTag(fout, mode, indent, node);
                }
                else
                {
                    /* other tags */
                    CondFlushLine(fout, indent);

                    if (_options.SmartIndent && node.Prev != null)
                    {
                        FlushLine(fout, indent);
                    }

                    if (_options.HideEndTags == false || !(node.Tag != null && ((node.Tag.Model & ContentModel.OmitSt) != 0)))
                    {
                        PrintTag(lexer, fout, mode, indent, node);

                        if (ShouldIndent(node))
                        {
                            CondFlushLine(fout, indent);
                        }
                        else if ((node.Tag.Model & ContentModel.Html) != 0 || node.Tag == tt.TagNoframes || ((node.Tag.Model & ContentModel.Head) != 0 && !(node.Tag == tt.TagTitle)))
                        {
                            FlushLine(fout, indent);
                        }
                    }

                    if (node.Tag == tt.TagBody && _options.BurstSlides)
                    {
                        PrintSlide(fout, mode, (_options.IndentContent?indent + _options.Spaces:indent), lexer);
                    }
                    else
                    {
                        last = null;

                        for (content = node.Content; content != null; content = content.Next)
                        {
                            /* kludge for naked text before block level tag */
                            if (last != null && !_options.IndentContent && last.Type == Node.TextNode && content.Tag != null && (content.Tag.Model & ContentModel.Block) != 0)
                            {
                                FlushLine(fout, indent);
                                FlushLine(fout, indent);
                            }

                            PrintTree(fout, mode, (ShouldIndent(node)?indent + _options.Spaces:indent), lexer, content);

                            last = content;
                        }
                    }

                    /* don't flush line for td and th */
                    if (ShouldIndent(node) || (((node.Tag.Model & ContentModel.Html) != 0 || node.Tag == tt.TagNoframes || ((node.Tag.Model & ContentModel.Head) != 0 && !(node.Tag == tt.TagTitle))) && _options.HideEndTags == false))
                    {
                        CondFlushLine(fout, (_options.IndentContent?indent + _options.Spaces:indent));

                        if (_options.HideEndTags == false || !((node.Tag.Model & ContentModel.Opt) != 0))
                        {
                            PrintEndTag(fout, mode, indent, node);
                            FlushLine(fout, indent);
                        }
                    }
                    else
                    {
                        if (_options.HideEndTags == false || !((node.Tag.Model & ContentModel.Opt) != 0))
                        {
                            PrintEndTag(fout, mode, indent, node);
                        }

                        FlushLine(fout, indent);
                    }

                    if (_options.IndentContent == false && node.Next != null && _options.HideEndTags == false && (node.Tag.Model & (ContentModel.Block | ContentModel.List | ContentModel.Deflist | ContentModel.Table)) != 0)
                    {
                        FlushLine(fout, indent);
                    }
                }
            }
        }
Example #15
0
 private void PrintString(Out fout, int indent, string str)
 {
     for (int i = 0; i < str.Length; i++)
     {
         AddC((int) str[i], linelen++);
     }
 }
Example #16
0
        public virtual void PrintXmlTree(Out fout, int mode, int indent, Lexer lexer, Node node)
        {
            TagTable tt = _options.tt;

            if (node == null)
            {
                return;
            }

            if (node.Type == Node.TextNode)
            {
                PrintText(fout, mode, indent, node.Textarray, node.Start, node.End);
            }
            else if (node.Type == Node.CommentTag)
            {
                CondFlushLine(fout, indent);
                PrintComment(fout, 0, node);
                CondFlushLine(fout, 0);
            }
            else if (node.Type == Node.RootNode)
            {
                Node content;

                for (content = node.Content; content != null; content = content.Next)
                {
                    PrintXmlTree(fout, mode, indent, lexer, content);
                }
            }
            else if (node.Type == Node.DocTypeTag)
            {
                PrintDocType(fout, indent, node);
            }
            else if (node.Type == Node.ProcInsTag)
            {
                PrintPI(fout, indent, node);
            }
            else if (node.Type == Node.SectionTag)
            {
                PrintSection(fout, indent, node);
            }
            else if (node.Type == Node.AspTag)
            {
                PrintAsp(fout, indent, node);
            }
            else if (node.Type == Node.JsteTag)
            {
                PrintJste(fout, indent, node);
            }
            else if (node.Type == Node.PhpTag)
            {
                PrintPhp(fout, indent, node);
            }
            else if ((node.Tag.Model & ContentModel.Empty) != 0 || node.Type == Node.StartEndTag)
            {
                CondFlushLine(fout, indent);
                PrintTag(lexer, fout, mode, indent, node);
                FlushLine(fout, indent);

                if (node.Next != null)
                {
                    FlushLine(fout, indent);
                }
            }
            else
            {
                /* some kind of container element */
                Node content;
                bool mixed = false;
                int cindent;

                for (content = node.Content; content != null; content = content.Next)
                {
                    if (content.Type == Node.TextNode)
                    {
                        mixed = true;
                        break;
                    }
                }

                CondFlushLine(fout, indent);

                if (ParserImpl.XMLPreserveWhiteSpace(node, tt))
                {
                    indent = 0;
                    cindent = 0;
                    mixed = false;
                }
                else if (mixed)
                {
                    cindent = indent;
                }
                else
                {
                    cindent = indent + _options.Spaces;
                }

                PrintTag(lexer, fout, mode, indent, node);

                if (!mixed)
                {
                    FlushLine(fout, indent);
                }

                for (content = node.Content; content != null; content = content.Next)
                {
                    PrintXmlTree(fout, mode, cindent, lexer, content);
                }

                if (!mixed)
                {
                    CondFlushLine(fout, cindent);
                }
                PrintEndTag(fout, mode, indent, node);
                CondFlushLine(fout, indent);

                if (node.Next != null)
                {
                    FlushLine(fout, indent);
                }
            }
        }
Example #17
0
        private void PrintTag(Lexer lexer, Out fout, int mode, int indent, Node node)
        {
            string p;
            TagTable tt = _options.tt;

            AddC('<', linelen++);

            if (node.Type == Node.EndTag)
            {
                AddC('/', linelen++);
            }

            p = node.Element;
            for (int i = 0; i < p.Length; i++)
            {
                AddC((int) Lexer.FoldCase(p[i], _options.UpperCaseTags, _options.XmlTags), linelen++);
            }

            PrintAttrs(fout, indent, node, node.Attributes);

            if ((_options.XmlOut || lexer != null && lexer.isvoyager) && (node.Type == Node.StartEndTag || (node.Tag.Model & ContentModel.Empty) != 0))
            {
                AddC(' ', linelen++); /* compatibility hack */
                AddC('/', linelen++);
            }

            AddC('>', linelen++); ;

            if (node.Type != Node.StartEndTag && !((mode & PREFORMATTED) != 0))
            {
                if (indent + linelen >= _options.WrapLen)
                {
                    WrapLine(fout, indent);
                }

                if (indent + linelen < _options.WrapLen)
                {
                    /*
                    wrap after start tag if is <br/> or if it's not
                    inline or it is an empty tag followed by </a>
                    */
                    if (AfterSpace(node))
                    {
                        if (!((mode & NOWRAP) != 0) && (!((node.Tag.Model & ContentModel.Inline) != 0) || (node.Tag == tt.TagBr) || (((node.Tag.Model & ContentModel.Empty) != 0) && node.Next == null && node.Parent.Tag == tt.TagA)))
                        {
                            wraphere = linelen;
                        }
                    }
                }
                else
                {
                    CondFlushLine(fout, indent);
                }
            }
        }
Example #18
0
        private void PrintAttribute(Out fout, int indent, Node node, AttVal attr)
        {
            string name;
            bool wrappable = false;

            if (_options.IndentAttributes)
            {
                FlushLine(fout, indent);
                indent += _options.Spaces;
            }

            name = attr.Attribute;

            if (indent + linelen >= _options.WrapLen)
            {
                WrapLine(fout, indent);
            }

            if (!_options.XmlTags && !_options.XmlOut && attr.Dict != null)
            {
                if (AttributeTable.DefaultAttributeTable.IsScript(name))
                {
                    wrappable = _options.WrapScriptlets;
                }
                else if (!attr.Dict.Nowrap && _options.WrapAttVals)
                {
                    wrappable = true;
                }
            }

            if (indent + linelen < _options.WrapLen)
            {
                wraphere = linelen;
                AddC(' ', linelen++);
            }
            else
            {
                CondFlushLine(fout, indent);
                AddC(' ', linelen++);
            }

            for (int i = 0; i < name.Length; i++)
            {
                AddC((int) Lexer.FoldCase(name[i], _options.UpperCaseAttrs, _options.XmlTags), linelen++);
            }

            if (indent + linelen >= _options.WrapLen)
            {
                WrapLine(fout, indent);
            }

            if (attr.Val == null)
            {
                if (_options.XmlTags || _options.XmlOut)
                {
                    PrintAttrValue(fout, indent, attr.Attribute, attr.Delim, true);
                }
                else if (!attr.BoolAttribute && !Node.IsNewNode(node))
                {
                    PrintAttrValue(fout, indent, "", attr.Delim, true);
                }
                else if (indent + linelen < _options.WrapLen)
                {
                    wraphere = linelen;
                }
            }
            else
            {
                PrintAttrValue(fout, indent, attr.Val, attr.Delim, wrappable);
            }
        }
Example #19
0
        private void PrintAttrs(Out fout, int indent, Node node, AttVal attr)
        {
            if (attr != null)
            {
                if (attr.Next != null)
                {
                    PrintAttrs(fout, indent, node, attr.Next);
                }

                if (attr.Attribute != null)
                {
                    PrintAttribute(fout, indent, node, attr);
                }
                else if (attr.Asp != null)
                {
                    AddC(' ', linelen++);
                    PrintAsp(fout, indent, attr.Asp);
                }
                else if (attr.Php != null)
                {
                    AddC(' ', linelen++);
                    PrintPhp(fout, indent, attr.Php);
                }
            }

            /* add xml:space attribute to pre and other elements */
            if (_options.XmlOut && _options.XmlSpace && ParserImpl.XMLPreserveWhiteSpace(node, _options.tt) && node.GetAttrByName("xml:space") == null)
            {
                PrintString(fout, indent, " xml:space=\"preserve\"");
            }
        }