private static HtmlDtd.TagDefinition GetTagDefinition(HtmlTagIndex tagIndex) { if (tagIndex == HtmlTagIndex._NULL) { return(null); } return(HtmlDtd.tags[(int)tagIndex]); }
internal new void Reset() { tagIndex = (originalTagIndex = HtmlTagIndex._NULL); nameIndex = HtmlNameIndex._NOTANAME; flags = TagFlags.None; partMajor = TagPartMajor.None; partMinor = TagPartMinor.Empty; name.Reset(); unstructured.Reset(); namePosition.Reset(); unstructuredPosition.Reset(); attributeTail = 0; currentAttribute = -1; attrNamePosition.Reset(); attrValuePosition.Reset(); }
internal new void Reset() { this.tagIndex = this.originalTagIndex = HtmlTagIndex._NULL; this.nameIndex = HtmlNameIndex._NOTANAME; this.flags = HtmlToken.TagFlags.None; this.partMajor = HtmlToken.TagPartMajor.None; this.partMinor = HtmlToken.TagPartMinor.Empty; this.name.Reset(); this.unstructured.Reset(); this.namePosition.Reset(); this.unstructuredPosition.Reset(); this.attributeTail = 0; this.currentAttribute = -1; this.attrNamePosition.Reset(); this.attrValuePosition.Reset(); }
private static HtmlDtd.TagDefinition GetTagDefinition(HtmlTagIndex tagIndex) { return(tagIndex != HtmlTagIndex._NULL ? HtmlDtd.tags[(int)tagIndex] : null); }
// Token: 0x060013C5 RID: 5061 RVA: 0x0008BA64 File Offset: 0x00089C64 private void Process(HtmlTokenId tokenId) { HtmlToken token = this.parser.Token; switch (tokenId) { case HtmlTokenId.EndOfFile: this.output.Write("\r\n"); this.output.Flush(); this.endOfFile = true; break; case HtmlTokenId.Text: if (!this.insideComment) { token.Text.WriteToAndCollapseWhitespace(this.output, ref this.collapseWhitespaceState); return; } break; case HtmlTokenId.EncodingChange: { ConverterEncodingOutput converterEncodingOutput = this.output as ConverterEncodingOutput; if (converterEncodingOutput != null && converterEncodingOutput.CodePageSameAsInput) { converterEncodingOutput.Encoding = token.TokenEncoding; return; } break; } case HtmlTokenId.Tag: { if (token.IsTagBegin) { switch (token.TagIndex) { case HtmlTagIndex.A: if (!token.IsEndTag) { } break; case HtmlTagIndex.Address: case HtmlTagIndex.BlockQuote: case HtmlTagIndex.BR: case HtmlTagIndex.Caption: case HtmlTagIndex.Center: case HtmlTagIndex.Col: case HtmlTagIndex.ColGroup: case HtmlTagIndex.DD: case HtmlTagIndex.Dir: case HtmlTagIndex.Div: case HtmlTagIndex.DL: case HtmlTagIndex.DT: case HtmlTagIndex.FieldSet: case HtmlTagIndex.Form: case HtmlTagIndex.H1: case HtmlTagIndex.H2: case HtmlTagIndex.H3: case HtmlTagIndex.H4: case HtmlTagIndex.H5: case HtmlTagIndex.H6: case HtmlTagIndex.HR: case HtmlTagIndex.LI: case HtmlTagIndex.Listing: case HtmlTagIndex.Map: case HtmlTagIndex.Marquee: case HtmlTagIndex.Menu: case HtmlTagIndex.OL: case HtmlTagIndex.OptGroup: case HtmlTagIndex.Option: case HtmlTagIndex.P: case HtmlTagIndex.PlainText: case HtmlTagIndex.Pre: case HtmlTagIndex.Select: case HtmlTagIndex.Table: case HtmlTagIndex.Tbody: case HtmlTagIndex.TC: case HtmlTagIndex.Tfoot: case HtmlTagIndex.Thead: case HtmlTagIndex.TR: case HtmlTagIndex.UL: this.collapseWhitespaceState = CollapseWhitespaceState.NewLine; break; case HtmlTagIndex.Comment: case HtmlTagIndex.Script: case HtmlTagIndex.Style: this.insideComment = !token.IsEndTag; break; case HtmlTagIndex.NoEmbed: case HtmlTagIndex.NoFrames: this.insideComment = !token.IsEndTag; break; case HtmlTagIndex.TD: case HtmlTagIndex.TH: if (!token.IsEndTag) { this.output.Write("\t"); } break; } } HtmlTagIndex tagIndex = token.TagIndex; if (tagIndex != HtmlTagIndex.A) { if (tagIndex != HtmlTagIndex.Area) { switch (tagIndex) { case HtmlTagIndex.Image: case HtmlTagIndex.Img: if (!token.IsEndTag) { return; } break; default: return; } } else if (!token.IsEndTag) { return; } } else if (!token.IsEndTag) { return; } break; } case HtmlTokenId.Restart: case HtmlTokenId.OverlappedClose: case HtmlTokenId.OverlappedReopen: break; default: return; } }
public FormatConverterContainer OpenContainer(FormatContainerType nodeType, bool empty, int inheritanceMaskIndex, FormatStyle baseStyle, HtmlTagIndex tagIndex) { if (!this.ContainerFlushed) { this.FlushContainer(this.EmptyContainer ? this.BuildStackTop : (this.BuildStackTop - 1)); } if (this.EmptyContainer) { this.PrepareToCloseContainer(this.BuildStackTop); } int num = this.PushContainer(nodeType, empty, inheritanceMaskIndex); if (!baseStyle.IsNull) { baseStyle.AddRef(); this.ContainerStyleBuildHelper.AddStyle(10, baseStyle.Handle); } this.BuildStack[num].TagIndex = tagIndex; return(new FormatConverterContainer(this, num)); }
private void PopElement(HtmlDtd.TagDefinition tagDef) { HtmlTagIndex tagIndex = tagDef.tagIndex; if (tagIndex <= HtmlTagIndex.Listing) { if (tagIndex <= HtmlTagIndex.DT) { if (tagIndex <= HtmlTagIndex.BR) { if (tagIndex != HtmlTagIndex.A) { if (tagIndex != HtmlTagIndex.BR) { goto IL_1D6; } goto IL_173; } else { if (insideAnchor) { EndAnchor(); goto IL_1E5; } goto IL_1E5; } } else { switch (tagIndex) { case HtmlTagIndex.Comment: break; case HtmlTagIndex.DD: goto IL_1E5; case HtmlTagIndex.Del: case HtmlTagIndex.Dfn: goto IL_1D6; case HtmlTagIndex.Dir: goto IL_196; default: if (tagIndex != HtmlTagIndex.DT) { goto IL_1D6; } goto IL_1E5; } } } else if (tagIndex <= HtmlTagIndex.HR) { if (tagIndex == HtmlTagIndex.Font) { goto IL_1CD; } if (tagIndex != HtmlTagIndex.HR) { goto IL_1D6; } EndParagraph(false); OutputText("________________________________"); EndParagraph(false); goto IL_1E5; } else { switch (tagIndex) { case HtmlTagIndex.Image: case HtmlTagIndex.Img: goto IL_1E5; default: if (tagIndex != HtmlTagIndex.Listing) { goto IL_1D6; } goto IL_1BD; } } } else if (tagIndex <= HtmlTagIndex.Style) { if (tagIndex <= HtmlTagIndex.Script) { switch (tagIndex) { case HtmlTagIndex.Menu: case HtmlTagIndex.OL: goto IL_196; case HtmlTagIndex.Meta: case HtmlTagIndex.NextId: case HtmlTagIndex.NoBR: case HtmlTagIndex.NoScript: case HtmlTagIndex.Object: case HtmlTagIndex.OptGroup: case HtmlTagIndex.Param: goto IL_1D6; case HtmlTagIndex.NoEmbed: case HtmlTagIndex.NoFrames: break; case HtmlTagIndex.Option: goto IL_173; case HtmlTagIndex.P: EndParagraph(nextParagraphCloseWideGap); nextParagraphCloseWideGap = true; goto IL_1E5; case HtmlTagIndex.PlainText: case HtmlTagIndex.Pre: goto IL_1BD; default: if (tagIndex != HtmlTagIndex.Script) { goto IL_1D6; } break; } } else { if (tagIndex == HtmlTagIndex.Span) { goto IL_1CD; } if (tagIndex != HtmlTagIndex.Style) { goto IL_1D6; } } } else { if (tagIndex <= HtmlTagIndex.Title) { if (tagIndex != HtmlTagIndex.TD) { switch (tagIndex) { case HtmlTagIndex.TH: break; case HtmlTagIndex.Thead: goto IL_1D6; case HtmlTagIndex.Title: goto IL_130; default: goto IL_1D6; } } lineStarted = true; goto IL_1E5; } if (tagIndex == HtmlTagIndex.UL) { goto IL_196; } if (tagIndex != HtmlTagIndex.Xmp) { goto IL_1D6; } goto IL_1BD; } IL_130: insideComment = false; goto IL_1E5; IL_173: EndLine(); goto IL_1E5; IL_196: if (listLevel != 0) { listLevel--; } EndParagraph(listLevel == 0); goto IL_1E5; IL_1BD: EndParagraph(true); insidePre = false; goto IL_1E5; IL_1CD: textMapping = TextMapping.Unicode; goto IL_1E5; IL_1D6: if (tagDef.blockElement) { EndParagraph(false); } IL_1E5: ignoreNextP = false; }
private void ProcessStartTagAttributes(HtmlDtd.TagDefinition tagDef) { HtmlTagIndex tagIndex = tagDef.tagIndex; if (tagIndex <= HtmlTagIndex.Font) { if (tagIndex != HtmlTagIndex.A) { if (tagIndex != HtmlTagIndex.Font) { return; } HtmlToken.AttributeEnumerator enumerator = token.Attributes.GetEnumerator(); while (enumerator.MoveNext()) { HtmlAttribute current = enumerator.Current; if (current.NameIndex == HtmlNameIndex.Face) { scratch.Reset(); scratch.AppendHtmlAttributeValue(current, 4096); RecognizeInterestingFontName recognizeInterestingFontName = default(RecognizeInterestingFontName); int num = 0; while (num < scratch.Length && !recognizeInterestingFontName.IsRejected) { recognizeInterestingFontName.AddCharacter(scratch.Buffer[num]); num++; } textMapping = recognizeInterestingFontName.TextMapping; return; } } return; } else if (outputAnchorLinks) { HtmlToken.AttributeEnumerator enumerator2 = token.Attributes.GetEnumerator(); while (enumerator2.MoveNext()) { HtmlAttribute current2 = enumerator2.Current; if (current2.NameIndex == HtmlNameIndex.Href) { if (current2.IsAttrBegin) { urlScratch.Reset(); } urlScratch.AppendHtmlAttributeValue(current2, 4096); break; } } if (token.IsTagEnd) { BufferString bufferString = urlScratch.BufferString; bufferString.TrimWhitespace(); if (bufferString.Length != 0 && bufferString[0] != '#' && bufferString[0] != '?' && bufferString[0] != ';') { if (!lineStarted) { StartParagraphOrLine(); } string text = bufferString.ToString(); if (text.IndexOf(' ') != -1) { text = text.Replace(" ", "%20"); } output.AnchorUrl = text; insideAnchor = true; if (urlCompareSink == null) { urlCompareSink = new UrlCompareSink(); } urlCompareSink.Initialize(text); } urlScratch.Reset(); return; } } } else { switch (tagIndex) { case HtmlTagIndex.Image: case HtmlTagIndex.Img: if (outputImageLinks) { HtmlToken.AttributeEnumerator enumerator3 = token.Attributes.GetEnumerator(); while (enumerator3.MoveNext()) { HtmlAttribute current3 = enumerator3.Current; if (current3.NameIndex == HtmlNameIndex.Src) { if (current3.IsAttrBegin) { urlScratch.Reset(); } urlScratch.AppendHtmlAttributeValue(current3, 4096); } else if (current3.NameIndex == HtmlNameIndex.Alt) { if (current3.IsAttrBegin) { imageAltText.Reset(); } imageAltText.AppendHtmlAttributeValue(current3, 4096); } else if (current3.NameIndex == HtmlNameIndex.Height) { if (!current3.Value.IsEmpty) { PropertyValue propertyValue; if (current3.Value.IsContiguous) { propertyValue = HtmlSupport.ParseNumber(current3.Value.ContiguousBufferString, HtmlSupport.NumberParseFlags.Length); } else { scratch.Reset(); scratch.AppendHtmlAttributeValue(current3, 4096); propertyValue = HtmlSupport.ParseNumber(scratch.BufferString, HtmlSupport.NumberParseFlags.Length); } if (propertyValue.IsAbsRelLength) { imageHeightPixels = propertyValue.PixelsInteger; if (imageHeightPixels == 0) { imageHeightPixels = 1; } } } } else if (current3.NameIndex == HtmlNameIndex.Width && !current3.Value.IsEmpty) { PropertyValue propertyValue2; if (current3.Value.IsContiguous) { propertyValue2 = HtmlSupport.ParseNumber(current3.Value.ContiguousBufferString, HtmlSupport.NumberParseFlags.Length); } else { scratch.Reset(); scratch.AppendHtmlAttributeValue(current3, 4096); propertyValue2 = HtmlSupport.ParseNumber(scratch.BufferString, HtmlSupport.NumberParseFlags.Length); } if (propertyValue2.IsAbsRelLength) { imageWidthPixels = propertyValue2.PixelsInteger; if (imageWidthPixels == 0) { imageWidthPixels = 1; } } } } if (token.IsTagEnd) { string imageUrl = null; string text2 = null; BufferString bufferString2 = imageAltText.BufferString; bufferString2.TrimWhitespace(); if (bufferString2.Length != 0) { text2 = bufferString2.ToString(); } if (text2 == null || output.ImageRenderingCallbackDefined) { BufferString bufferString3 = urlScratch.BufferString; bufferString3.TrimWhitespace(); if (bufferString3.Length != 0) { imageUrl = bufferString3.ToString(); } } if (!lineStarted) { StartParagraphOrLine(); } output.OutputImage(imageUrl, text2, imageWidthPixels, imageHeightPixels); urlScratch.Reset(); imageAltText.Reset(); imageHeightPixels = 0; imageWidthPixels = 0; return; } } break; default: if (tagIndex != HtmlTagIndex.P) { if (tagIndex != HtmlTagIndex.Span) { return; } HtmlToken.AttributeEnumerator enumerator4 = token.Attributes.GetEnumerator(); while (enumerator4.MoveNext()) { HtmlAttribute current4 = enumerator4.Current; if (current4.NameIndex == HtmlNameIndex.Style) { scratch.Reset(); scratch.AppendHtmlAttributeValue(current4, 4096); RecognizeInterestingFontNameInInlineStyle recognizeInterestingFontNameInInlineStyle = default(RecognizeInterestingFontNameInInlineStyle); int num2 = 0; while (num2 < scratch.Length && !recognizeInterestingFontNameInInlineStyle.IsFinished) { recognizeInterestingFontNameInInlineStyle.AddCharacter(scratch.Buffer[num2]); num2++; } textMapping = recognizeInterestingFontNameInInlineStyle.TextMapping; return; } } } else if (token.Attributes.Find(HtmlNameIndex.Class)) { HtmlAttribute current5 = token.Attributes.Current; if (current5.Value.CaseInsensitiveCompareEqual("msonormal")) { wideGap = false; nextParagraphCloseWideGap = false; return; } } break; } } }
private void PushElement(HtmlDtd.TagDefinition tagDef) { HtmlTagIndex tagIndex = tagDef.tagIndex; if (tagIndex <= HtmlTagIndex.Listing) { if (tagIndex <= HtmlTagIndex.DT) { if (tagIndex != HtmlTagIndex.A) { if (tagIndex == HtmlTagIndex.BR) { goto IL_193; } switch (tagIndex) { case HtmlTagIndex.Comment: break; case HtmlTagIndex.DD: if (lineStarted) { EndLine(); goto IL_2FF; } goto IL_2FF; case HtmlTagIndex.Del: case HtmlTagIndex.Dfn: case HtmlTagIndex.Div: goto IL_2F0; case HtmlTagIndex.Dir: goto IL_1BC; case HtmlTagIndex.DL: EndParagraph(true); goto IL_2FF; case HtmlTagIndex.DT: if (lineStarted) { EndLine(); goto IL_2FF; } goto IL_2FF; default: goto IL_2F0; } } else { if (insideAnchor) { EndAnchor(); goto IL_2FF; } goto IL_2FF; } } else if (tagIndex <= HtmlTagIndex.HR) { if (tagIndex == HtmlTagIndex.Font) { goto IL_2FF; } if (tagIndex != HtmlTagIndex.HR) { goto IL_2F0; } EndParagraph(false); OutputText("________________________________"); EndParagraph(false); goto IL_2FF; } else { switch (tagIndex) { case HtmlTagIndex.Image: case HtmlTagIndex.Img: goto IL_2FF; default: switch (tagIndex) { case HtmlTagIndex.LI: { EndParagraph(false); OutputText(" "); for (int i = 0; i < listLevel - 1; i++) { OutputText(" "); } if (listLevel > 1 || !listOrdered) { OutputText("*"); output.OutputSpace(3); goto IL_2FF; } string text = listIndex.ToString(); OutputText(text); OutputText("."); output.OutputSpace((text.Length == 1) ? 2 : 1); listIndex++; goto IL_2FF; } case HtmlTagIndex.Link: goto IL_2F0; case HtmlTagIndex.Listing: goto IL_2E0; default: goto IL_2F0; } //break; } } } else if (tagIndex <= HtmlTagIndex.Style) { if (tagIndex <= HtmlTagIndex.Script) { switch (tagIndex) { case HtmlTagIndex.Menu: case HtmlTagIndex.OL: goto IL_1BC; case HtmlTagIndex.Meta: case HtmlTagIndex.NextId: case HtmlTagIndex.NoBR: case HtmlTagIndex.NoScript: case HtmlTagIndex.Object: case HtmlTagIndex.OptGroup: case HtmlTagIndex.Param: goto IL_2F0; case HtmlTagIndex.NoEmbed: case HtmlTagIndex.NoFrames: break; case HtmlTagIndex.Option: goto IL_193; case HtmlTagIndex.P: if (!ignoreNextP) { EndParagraph(true); } nextParagraphCloseWideGap = true; goto IL_2FF; case HtmlTagIndex.PlainText: case HtmlTagIndex.Pre: goto IL_2E0; default: if (tagIndex != HtmlTagIndex.Script) { goto IL_2F0; } break; } } else { if (tagIndex == HtmlTagIndex.Span) { goto IL_2FF; } if (tagIndex != HtmlTagIndex.Style) { goto IL_2F0; } } } else if (tagIndex <= HtmlTagIndex.Title) { if (tagIndex != HtmlTagIndex.TD) { switch (tagIndex) { case HtmlTagIndex.TH: break; case HtmlTagIndex.Thead: goto IL_2F0; case HtmlTagIndex.Title: goto IL_13A; default: goto IL_2F0; } } if (lineStarted) { output.OutputTabulation(1); goto IL_2FF; } goto IL_2FF; } else { if (tagIndex == HtmlTagIndex.UL) { goto IL_1BC; } if (tagIndex != HtmlTagIndex.Xmp) { goto IL_2F0; } goto IL_2E0; } IL_13A: insideComment = true; goto IL_2FF; IL_193: EndLine(); goto IL_2FF; IL_1BC: EndParagraph(listLevel == 0); if (listLevel < 10) { listLevel++; if (listLevel == 1) { listIndex = 1; listOrdered = (token.TagIndex == HtmlTagIndex.OL); } } nextParagraphCloseWideGap = false; goto IL_2FF; IL_2E0: EndParagraph(true); insidePre = true; goto IL_2FF; IL_2F0: if (tagDef.blockElement) { EndParagraph(false); } IL_2FF: ignoreNextP = false; if (tagDef.tagIndex == HtmlTagIndex.LI) { ignoreNextP = true; } }
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 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; }
private void ProcessStartTagAttributes(HtmlDtd.TagDefinition tagDef) { HtmlTagIndex tagIndex = tagDef.TagIndex; if (tagIndex <= HtmlTagIndex.Font) { if (tagIndex != HtmlTagIndex.A) { if (tagIndex != HtmlTagIndex.Font) { return; } foreach (HtmlAttribute attr in this.token.Attributes) { if (attr.NameIndex == HtmlNameIndex.Face) { this.scratch.Reset(); this.scratch.AppendHtmlAttributeValue(attr, 4096); RecognizeInterestingFontName recognizeInterestingFontName = default(RecognizeInterestingFontName); int num = 0; while (num < this.scratch.Length && !recognizeInterestingFontName.IsRejected) { recognizeInterestingFontName.AddCharacter(this.scratch.Buffer[num]); num++; } this.textMapping = recognizeInterestingFontName.TextMapping; return; } } return; } else if (this.outputAnchorLinks) { foreach (HtmlAttribute attr2 in this.token.Attributes) { if (attr2.NameIndex == HtmlNameIndex.Href) { if (attr2.IsAttrBegin) { this.urlScratch.Reset(); } this.urlScratch.AppendHtmlAttributeValue(attr2, 4096); break; } } if (this.token.IsTagEnd) { BufferString bufferString = this.urlScratch.BufferString; bufferString.TrimWhitespace(); if (bufferString.Length != 0 && bufferString[0] != '#' && bufferString[0] != '?' && bufferString[0] != ';') { if (!this.lineStarted) { this.StartParagraphOrLine(); } string text = bufferString.ToString(); if (text.IndexOf(' ') != -1) { text = text.Replace(" ", "%20"); } this.output.OpenAnchor(text); this.insideAnchor = true; if (this.urlCompareSink == null) { this.urlCompareSink = new UrlCompareSink(); } this.urlCompareSink.Initialize(text); } this.urlScratch.Reset(); return; } } } else { switch (tagIndex) { case HtmlTagIndex.Image: case HtmlTagIndex.Img: if (this.outputImageLinks) { foreach (HtmlAttribute attr3 in this.token.Attributes) { if (attr3.NameIndex == HtmlNameIndex.Src) { if (attr3.IsAttrBegin) { this.urlScratch.Reset(); } this.urlScratch.AppendHtmlAttributeValue(attr3, 4096); } else if (attr3.NameIndex == HtmlNameIndex.Alt) { if (attr3.IsAttrBegin) { this.imageAltText.Reset(); } this.imageAltText.AppendHtmlAttributeValue(attr3, 4096); } else if (attr3.NameIndex == HtmlNameIndex.Height) { if (!attr3.Value.IsEmpty) { PropertyValue propertyValue; if (attr3.Value.IsContiguous) { propertyValue = HtmlSupport.ParseNumber(attr3.Value.ContiguousBufferString, HtmlSupport.NumberParseFlags.Length); } else { this.scratch.Reset(); this.scratch.AppendHtmlAttributeValue(attr3, 4096); propertyValue = HtmlSupport.ParseNumber(this.scratch.BufferString, HtmlSupport.NumberParseFlags.Length); } if (propertyValue.IsAbsRelLength) { this.imageHeightPixels = propertyValue.PixelsInteger; if (this.imageHeightPixels == 0) { this.imageHeightPixels = 1; } } } } else if (attr3.NameIndex == HtmlNameIndex.Width && !attr3.Value.IsEmpty) { PropertyValue propertyValue2; if (attr3.Value.IsContiguous) { propertyValue2 = HtmlSupport.ParseNumber(attr3.Value.ContiguousBufferString, HtmlSupport.NumberParseFlags.Length); } else { this.scratch.Reset(); this.scratch.AppendHtmlAttributeValue(attr3, 4096); propertyValue2 = HtmlSupport.ParseNumber(this.scratch.BufferString, HtmlSupport.NumberParseFlags.Length); } if (propertyValue2.IsAbsRelLength) { this.imageWidthPixels = propertyValue2.PixelsInteger; if (this.imageWidthPixels == 0) { this.imageWidthPixels = 1; } } } } if (this.token.IsTagEnd) { string imageUrl = null; string text2 = null; BufferString bufferString2 = this.imageAltText.BufferString; bufferString2.TrimWhitespace(); if (bufferString2.Length != 0) { text2 = bufferString2.ToString(); } if (text2 == null || this.output.ImageRenderingCallbackDefined) { BufferString bufferString3 = this.urlScratch.BufferString; bufferString3.TrimWhitespace(); if (bufferString3.Length != 0) { imageUrl = bufferString3.ToString(); } } if (!this.lineStarted) { this.StartParagraphOrLine(); } this.output.OutputImage(imageUrl, text2, this.imageWidthPixels, this.imageHeightPixels); this.urlScratch.Reset(); this.imageAltText.Reset(); this.imageHeightPixels = 0; this.imageWidthPixels = 0; return; } } break; default: if (tagIndex == HtmlTagIndex.P) { if (!this.shouldUseNarrowGapForPTagHtmlToTextConversion) { if (!this.token.Attributes.Find(HtmlNameIndex.Class)) { break; } HtmlAttribute htmlAttribute = this.token.Attributes.Current; if (!htmlAttribute.Value.CaseInsensitiveCompareEqual("msonormal")) { break; } } this.wideGap = false; this.nextParagraphCloseWideGap = false; return; } if (tagIndex != HtmlTagIndex.Span) { return; } foreach (HtmlAttribute attr4 in this.token.Attributes) { if (attr4.NameIndex == HtmlNameIndex.Style) { this.scratch.Reset(); this.scratch.AppendHtmlAttributeValue(attr4, 4096); RecognizeInterestingFontNameInInlineStyle recognizeInterestingFontNameInInlineStyle = default(RecognizeInterestingFontNameInInlineStyle); int num2 = 0; while (num2 < this.scratch.Length && !recognizeInterestingFontNameInInlineStyle.IsFinished) { recognizeInterestingFontNameInInlineStyle.AddCharacter(this.scratch.Buffer[num2]); num2++; } this.textMapping = recognizeInterestingFontNameInInlineStyle.TextMapping; return; } } break; } } }
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 (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; }