private void LFillTagB(HtmlDtd.TagDefinition tagDef) { if (!this.insidePre) { this.LFill(tagDef.fill.LB); } }
private void RFillTagE(HtmlDtd.TagDefinition tagDef) { if (!this.insidePre) { this.RFill(tagDef.fill.RE); } }
private void LFillTagE(HtmlDtd.TagDefinition tagDef) { if (!insidePre) { LFill(tagDef.fill.LE); } }
private void RFillTagB(HtmlDtd.TagDefinition tagDef) { if (!insidePre) { RFill(tagDef.fill.RB); } }
private void PopElement(HtmlDtd.TagDefinition tagDef) { switch (tagDef.tagIndex) { case HtmlTagIndex.Title: case HtmlTagIndex.Comment: case HtmlTagIndex.Script: case HtmlTagIndex.Style: case HtmlTagIndex.NoEmbed: case HtmlTagIndex.NoFrames: this.insideComment = false; break; case HtmlTagIndex.A: if (this.insideAnchor) { this.EndAnchor(); } break; case HtmlTagIndex.Image: case HtmlTagIndex.Img: break; case HtmlTagIndex.TD: case HtmlTagIndex.TH: this.lineStarted = true; break; case HtmlTagIndex.P: this.EndParagraph(this.nextParagraphCloseWideGap); this.nextParagraphCloseWideGap = true; break; case HtmlTagIndex.BR: case HtmlTagIndex.Option: this.EndLine(); break; case HtmlTagIndex.HR: this.EndParagraph(false); this.OutputText("________________________________"); this.EndParagraph(false); break; case HtmlTagIndex.OL: case HtmlTagIndex.UL: case HtmlTagIndex.Dir: case HtmlTagIndex.Menu: if (this.listLevel != 0) { this.listLevel--; } this.EndParagraph(this.listLevel == 0); break; case HtmlTagIndex.DT: break; case HtmlTagIndex.DD: break; case HtmlTagIndex.Pre: case HtmlTagIndex.PlainText: case HtmlTagIndex.Listing: case HtmlTagIndex.Xmp: this.EndParagraph(true); this.insidePre = false; break; case HtmlTagIndex.Font: case HtmlTagIndex.Span: this.textMapping = TextMapping.Unicode; break; default: if (tagDef.blockElement) { this.EndParagraph(false); } break; } this.ignoreNextP = false; }
private void ProcessStartTagAttributes(HtmlDtd.TagDefinition tagDef) { switch (tagDef.tagIndex) { case HtmlTagIndex.A: if (this.outputAnchorLinks) { foreach (HtmlAttribute attr in this.token.Attributes) { if (attr.NameIndex == HtmlNameIndex.Href) { if (attr.IsAttrBegin) { this.urlScratch.Reset(); } this.urlScratch.AppendHtmlAttributeValue(attr, HtmlSupport.MaxAttributeSize); break; } } if (this.token.IsTagEnd) { BufferString url = this.urlScratch.BufferString; url.TrimWhitespace(); if (url.Length != 0 && url[0] != '#' && url[0] != '?' && url[0] != ';') { if (!this.lineStarted) { this.StartParagraphOrLine(); } string urlString = url.ToString(); if (urlString.IndexOf(' ') != -1) { urlString = urlString.Replace(" ", "%20"); } this.output.AnchorUrl = urlString; this.insideAnchor = true; if (this.urlCompareSink == null) { this.urlCompareSink = new UrlCompareSink(); } this.urlCompareSink.Initialize(urlString); } this.urlScratch.Reset(); } } break; case HtmlTagIndex.Image: case HtmlTagIndex.Img: if (this.outputImageLinks) { foreach (HtmlAttribute attr in this.token.Attributes) { if (attr.NameIndex == HtmlNameIndex.Src) { if (attr.IsAttrBegin) { this.urlScratch.Reset(); } this.urlScratch.AppendHtmlAttributeValue(attr, HtmlSupport.MaxAttributeSize); } else if (attr.NameIndex == HtmlNameIndex.Alt) { if (attr.IsAttrBegin) { this.imageAltText.Reset(); } this.imageAltText.AppendHtmlAttributeValue(attr, HtmlSupport.MaxAttributeSize); } else if (attr.NameIndex == HtmlNameIndex.Height) { if (!attr.Value.IsEmpty) { PropertyValue value; if (attr.Value.IsContiguous) { value = HtmlSupport.ParseNumber(attr.Value.ContiguousBufferString, HtmlSupport.NumberParseFlags.Length); } else { this.scratch.Reset(); this.scratch.AppendHtmlAttributeValue(attr, HtmlSupport.MaxAttributeSize); value = HtmlSupport.ParseNumber(this.scratch.BufferString, HtmlSupport.NumberParseFlags.Length); } if (value.IsAbsRelLength) { this.imageHeightPixels = value.PixelsInteger; if (this.imageHeightPixels == 0) { this.imageHeightPixels = 1; } } } } else if (attr.NameIndex == HtmlNameIndex.Width) { if (!attr.Value.IsEmpty) { PropertyValue value; if (attr.Value.IsContiguous) { value = HtmlSupport.ParseNumber(attr.Value.ContiguousBufferString, HtmlSupport.NumberParseFlags.Length); } else { this.scratch.Reset(); this.scratch.AppendHtmlAttributeValue(attr, HtmlSupport.MaxAttributeSize); value = HtmlSupport.ParseNumber(this.scratch.BufferString, HtmlSupport.NumberParseFlags.Length); } if (value.IsAbsRelLength) { this.imageWidthPixels = value.PixelsInteger; if (this.imageWidthPixels == 0) { this.imageWidthPixels = 1; } } } } } if (this.token.IsTagEnd) { string urlString = null; string altString = null; BufferString alt = this.imageAltText.BufferString; alt.TrimWhitespace(); if (alt.Length != 0) { altString = alt.ToString(); } if (altString == null || this.output.ImageRenderingCallbackDefined) { BufferString url = this.urlScratch.BufferString; url.TrimWhitespace(); if (url.Length != 0) { urlString = url.ToString(); } } if (!this.lineStarted) { this.StartParagraphOrLine(); } this.output.OutputImage(urlString, altString, this.imageWidthPixels, this.imageHeightPixels); this.urlScratch.Reset(); this.imageAltText.Reset(); this.imageHeightPixels = 0; this.imageWidthPixels = 0; } } break; case HtmlTagIndex.P: if (this.token.Attributes.Find(HtmlNameIndex.Class) && this.token.Attributes.Current.Value.CaseInsensitiveCompareEqual("msonormal")) { this.wideGap = false; this.nextParagraphCloseWideGap = false; } break; case HtmlTagIndex.Font: foreach (HtmlAttribute attr in this.token.Attributes) { if (attr.NameIndex == HtmlNameIndex.Face) { this.scratch.Reset(); this.scratch.AppendHtmlAttributeValue(attr, HtmlSupport.MaxAttributeSize); RecognizeInterestingFontName fontRecognizer = new RecognizeInterestingFontName(); for (int i = 0; i < this.scratch.Length && !fontRecognizer.IsRejected; i++) { fontRecognizer.AddCharacter(this.scratch.Buffer[i]); } this.textMapping = fontRecognizer.TextMapping; break; } } break; case HtmlTagIndex.Span: foreach (HtmlAttribute attr in this.token.Attributes) { if (attr.NameIndex == HtmlNameIndex.Style) { this.scratch.Reset(); this.scratch.AppendHtmlAttributeValue(attr, HtmlSupport.MaxAttributeSize); RecognizeInterestingFontNameInInlineStyle fontRecognizer = new RecognizeInterestingFontNameInInlineStyle(); for (int i = 0; i < this.scratch.Length && !fontRecognizer.IsFinished; i++) { fontRecognizer.AddCharacter(this.scratch.Buffer[i]); } this.textMapping = fontRecognizer.TextMapping; break; } } break; } }
private void PushElement(HtmlDtd.TagDefinition tagDef) { switch (tagDef.tagIndex) { case HtmlTagIndex.Title: case HtmlTagIndex.Comment: case HtmlTagIndex.Script: case HtmlTagIndex.Style: case HtmlTagIndex.NoEmbed: case HtmlTagIndex.NoFrames: this.insideComment = true; break; case HtmlTagIndex.A: if (this.insideAnchor) { this.EndAnchor(); } break; case HtmlTagIndex.Image: case HtmlTagIndex.Img: break; case HtmlTagIndex.TD: case HtmlTagIndex.TH: if (this.lineStarted) { this.output.OutputTabulation(1); } break; case HtmlTagIndex.P: if (!this.ignoreNextP) { this.EndParagraph(true); } this.nextParagraphCloseWideGap = true; break; case HtmlTagIndex.BR: case HtmlTagIndex.Option: this.EndLine(); break; case HtmlTagIndex.HR: this.EndParagraph(false); this.OutputText("________________________________"); this.EndParagraph(false); break; case HtmlTagIndex.OL: case HtmlTagIndex.UL: case HtmlTagIndex.Dir: case HtmlTagIndex.Menu: this.EndParagraph(this.listLevel == 0); if (this.listLevel < 10) { this.listLevel++; if (this.listLevel == 1) { this.listIndex = 1; this.listOrdered = (this.token.TagIndex == HtmlTagIndex.OL); } } this.nextParagraphCloseWideGap = false; break; case HtmlTagIndex.LI: this.EndParagraph(false); this.OutputText(" "); for (int i = 0; i < this.listLevel - 1; i++) { this.OutputText(" "); } if (this.listLevel > 1 || !this.listOrdered) { this.OutputText("*"); this.output.OutputSpace(3); } else { string num = this.listIndex.ToString(); this.OutputText(num); this.OutputText("."); this.output.OutputSpace(num.Length == 1 ? 2 : 1); this.listIndex++; } break; case HtmlTagIndex.DL: this.EndParagraph(true); break; case HtmlTagIndex.DT: if (this.lineStarted) { this.EndLine(); } break; case HtmlTagIndex.DD: if (this.lineStarted) { this.EndLine(); } break; case HtmlTagIndex.Pre: case HtmlTagIndex.PlainText: case HtmlTagIndex.Listing: case HtmlTagIndex.Xmp: this.EndParagraph(true); this.insidePre = true; break; case HtmlTagIndex.Font: case HtmlTagIndex.Span: break; default: if (tagDef.blockElement) { this.EndParagraph(false); } break; } this.ignoreNextP = false; if (tagDef.tagIndex == HtmlTagIndex.LI) { this.ignoreNextP = true; } }
private void Process(HtmlTokenId tokenId) { this.token = this.parser.Token; switch (tokenId) { case HtmlTokenId.Tag: if (this.token.TagIndex <= HtmlTagIndex.Unknown) { break; } HtmlDtd.TagDefinition tagDef = GetTagDefinition(this.token.TagIndex); if (this.normalizedInput) { if (!this.token.IsEndTag) { if (this.token.IsTagBegin) { this.PushElement(tagDef); } this.ProcessStartTagAttributes(tagDef); } else { if (this.token.IsTagBegin) { this.PopElement(tagDef); } } } else { if (!this.token.IsEndTag) { if (this.token.IsTagBegin) { this.LFillTagB(tagDef); this.PushElement(tagDef); this.RFillTagB(tagDef); } this.ProcessStartTagAttributes(tagDef); } else { if (this.token.IsTagBegin) { this.LFillTagE(tagDef); this.PopElement(tagDef); this.RFillTagE(tagDef); } } } break; case HtmlTokenId.Text: if (!this.insideComment) { if (this.insideAnchor && this.urlCompareSink.IsActive) { token.Text.WriteTo(this.urlCompareSink); } if (this.insidePre) { this.ProcessPreformatedText(); } else if (this.normalizedInput) { this.ProcessText(); } else { this.NormalizeProcessText(); } } break; case HtmlTokenId.OverlappedClose: case HtmlTokenId.OverlappedReopen: break; case HtmlTokenId.Restart: break; case HtmlTokenId.EncodingChange: if (this.output.OutputCodePageSameAsInput) { int codePage = this.token.Argument; #if DEBUG Encoding newOutputEncoding; InternalDebug.Assert(Charset.TryGetEncoding(codePage, out newOutputEncoding)); #endif this.output.OutputEncoding = Charset.GetEncoding(codePage); } break; case HtmlTokenId.EndOfFile: if (this.lineStarted) { this.output.OutputNewLine(); this.lineStarted = false; } if (!this.convertFragment) { if (this.injection != null && this.injection.HaveHead) { if (this.wideGap) { this.output.OutputNewLine(); this.wideGap = false; } this.injection.Inject(false, this.output); } this.output.CloseDocument(); this.output.Flush(); } this.endOfFile = true; break; } }
// Token: 0x060013EC RID: 5100 RVA: 0x0008DCE8 File Offset: 0x0008BEE8 protected override void Process(HtmlTokenId tokenId) { this.token = this.parser.Token; switch (tokenId) { case HtmlTokenId.EndOfFile: base.CloseAllContainersAndSetEOF(); break; case HtmlTokenId.Text: if (this.insideStyle) { this.OutputEncapsulatedMarkup(); this.token.Text.WriteTo(this.cssParserInput); return; } if (this.insideComment) { this.OutputEncapsulatedMarkup(); return; } if (this.insidePre) { base.ProcessPreformatedText(); return; } base.ProcessText(); return; case HtmlTokenId.EncodingChange: if (this.output != null && this.output.OutputCodePageSameAsInput) { this.output.OutputEncoding = this.token.TokenEncoding; return; } break; case HtmlTokenId.Tag: this.OutputEncapsulatedMarkup(); if (this.token.TagIndex <= HtmlTagIndex.Unknown) { if (this.insideStyle && this.token.TagIndex == HtmlTagIndex._COMMENT) { this.token.Text.WriteTo(this.cssParserInput); return; } } else { HtmlDtd.TagDefinition tagDefinition = HtmlFormatConverter.GetTagDefinition(this.token.TagIndex); if (!this.token.IsEndTag) { if (this.token.IsTagBegin) { base.PushElement(tagDefinition, this.token.IsEmptyScope); } base.ProcessStartTagAttributes(tagDefinition); return; } if (this.token.IsTagEnd) { base.PopElement(this.BuildStackTop - 1 - this.temporarilyClosedLevels, this.token.Argument != 1); return; } } break; case HtmlTokenId.Restart: break; case HtmlTokenId.OverlappedClose: this.temporarilyClosedLevels = this.token.Argument; return; case HtmlTokenId.OverlappedReopen: this.temporarilyClosedLevels = 0; return; default: return; } }
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; } }
private void Process(HtmlTokenId tokenId) { token = parser.Token; switch (tokenId) { case HtmlTokenId.EndOfFile: if (lineStarted) { output.OutputNewLine(); lineStarted = false; } if (!convertFragment) { if (injection != null && injection.HaveHead) { if (wideGap) { output.OutputNewLine(); wideGap = false; } injection.Inject(false, output); } output.CloseDocument(); output.Flush(); } endOfFile = true; break; case HtmlTokenId.Text: if (!insideComment) { if (insideAnchor && urlCompareSink.IsActive) { token.Text.WriteTo(urlCompareSink); } if (insidePre) { ProcessPreformatedText(); return; } if (normalizedInput) { ProcessText(); return; } NormalizeProcessText(); return; } break; case HtmlTokenId.EncodingChange: if (output.OutputCodePageSameAsInput) { int argument = token.Argument; output.OutputEncoding = Charset.GetEncoding(argument); return; } break; case HtmlTokenId.Tag: { if (token.TagIndex <= HtmlTagIndex.Unknown) { return; } HtmlDtd.TagDefinition tagDefinition = GetTagDefinition(token.TagIndex); if (normalizedInput) { if (!token.IsEndTag) { if (token.IsTagBegin) { PushElement(tagDefinition); } ProcessStartTagAttributes(tagDefinition); return; } if (token.IsTagBegin) { PopElement(tagDefinition); return; } } else { if (!token.IsEndTag) { if (token.IsTagBegin) { LFillTagB(tagDefinition); PushElement(tagDefinition); RFillTagB(tagDefinition); } ProcessStartTagAttributes(tagDefinition); return; } if (token.IsTagBegin) { LFillTagE(tagDefinition); PopElement(tagDefinition); RFillTagE(tagDefinition); return; } } break; } case HtmlTokenId.Restart: case HtmlTokenId.OverlappedClose: case HtmlTokenId.OverlappedReopen: break; default: return; } }
private void Process(HtmlTokenId tokenId) { this.token = this.parser.Token; switch (tokenId) { case HtmlTokenId.EndOfFile: if (this.lineStarted) { this.output.OutputNewLine(); this.lineStarted = false; } if (!this.convertFragment) { if (this.injection != null && this.injection.HaveHead) { if (this.wideGap) { this.output.OutputNewLine(); this.wideGap = false; } this.injection.Inject(false, this.output); } this.output.CloseDocument(); this.output.Flush(); } this.endOfFile = true; break; case HtmlTokenId.Text: if (!this.insideComment) { if (this.insideAnchor && this.urlCompareSink.IsActive) { this.token.Text.WriteTo(this.urlCompareSink); } if (this.insidePre) { this.ProcessPreformatedText(); return; } if (this.normalizedInput) { this.ProcessText(); return; } this.NormalizeProcessText(); return; } break; case HtmlTokenId.EncodingChange: if (this.output.OutputCodePageSameAsInput) { this.output.OutputEncoding = this.token.TokenEncoding; return; } break; case HtmlTokenId.Tag: { if (this.token.TagIndex <= HtmlTagIndex.Unknown) { return; } HtmlDtd.TagDefinition tagDefinition = HtmlToTextConverter.GetTagDefinition(this.token.TagIndex); if (this.normalizedInput) { if (!this.token.IsEndTag) { if (this.token.IsTagBegin) { this.PushElement(tagDefinition); } this.ProcessStartTagAttributes(tagDefinition); return; } if (this.token.IsTagBegin) { this.PopElement(tagDefinition); return; } } else { if (!this.token.IsEndTag) { if (this.token.IsTagBegin) { this.LFillTagB(tagDefinition); this.PushElement(tagDefinition); this.RFillTagB(tagDefinition); } this.ProcessStartTagAttributes(tagDefinition); return; } if (this.token.IsTagBegin) { this.LFillTagE(tagDefinition); this.PopElement(tagDefinition); this.RFillTagE(tagDefinition); return; } } break; } case HtmlTokenId.Restart: case HtmlTokenId.OverlappedClose: case HtmlTokenId.OverlappedReopen: break; default: return; } }
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; } } }