From 8e4334d2db16b72701434b173817637842df49d5 Mon Sep 17 00:00:00 2001 From: Seemant Rajvanshi Date: Fri, 4 Mar 2016 01:48:21 +0000 Subject: [PATCH 1/3] Do not encode targetUrl as it creates an issue when the home url contain a '\' --- src/DocNet/NavigatedPath.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DocNet/NavigatedPath.cs b/src/DocNet/NavigatedPath.cs index b2c53df..d2e51f6 100644 --- a/src/DocNet/NavigatedPath.cs +++ b/src/DocNet/NavigatedPath.cs @@ -52,7 +52,7 @@ public string CreateBreadCrumbsHTML(string relativePathToRoot) } else { - fragments.Add(string.Format("
  • {2}
  • ", relativePathToRoot, HttpUtility.UrlEncode(targetURL), element.Name)); + fragments.Add(string.Format("
  • {2}
  • ", relativePathToRoot, targetURL, element.Name)); } } return string.Format("{1}", string.Join(" / ", fragments.ToArray()), Environment.NewLine); From 2d54eb3ed233e80306629176655ba9eb09b4ef4e Mon Sep 17 00:00:00 2001 From: Seemant Rajvanshi Date: Fri, 4 Mar 2016 01:50:25 +0000 Subject: [PATCH 2/3] Use .html as extension for the generated files instead of htm --- src/DocNet/SimpleNavigationElement.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DocNet/SimpleNavigationElement.cs b/src/DocNet/SimpleNavigationElement.cs index 2de247b..d3c0edc 100644 --- a/src/DocNet/SimpleNavigationElement.cs +++ b/src/DocNet/SimpleNavigationElement.cs @@ -210,7 +210,7 @@ public override string TargetURL _targetURLForHTML = (this.Value ?? string.Empty); if(_targetURLForHTML.ToLowerInvariant().EndsWith(".md")) { - _targetURLForHTML = _targetURLForHTML.Substring(0, _targetURLForHTML.Length-3) + ".htm"; + _targetURLForHTML = _targetURLForHTML.Substring(0, _targetURLForHTML.Length-3) + ".html"; } _targetURLForHTML = _targetURLForHTML.Replace("\\", "/"); } From 27d05b728814e3e5d8c4d3e2a11ab5b4f1024b41 Mon Sep 17 00:00:00 2001 From: Seemant Rajvanshi Date: Fri, 4 Mar 2016 23:40:26 +0000 Subject: [PATCH 3/3] Added support for @@include tag which will allow embedding html files from the '_partial' folder --- src/DocNet/SimpleNavigationElement.cs | 9 ++++--- src/DocNet/Utils.cs | 35 ++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/DocNet/SimpleNavigationElement.cs b/src/DocNet/SimpleNavigationElement.cs index d3c0edc..5d0b0b8 100644 --- a/src/DocNet/SimpleNavigationElement.cs +++ b/src/DocNet/SimpleNavigationElement.cs @@ -108,9 +108,12 @@ public override void GenerateOutput(Config activeConfig, NavigatedPath activePat sb.Replace("{{Breadcrumbs}}", activePath.CreateBreadCrumbsHTML(relativePathToRoot)); sb.Replace("{{ToC}}", activePath.CreateToCHTML(relativePathToRoot)); sb.Replace("{{ExtraScript}}", (this.ExtraScriptProducerFunc == null) ? string.Empty : this.ExtraScriptProducerFunc(this)); - - // the last action has to be replacing the content marker, so markers in the content which we have in the template as well aren't replaced - sb.Replace("{{Content}}", content); + + // Check if the content contains @@include tag + content = Utils.IncludeProcessor(content, Path.Combine(activeConfig.Source, "_partials")); + + // the last action has to be replacing the content marker, so markers in the content which we have in the template as well aren't replaced + sb.Replace("{{Content}}", content); Utils.CreateFoldersIfRequired(destinationFile); File.WriteAllText(destinationFile, sb.ToString()); if(!this.IsIndexElement) diff --git a/src/DocNet/Utils.cs b/src/DocNet/Utils.cs index 492f128..f45593f 100644 --- a/src/DocNet/Utils.cs +++ b/src/DocNet/Utils.cs @@ -25,6 +25,7 @@ using System.IO; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; namespace Docnet @@ -184,5 +185,37 @@ public static string MakeRelativePath(string fromPath, string toPath) return relativePath; } - } + + /// + /// 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. + /// + /// + /// + /// + 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; + } + } }