From b35163b10ebbf49ada2cc8b6d13efe1439d42fdc Mon Sep 17 00:00:00 2001 From: Frans Bouma Date: Wed, 9 Mar 2016 12:50:45 +0100 Subject: [PATCH] Corrections on #31 code, _partial=>Includes. Spaces=>Tabs, some clean up (minor) --- src/DocNet/SimpleNavigationElement.cs | 6 ++-- src/DocNet/Utils.cs | 65 ++++++++++++++++++----------------- 2 files changed, 37 insertions(+), 34 deletions(-) diff --git a/src/DocNet/SimpleNavigationElement.cs b/src/DocNet/SimpleNavigationElement.cs index 0bfa620..eb59dc2 100644 --- a/src/DocNet/SimpleNavigationElement.cs +++ b/src/DocNet/SimpleNavigationElement.cs @@ -66,9 +66,9 @@ namespace Docnet if(File.Exists(sourceFile)) { this.MarkdownFromFile = File.ReadAllText(sourceFile); - // Check if the content contains @@include tag - content = Utils.IncludeProcessor(this.MarkdownFromFile, Path.Combine(activeConfig.Source, "_partials")); - content = Utils.ConvertMarkdownToHtml(content, Path.GetDirectoryName(destinationFile), activeConfig.Destination, _relativeH2LinksOnPage); + // Check if the content contains @@include tag + content = Utils.IncludeProcessor(this.MarkdownFromFile, Path.Combine(activeConfig.Source, "Includes")); + content = Utils.ConvertMarkdownToHtml(content, Path.GetDirectoryName(destinationFile), activeConfig.Destination, _relativeH2LinksOnPage); } else { diff --git a/src/DocNet/Utils.cs b/src/DocNet/Utils.cs index 1f9e198..738cb1b 100644 --- a/src/DocNet/Utils.cs +++ b/src/DocNet/Utils.cs @@ -32,6 +32,13 @@ namespace Docnet { public static class Utils { + #region Statics + /// + /// Regex expression used to parse @@include(filename.html) tag. + /// + private static Regex includeRegex = new Regex(@"@@include\((.*)\)", RegexOptions.IgnoreCase | RegexOptions.Compiled); + #endregion + /// /// Converts the markdown to HTML. /// @@ -199,36 +206,32 @@ namespace Docnet return Utils.MakeRelativePath(fromPath, toPath).Replace(@"\", @"/"); } - /// - /// Regex expression used to parse @@include(filename.html) tag. - /// - private static Regex includeRegex = new Regex(@"@@include\((.*)\)", RegexOptions.IgnoreCase | RegexOptions.Compiled); - - /// - /// Process the input for @@include tags and embeds the included content - /// into the output. - /// - /// content to be scanned for include tags - /// Directory containing the partials - /// String with @@content replaced with the actual content from the partial. - public static string IncludeProcessor(String content, string partialPath) - { - Match m = includeRegex.Match(content); - while (m.Success) - { - if (m.Groups.Count > 1) - { - string tagToReplace = m.Groups[0].Value; - string fileName = m.Groups[1].Value; - string filePath = Path.Combine(partialPath, fileName); - if (File.Exists(filePath)) - { - content = content.Replace(tagToReplace, File.ReadAllText(filePath)); - } - } - m = m.NextMatch(); - } - return content; - } + + /// + /// Process the input for @@include tags and embeds the included content + /// into the output. + /// + /// content to be scanned for include tags + /// Directory containing the include files + /// String with @@include replaced with the actual content from the partial. + public static string IncludeProcessor(String content, string includePath) + { + Match m = includeRegex.Match(content); + while (m.Success) + { + if (m.Groups.Count > 1) + { + string tagToReplace = m.Groups[0].Value; + string fileName = m.Groups[1].Value; + string filePath = Path.Combine(includePath, fileName); + if (File.Exists(filePath)) + { + content = content.Replace(tagToReplace, File.ReadAllText(filePath)); + } + } + m = m.NextMatch(); + } + return content; + } } }