Exemple #1
0
        static void ParseHtmlDocument(RazorCSharpParserContext context, List <Error> errors)
        {
            var sb       = new StringBuilder();
            var spanList = new List <Span> ();

            context.Comments = new List <Comment> ();

            Action <Span> action = (Span span) =>
            {
                if (span.Kind == SpanKind.Markup)
                {
                    sb.Append(span.Content);
                    spanList.Add(span);
                }
                else
                {
                    for (int i = 0; i < span.Content.Length; i++)
                    {
                        char ch = span.Content[i];
                        if (ch != '\r' && ch != '\n')
                        {
                            sb.Append(' ');
                        }
                        else
                        {
                            sb.Append(ch);
                        }
                    }
                    if (span.Kind == SpanKind.Comment)
                    {
                        var comment = new Comment(span.Content)
                        {
                            OpenTag     = "@*",
                            ClosingTag  = "*@",
                            CommentType = CommentType.Block,
                        };
                        comment.Region = new MonoDevelop.Ide.Editor.DocumentRegion(
                            context.Document.OffsetToLocation(span.Start.AbsoluteIndex - comment.OpenTag.Length),
                            context.Document.OffsetToLocation(span.Start.AbsoluteIndex + span.Length + comment.ClosingTag.Length));
                        context.Comments.Add(comment);
                    }
                }
            };

            context.EditorParser.CurrentParseTree.Accept(new CallbackVisitor(action));

            var parser = new MonoDevelop.Xml.Parser.XmlParser(new WebFormsRootState(), true);

            try {
                parser.Parse(new StringReader(sb.ToString()));
            } catch (Exception ex) {
                LoggingService.LogError("Unhandled error parsing html in Razor document '" + (context.FileName ?? "") + "'", ex);
            }

            context.HtmlParsedDocument = parser.Nodes.GetRoot();
            errors.AddRange(parser.Errors);
        }
		void ParseHtmlDocument (List<Error> errors)
		{
			var sb = new StringBuilder ();
			var spanList = new List<Span> ();
			comments = new List<Comment> ();

			Action<Span> action = (Span span) =>
			{
				if (span.Kind == SpanKind.Markup) {
					sb.Append (span.Content);
					spanList.Add (span);
				} else {
					for (int i = 0; i < span.Content.Length; i++) {
						char ch = span.Content[i];
						if (ch != '\r' && ch != '\n')
							sb.Append (' ');
						else
							sb.Append (ch);
					}
					if (span.Kind == SpanKind.Comment) {
						var comment = new Comment (span.Content)
						{
							OpenTag = "@*",
							ClosingTag = "*@",
							CommentType = CommentType.Block,
						};
						comment.Region = new DomRegion (
							currentDocument.OffsetToLocation (span.Start.AbsoluteIndex - comment.OpenTag.Length),
							currentDocument.OffsetToLocation (span.Start.AbsoluteIndex + span.Length + comment.ClosingTag.Length));
						comments.Add (comment);
					}
				}
			};

			editorParser.CurrentParseTree.Accept (new CallbackVisitor (action));

			var parser = new MonoDevelop.Xml.Parser.XmlParser (new WebFormsRootState (), true);

			try {
				parser.Parse (new StringReader (sb.ToString ()));
			} catch (Exception ex) {
				LoggingService.LogError ("Unhandled error parsing html in Razor document '" + (lastParsedFile ?? "") + "'", ex);
			}

			htmlParsedDocument = parser.Nodes.GetRoot ();
			errors.AddRange (parser.Errors);
		}