Output Stream (c) 1998-2000 (W3C) MIT, INRIA, Keio University See Tidy.cs for the copyright notice. Derived from HTML Tidy Release 4 Aug 2000
Exemple #1
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.TagTable) &&
                node.GetAttrByName("xml:space") == null)
            {
                PrintString(" xml:space=\"preserve\"");
            }
        }
Exemple #2
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;
        }
Exemple #3
0
        private void PrintAttribute(Out fout, int indent, Node node, AttVal attr)
        {
            bool wrappable = false;

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

            string 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(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);
            }
        }
Exemple #4
0
        public virtual void PrintTree(Out fout, int mode, int indent, Lexer lexer, Node node)
        {
            Node content;
            TagCollection tt = _options.TagTable;

            if (node == null)
                return;

            if (node.Type == Node.TEXT_NODE)
            {
                PrintText(fout, mode, indent, node.Textarray, node.Start, node.End);
            }
            else if (node.Type == Node.COMMENT_TAG)
            {
                PrintComment(fout, indent, node);
            }
            else if (node.Type == Node.ROOT_NODE)
            {
                for (content = node.Content; content != null; content = content.Next)
                {
                    PrintTree(fout, mode, indent, lexer, content);
                }
            }
            else if (node.Type == Node.DOC_TYPE_TAG)
            {
                PrintDocType(fout, indent, node);
            }
            else if (node.Type == Node.PROC_INS_TAG)
            {
                PrintPi(fout, indent, node);
            }
            else if (node.Type == Node.CDATA_TAG)
            {
                PrintCdata(fout, indent, node);
            }
            else if (node.Type == Node.SECTION_TAG)
            {
                PrintSection(fout, indent, node);
            }
            else if (node.Type == Node.ASP_TAG)
            {
                PrintAsp(fout, indent, node);
            }
            else if (node.Type == Node.JSTE_TAG)
            {
                PrintJste(fout, indent, node);
            }
            else if (node.Type == Node.PHP_TAG)
            {
                PrintPhp(fout, indent, node);
            }
            else if ((node.Tag.Model & ContentModel.EMPTY) != 0 || node.Type == Node.START_END_TAG)
            {
                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(" ");
                }
                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, (mode | PREFORMATTED | NOWRAP), indent, lexer, content);
                    }

                    CondFlushLine(fout, indent);
                    PrintEndTag(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, (mode | PREFORMATTED | NOWRAP | CDATA), indent, lexer, content);
                    }

                    CondFlushLine(fout, indent);
                    PrintEndTag(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, (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(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.OMIT_ST) != 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
                    {
                        Node 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.TEXT_NODE &&
                                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(node);
                            FlushLine(fout, indent);
                        }
                    }
                    else
                    {
                        if (_options.HideEndTags == false || (node.Tag.Model & ContentModel.OPT) == 0)
                        {
                            PrintEndTag(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);
                    }
                }
            }
        }
Exemple #5
0
        public virtual void PrintXmlTree(Out fout, int mode, int indent, Lexer lexer, Node node)
        {
            TagCollection tt = _options.TagTable;

            if (node == null)
            {
                return;
            }

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

                for (content = node.Content; content != null; content = content.Next)
                {
                    PrintXmlTree(fout, mode, indent, lexer, content);
                }
            }
            else if (node.Type == Node.DOC_TYPE_TAG)
            {
                PrintDocType(fout, indent, node);
            }
            else if (node.Type == Node.PROC_INS_TAG)
            {
                PrintPi(fout, indent, node);
            }
            else if (node.Type == Node.SECTION_TAG)
            {
                PrintSection(fout, indent, node);
            }
            else if (node.Type == Node.ASP_TAG)
            {
                PrintAsp(fout, indent, node);
            }
            else if (node.Type == Node.JSTE_TAG)
            {
                PrintJste(fout, indent, node);
            }
            else if (node.Type == Node.PHP_TAG)
            {
                PrintPhp(fout, indent, node);
            }
            else if ((node.Tag.Model & ContentModel.EMPTY) != 0 || node.Type == Node.START_END_TAG)
            {
                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.TEXT_NODE)
                    {
                        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(node);
                CondFlushLine(fout, indent);

                if (node.Next != null)
                {
                    FlushLine(fout, indent);
                }
            }
        }
Exemple #6
0
        public virtual void FlushLine(Out fout, int indent)
        {
            if (_linelen > 0)
            {
                if (indent + _linelen >= _options.WrapLen)
                {
                    WrapLine(fout, indent);
                }

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

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

            fout.Newline();
            _linelen = 0;
            _wraphere = 0;
            _inAttVal = false;
        }
Exemple #7
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)
        {
            TagCollection tt = _options.TagTable;

            /* insert div for onclick handler */
            string s = "<div onclick=\"document.location='slide" + (_slide < _count ? _slide + 1 : 1).ToString() +
                       ".html'\">";
            PrintString(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(Lexer.FoldCase('h', _options.UpperCaseTags, _options.XmlTags), _linelen++);
                AddC(Lexer.FoldCase('r', _options.UpperCaseTags, _options.XmlTags), _linelen++);

                if (_options.XmlOut)
                {
                    PrintString(" />");
                }
                else
                {
                    AddC('>', _linelen++);
                }

                if (_options.IndentContent)
                {
                    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 */

            Node last = null;
            Node 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.TEXT_NODE && 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("<br clear=\"all\">");
            CondFlushLine(fout, indent);

            AddC('<', _linelen++);

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

            if (_options.XmlOut)
            {
                PrintString(" />");
            }
            else
            {
                AddC('>', _linelen++);
            }

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

            PrintNavBar(fout, indent);

            /* end tag for div */
            PrintString("</div>");
            CondFlushLine(fout, indent);
        }
Exemple #8
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;
            var ci = new MutableInteger();

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

                int c = (textarray[i]) & 0xFF;

                /* 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);
            }
        }
Exemple #9
0
        private void WrapLine(Out fout, int indent)
        {
            int i;

            if (_wraphere == 0)
            {
                return;
            }

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

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

            if (_inString)
            {
                fout.Outc(' ');
                fout.Outc('\\');
            }

            fout.Newline();

            if (_linelen > _wraphere)
            {
                int p = 0;

                if (_linebuf[_wraphere] == ' ')
                {
                    ++_wraphere;
                }

                int 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;
        }
Exemple #10
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);
        }
Exemple #11
0
        private void PrintTag(Lexer lexer, Out fout, int mode, int indent, Node node)
        {
            TagCollection tt = _options.TagTable;

            AddC('<', _linelen++);

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

            string p = node.Element;
            for (int i = 0; i < p.Length; i++)
            {
                AddC(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.START_END_TAG || (node.Tag.Model & ContentModel.EMPTY) != 0))
            {
                AddC(' ', _linelen++); /* compatibility hack */
                AddC('/', _linelen++);
            }

            AddC('>', _linelen++);

            if (node.Type == Node.START_END_TAG || (mode & PREFORMATTED) != 0) return;
            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);
            }
        }
Exemple #12
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("<img width=\"0\" height=\"0\" hspace=\"1\" src=\"dot.gif\" vspace=\"%d\" align=\"left\">");
        //    CondFlushLine(fout, indent);
        //}
        private void PrintNavBar(Out fout, int indent)
        {
            string buf;

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

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

                PrintString(_slide < _count
                                ? "<a href=\"slide1.html\">start</a> | "
                                : "<a href=\"slide1.html\">start</a>");

                CondFlushLine(fout, indent);
            }

            if (_slide < _count)
            {
                buf = "<a href=\"slide" + (_slide + 1).ToString() + ".html\">next</a>";
                PrintString(buf);
            }

            PrintString("</small></center>");
            CondFlushLine(fout, indent);
        }
Exemple #13
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, 0, indent, node.Textarray, node.Start, node.End);

            if (_linelen < _options.WrapLen)
            {
                _wraphere = _linelen;
            }

            AddC('>', _linelen++);
            _options.QuoteMarks = q;
            CondFlushLine(fout, indent);
        }
Exemple #14
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);
            }
        }
Exemple #15
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;
        }
Exemple #16
0
        private void PrintAttrValue(Out fout, int indent, string val, int delim, bool wrappable)
        {
            var ci = new MutableInteger();
            bool wasinstring = false;
            byte[] valueChars = null;
            int mode = (wrappable ? (NORMAL | ATTRIBVALUE) : (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] == '<')
            {
                var 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;

                int i = 0;
                while (valueChars != null && i < valueChars.Length)
                {
                    int c = (valueChars[i]) & 0xFF;

                    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 = (c == '"' ? "&quot;" : "&#39;");

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

                        ++i;
                        continue;
                    }
                    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;
                    }
                    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++);
        }