/// <summary>
        /// Get the contents of a template
        /// </summary>
        /// <param name="templateName">Name/location of the template</param>
        /// <param name="model">Model to use to locate the template via conventions</param>
        /// <returns>Contents of the template, or null if not found</returns>
        public string GetTemplate(string templateName, object model)
        {
            var viewLocationResult = this.renderContext.LocateView(templateName, model);

            if (viewLocationResult == null)
            {
                return("[ERR!]");
            }

            string templateContent;

            using (var reader = viewLocationResult.Contents.Invoke())
                templateContent = reader.ReadToEnd();

            if (viewLocationResult.Name.ToLower() == "master" && validExtensions.Any(x => x.Equals(viewLocationResult.Extension, StringComparison.OrdinalIgnoreCase)))
            {
                return(MarkdownViewengineRender.RenderMasterPage(templateContent));
            }

            if (!validExtensions.Any(x => x.Equals(viewLocationResult.Extension, StringComparison.OrdinalIgnoreCase)))
            {
                using (var reader = viewLocationResult.Contents.Invoke())
                    return(reader.ReadToEnd());
            }

            return(parser.Transform(templateContent));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Converts the markdown.
        /// </summary>
        /// <returns>
        /// HTML converted from markdown
        /// </returns>
        /// <param name='viewLocationResult'>
        /// View location result.
        /// </param>
        public string ConvertMarkdown(ViewLocationResult viewLocationResult)
        {
            string content =
                viewLocationResult.Contents().ReadToEnd();

            if (content.StartsWith("<!DOCTYPE html>"))
            {
                return(MarkdownViewengineRender.RenderMasterPage(content));
            }

            var parser = new Markdown();
            var html   = parser.Transform(content);

            return(ParagraphSubstitution.Replace(html, "$1"));
        }