internal void WriteTagEnd(bool emptyScopeTag) { HtmlTagIndex tagIndex = HtmlNameData.names[(int)tagNameIndex].tagIndex; if (outputState > OutputState.BeforeAttribute) { OutputAttributeEnd(); } if (tagNameIndex > HtmlNameIndex.Unknown) { output.Write('>'); lineLength++; } else { if (tagNameIndex == HtmlNameIndex._COMMENT) { output.Write("-->"); lineLength += 3; } else if (tagNameIndex == HtmlNameIndex._ASP) { output.Write("%>"); lineLength += 2; } else if (tagNameIndex == HtmlNameIndex._CONDITIONAL) { output.Write("]-->"); lineLength += 4; } else if (tagNameIndex == HtmlNameIndex.Unknown && emptyScopeTag) { output.Write(" />"); lineLength += 3; } else { output.Write('>'); lineLength++; } tagNameIndex = previousTagNameIndex; } if (isEndTag && (tagIndex == HtmlTagIndex.LI || tagIndex == HtmlTagIndex.DD || tagIndex == HtmlTagIndex.DT)) { lineLength = 0; } if (autoNewLines && literalWhitespaceNesting == 0) { HtmlDtd.TagFmt fmt = HtmlDtd.tags[(int)tagIndex].fmt; HtmlDtd.TagFill fill = HtmlDtd.tags[(int)tagIndex].fill; if ((!isEndTag && fmt.RB == HtmlDtd.FmtCode.BRK) || (isEndTag && fmt.RE == HtmlDtd.FmtCode.BRK) || (lineLength > 80 && (allowWspBeforeFollowingTag || (!isEndTag && fill.RB == HtmlDtd.FillCode.EAT) || (isEndTag && fill.RE == HtmlDtd.FillCode.EAT)))) { if (lineLength > longestLineLength) { longestLineLength = lineLength; } output.Write("\r\n"); lineLength = 0; } } if (!isEndTag && !emptyScopeTag) { HtmlDtd.Literal literal = HtmlDtd.tags[(int)tagIndex].literal; if ((byte)(literal & HtmlDtd.Literal.Tags) != 0) { literalTags = true; literalEntities = (0 != (byte)(literal & HtmlDtd.Literal.Entities)); cssEscaping = (tagIndex == HtmlTagIndex.Style); } if (HtmlDtd.tags[(int)tagIndex].contextTextType == HtmlDtd.ContextTextType.Literal) { literalWhitespaceNesting++; } } outputState = OutputState.OutsideTag; }
internal void WriteTagEnd(bool emptyScopeTag) { InternalDebug.Assert(this.outputState != OutputState.OutsideTag); InternalDebug.Assert(!this.lastWhitespace); HtmlTagIndex tagIndex = HtmlNameData.names[(int)this.tagNameIndex].tagIndex; if (this.outputState > OutputState.BeforeAttribute) { this.OutputAttributeEnd(); } if (this.tagNameIndex > HtmlNameIndex.Unknown) { this.output.Write('>'); this.lineLength++; } else { if (this.tagNameIndex == HtmlNameIndex._COMMENT) { this.output.Write("-->"); this.lineLength += 3; } else if (this.tagNameIndex == HtmlNameIndex._ASP) { this.output.Write("%>"); this.lineLength += 2; } else if (this.tagNameIndex == HtmlNameIndex._CONDITIONAL) { this.output.Write("]-->"); this.lineLength += 4; } else if (this.tagNameIndex == HtmlNameIndex.Unknown && emptyScopeTag) { this.output.Write(" />"); this.lineLength += 3; } else { this.output.Write('>'); this.lineLength++; } this.tagNameIndex = this.previousTagNameIndex; } if (this.isEndTag && (tagIndex == HtmlTagIndex.LI || tagIndex == HtmlTagIndex.DD || tagIndex == HtmlTagIndex.DT)) { this.lineLength = 0; } if (this.autoNewLines && this.literalWhitespaceNesting == 0) { HtmlDtd.TagFmt tagFmt = HtmlDtd.tags[(int)tagIndex].fmt; HtmlDtd.TagFill tagFill = HtmlDtd.tags[(int)tagIndex].fill; if ((!this.isEndTag && tagFmt.RB == HtmlDtd.FmtCode.BRK) || (this.isEndTag && tagFmt.RE == HtmlDtd.FmtCode.BRK) || (this.lineLength > 80 && (this.allowWspBeforeFollowingTag || (!this.isEndTag && tagFill.RB == HtmlDtd.FillCode.EAT) || (this.isEndTag && tagFill.RE == HtmlDtd.FillCode.EAT)))) { if (this.lineLength > this.longestLineLength) { this.longestLineLength = this.lineLength; } this.output.Write("\r\n"); this.lineLength = 0; } } if (!this.isEndTag && !emptyScopeTag) { HtmlDtd.Literal literal = HtmlDtd.tags[(int)tagIndex].literal; if (0 != (literal & HtmlDtd.Literal.Tags)) { this.literalTags = true; this.literalEntities = (0 != (literal & HtmlDtd.Literal.Entities)); this.cssEscaping = (tagIndex == HtmlTagIndex.Style); } if (HtmlDtd.tags[(int)tagIndex].contextTextType == HtmlDtd.ContextTextType.Literal) { this.literalWhitespaceNesting++; } } this.outputState = OutputState.OutsideTag; }
internal void WriteTagBegin(HtmlNameIndex nameIndex, string name, bool isEndTag, bool allowWspLeft, bool allowWspRight) { if (outputState != OutputState.OutsideTag) { WriteTagEnd(); } if (literalTags && nameIndex >= HtmlNameIndex.Unknown && (!isEndTag || nameIndex != tagNameIndex)) { throw new InvalidOperationException(TextConvertersStrings.CannotWriteOtherTagsInsideElement(HtmlNameData.names[(int)tagNameIndex].name)); } HtmlTagIndex tagIndex = HtmlNameData.names[(int)nameIndex].tagIndex; if (nameIndex > HtmlNameIndex.Unknown) { isEmptyScopeTag = (HtmlDtd.tags[(int)tagIndex].scope == HtmlDtd.TagScope.EMPTY); if (isEndTag && isEmptyScopeTag) { if (HtmlDtd.tags[(int)tagIndex].unmatchedSubstitute != HtmlTagIndex._IMPLICIT_BEGIN) { output.Write("<!-- </"); lineLength += 7; if (nameIndex > HtmlNameIndex.Unknown) { output.Write(HtmlNameData.names[(int)nameIndex].name); lineLength += HtmlNameData.names[(int)nameIndex].name.Length; } else { output.Write((name != null) ? name : "???"); lineLength += ((name != null) ? name.Length : 3); } output.Write("> "); lineLength += 2; tagNameIndex = HtmlNameIndex._COMMENT; outputState = OutputState.WritingUnstructuredTagContent; return; } isEndTag = false; } } if (autoNewLines && literalWhitespaceNesting == 0) { bool flag = lastWhitespace; HtmlDtd.TagFill fill = HtmlDtd.tags[(int)tagIndex].fill; if (lineLength != 0) { HtmlDtd.TagFmt fmt = HtmlDtd.tags[(int)tagIndex].fmt; if ((!isEndTag && fmt.LB == HtmlDtd.FmtCode.BRK) || (isEndTag && fmt.LE == HtmlDtd.FmtCode.BRK) || (lineLength > 80 && (lastWhitespace || allowWspBeforeFollowingTag || (!isEndTag && fill.LB == HtmlDtd.FillCode.EAT) || (isEndTag && fill.LE == HtmlDtd.FillCode.EAT)))) { if (lineLength > longestLineLength) { longestLineLength = lineLength; } output.Write("\r\n"); lineLength = 0; lastWhitespace = false; } } allowWspBeforeFollowingTag = (((!isEndTag && fill.RB == HtmlDtd.FillCode.EAT) || (isEndTag && fill.RE == HtmlDtd.FillCode.EAT) || (flag && ((!isEndTag && fill.RB == HtmlDtd.FillCode.NUL) || (isEndTag && fill.RE == HtmlDtd.FillCode.NUL)))) && (nameIndex != HtmlNameIndex.Body || !isEndTag)); } if (lastWhitespace) { output.Write(' '); lineLength++; lastWhitespace = false; } if (HtmlDtd.tags[(int)tagIndex].blockElement || tagIndex == HtmlTagIndex.BR) { textLineLength = 0; } output.Write('<'); lineLength++; if (nameIndex >= HtmlNameIndex.Unknown) { if (isEndTag) { if ((byte)(HtmlDtd.tags[(int)tagIndex].literal & HtmlDtd.Literal.Tags) != 0) { literalTags = false; literalEntities = false; cssEscaping = false; } if (HtmlDtd.tags[(int)tagIndex].contextTextType == HtmlDtd.ContextTextType.Literal) { literalWhitespaceNesting--; } output.Write('/'); lineLength++; } if (nameIndex != HtmlNameIndex.Unknown) { output.Write(HtmlNameData.names[(int)nameIndex].name); lineLength += HtmlNameData.names[(int)nameIndex].name.Length; outputState = OutputState.BeforeAttribute; } else { if (name != null) { output.Write(name); lineLength += name.Length; outputState = OutputState.BeforeAttribute; } else { outputState = OutputState.TagStarted; } isEmptyScopeTag = false; } } else { previousTagNameIndex = tagNameIndex; if (nameIndex == HtmlNameIndex._COMMENT) { output.Write("!--"); lineLength += 3; } else if (nameIndex == HtmlNameIndex._ASP) { output.Write('%'); lineLength++; } else if (nameIndex == HtmlNameIndex._CONDITIONAL) { output.Write("!--["); lineLength += 4; } else if (nameIndex == HtmlNameIndex._DTD) { output.Write('?'); lineLength++; } else { output.Write('!'); lineLength++; } outputState = OutputState.WritingUnstructuredTagContent; isEmptyScopeTag = true; } tagNameIndex = nameIndex; this.isEndTag = isEndTag; }
internal void WriteTagBegin(HtmlNameIndex nameIndex, string name, bool isEndTag, bool allowWspLeft, bool allowWspRight) { if (this.outputState != OutputState.OutsideTag) { this.WriteTagEnd(); } #if !BETTER_FUZZING if (this.literalTags && nameIndex >= HtmlNameIndex.Unknown && (!isEndTag || nameIndex != this.tagNameIndex)) { throw new InvalidOperationException(Strings.CannotWriteOtherTagsInsideElement(HtmlNameData.names[(int)this.tagNameIndex].name)); } #endif HtmlTagIndex tagIndex = HtmlNameData.names[(int)nameIndex].tagIndex; if (nameIndex > HtmlNameIndex.Unknown) { this.isEmptyScopeTag = (HtmlDtd.tags[(int)tagIndex].scope == HtmlDtd.TagScope.EMPTY); if (isEndTag && this.isEmptyScopeTag) { if (HtmlDtd.tags[(int)tagIndex].unmatchedSubstitute != HtmlTagIndex._IMPLICIT_BEGIN) { this.output.Write("<!-- </"); this.lineLength += 7; if (nameIndex > HtmlNameIndex.Unknown) { this.output.Write(HtmlNameData.names[(int)nameIndex].name); this.lineLength += HtmlNameData.names[(int)nameIndex].name.Length; } else { this.output.Write(name != null ? name : "???"); this.lineLength += name != null ? name.Length : 3; } this.output.Write("> "); this.lineLength += 2; this.tagNameIndex = HtmlNameIndex._COMMENT; this.outputState = OutputState.WritingUnstructuredTagContent; return; } isEndTag = false; } } InternalDebug.Assert(0 == (HtmlDtd.tags[(int)tagIndex].literal & HtmlDtd.Literal.Entities) || 0 != (HtmlDtd.tags[(int)tagIndex].literal & HtmlDtd.Literal.Tags)); if (this.autoNewLines && this.literalWhitespaceNesting == 0) { bool hadWhitespaceBeforeTag = this.lastWhitespace; HtmlDtd.TagFill tagFill = HtmlDtd.tags[(int)tagIndex].fill; if (this.lineLength != 0) { HtmlDtd.TagFmt tagFmt = HtmlDtd.tags[(int)tagIndex].fmt; if ((!isEndTag && tagFmt.LB == HtmlDtd.FmtCode.BRK) || (isEndTag && tagFmt.LE == HtmlDtd.FmtCode.BRK) || (this.lineLength > 80 && (this.lastWhitespace || this.allowWspBeforeFollowingTag || (!isEndTag && tagFill.LB == HtmlDtd.FillCode.EAT) || (isEndTag && tagFill.LE == HtmlDtd.FillCode.EAT)))) { if (this.lineLength > this.longestLineLength) { this.longestLineLength = this.lineLength; } this.output.Write("\r\n"); this.lineLength = 0; this.lastWhitespace = false; } } this.allowWspBeforeFollowingTag = ((!isEndTag && tagFill.RB == HtmlDtd.FillCode.EAT) || (isEndTag && tagFill.RE == HtmlDtd.FillCode.EAT) || hadWhitespaceBeforeTag && ((!isEndTag && tagFill.RB == HtmlDtd.FillCode.NUL) || (isEndTag && tagFill.RE == HtmlDtd.FillCode.NUL))) && (nameIndex != HtmlNameIndex.Body || !isEndTag); } if (this.lastWhitespace) { this.output.Write(' '); this.lineLength++; this.lastWhitespace = false; } if (HtmlDtd.tags[(int)tagIndex].blockElement || tagIndex == HtmlTagIndex.BR) { this.textLineLength = 0; } this.output.Write('<'); this.lineLength++; if (nameIndex >= HtmlNameIndex.Unknown) { if (isEndTag) { if (0 != (HtmlDtd.tags[(int)tagIndex].literal & HtmlDtd.Literal.Tags)) { this.literalTags = false; this.literalEntities = false; this.cssEscaping = false; } if (HtmlDtd.tags[(int)tagIndex].contextTextType == HtmlDtd.ContextTextType.Literal) { this.literalWhitespaceNesting--; } this.output.Write('/'); this.lineLength++; } if (nameIndex != HtmlNameIndex.Unknown) { this.output.Write(HtmlNameData.names[(int)nameIndex].name); this.lineLength += HtmlNameData.names[(int)nameIndex].name.Length; this.outputState = OutputState.BeforeAttribute; } else { if (name != null) { this.output.Write(name); this.lineLength += name.Length; this.outputState = OutputState.BeforeAttribute; } else { this.outputState = OutputState.TagStarted; } this.isEmptyScopeTag = false; } } else { this.previousTagNameIndex = this.tagNameIndex; if (nameIndex == HtmlNameIndex._COMMENT) { this.output.Write("!--"); this.lineLength += 3; } else if (nameIndex == HtmlNameIndex._ASP) { this.output.Write('%'); this.lineLength++; } else if (nameIndex == HtmlNameIndex._CONDITIONAL) { this.output.Write("!--["); this.lineLength += 4; } else if (nameIndex == HtmlNameIndex._DTD) { this.output.Write('?'); this.lineLength++; } else { this.output.Write('!'); this.lineLength++; } this.outputState = OutputState.WritingUnstructuredTagContent; this.isEmptyScopeTag = true; } this.tagNameIndex = nameIndex; this.isEndTag = isEndTag; }