Browse Source

Corrections on #31 code, _partial=>Includes. Spaces=>Tabs, some clean up (minor)

pull/34/head
Frans Bouma 9 years ago
parent
commit
b35163b10e
2 changed files with 37 additions and 34 deletions
  1. +3
    -3
      src/DocNet/SimpleNavigationElement.cs
  2. +34
    -31
      src/DocNet/Utils.cs

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

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


+ 34
- 31
src/DocNet/Utils.cs View File

@@ -32,6 +32,13 @@ 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>
@@ -199,36 +206,32 @@ namespace Docnet
return Utils.MakeRelativePath(fromPath, toPath).Replace(@"\", @"/");
}

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

/// <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="partialPath">Directory containing the partials</param>
/// <returns>String with @@content replaced with the actual content from the partial.</returns>
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;
}

/// <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