Browse Source

Merge branch 'FlexSearch-feature-include1'

Merge of PR #31
tags/0.13
Frans Bouma 10 years ago
parent
commit
eb6b1e36a2
2 changed files with 40 additions and 2 deletions
  1. +3
    -1
      src/DocNet/SimpleNavigationElement.cs
  2. +37
    -1
      src/DocNet/Utils.cs

+ 3
- 1
src/DocNet/SimpleNavigationElement.cs View File

@@ -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
{


+ 37
- 1
src/DocNet/Utils.cs View File

@@ -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
/// <summary>
/// Regex expression used to parse @@include(filename.html) tag.
/// </summary>
private static Regex includeRegex = new Regex(@"@@include\((.*)\)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
#endregion

/// <summary>
/// Converts the markdown to HTML.
/// </summary>
@@ -197,5 +205,33 @@ namespace Docnet
{
return Utils.MakeRelativePath(fromPath, toPath).Replace(@"\", @"/");
}
}


/// <summary>
/// Process the input for @@include tags and embeds the included content
/// into the output.
/// </summary>
/// <param name="content">content to be scanned for include tags</param>
/// <param name="includePath">Directory containing the include files</param>
/// <returns>String with @@include replaced with the actual content from the partial.</returns>
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;
}
}
}

Loading…
Cancel
Save