public static RazorHtmlDocument GetHtmlDocument(RazorCodeDocument codeDocument) { var options = codeDocument.GetCodeGenerationOptions(); if (options == null || !options.DesignTime) { // Not needed in run time. This pass generates the backing HTML document that is used to provide HTML intellisense. return(null); } var writer = new RazorHtmlWriter(codeDocument.Source); var syntaxTree = codeDocument.GetSyntaxTree(); writer.Visit(syntaxTree.Root); var generatedHtml = writer.Builder.ToString(); Debug.Assert( writer.Source.Length == writer.Builder.Length, $"The backing HTML document should be the same length as the original document. Expected: {writer.Source.Length} Actual: {writer.Builder.Length}"); var razorHtmlDocument = new DefaultRazorHtmlDocument(generatedHtml, options); return(razorHtmlDocument); }
internal static RazorHtmlDocument GetHtmlDocument(this RazorCodeDocument document) { if (document == null) { throw new ArgumentNullException(nameof(document)); } var razorHtmlObj = document.Items[typeof(RazorHtmlDocument)]; if (razorHtmlObj == null) { var razorHtmlDocument = RazorHtmlWriter.GetHtmlDocument(document); if (razorHtmlDocument != null) { document.Items[typeof(RazorHtmlDocument)] = razorHtmlDocument; return(razorHtmlDocument); } } return((RazorHtmlDocument)razorHtmlObj); }