diff --git a/src/DocNet/SimpleNavigationElement.cs b/src/DocNet/SimpleNavigationElement.cs index 9fee609..eb59dc2 100644 --- a/src/DocNet/SimpleNavigationElement.cs +++ b/src/DocNet/SimpleNavigationElement.cs @@ -66,7 +66,9 @@ namespace Docnet if(File.Exists(sourceFile)) { this.MarkdownFromFile = File.ReadAllText(sourceFile); - content = Utils.ConvertMarkdownToHtml(this.MarkdownFromFile, 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 243c830..738cb1b 100644 --- a/src/DocNet/Utils.cs +++ b/src/DocNet/Utils.cs @@ -25,12 +25,20 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; 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. /// @@ -197,5 +205,33 @@ namespace Docnet { return Utils.MakeRelativePath(fromPath, toPath).Replace(@"\", @"/"); } - } + + + /// + /// 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; + } + } }