protected override void Write(HtmlRenderer renderer, InclusionInline inclusion) { if (string.IsNullOrEmpty(inclusion.Context.IncludedFilePath)) { Logger.LogError("file path can't be empty or null in IncludeFile"); renderer.Write(inclusion.Context.GetRaw()); return; } if (!PathUtility.IsRelativePath(inclusion.Context.IncludedFilePath)) { string tag = "ERROR INCLUDE"; string message = $"Unable to resolve {inclusion.Context.GetRaw()}: Absolute path \"{inclusion.Context.IncludedFilePath}\" is not supported."; ExtensionsHelper.GenerateNodeWithCommentWrapper(renderer, tag, message, inclusion.Context.GetRaw(), inclusion.Line); return; } var currentFilePath = ((RelativePath)_context.FilePath).GetPathFromWorkingFolder(); var includeFilePath = ((RelativePath)inclusion.Context.IncludedFilePath).BasedOn(currentFilePath); var filePath = Path.Combine(_context.BasePath, includeFilePath.RemoveWorkingFolder()); if (!File.Exists(filePath)) { Logger.LogWarning($"Can't find {includeFilePath}."); renderer.Write(inclusion.Context.GetRaw()); return; } var parents = _context.InclusionSet; if (parents != null && parents.Contains(includeFilePath)) { string tag = "ERROR INCLUDE"; string message = $"Unable to resolve {inclusion.Context.GetRaw()}: Circular dependency found in \"{_context.FilePath}\""; ExtensionsHelper.GenerateNodeWithCommentWrapper(renderer, tag, message, inclusion.Context.GetRaw(), inclusion.Line); return; } var content = File.ReadAllText(filePath); var context = new MarkdownContextBuilder() .WithContext(_context) .WithFilePath(includeFilePath.RemoveWorkingFolder()) .WithContent(content) .WithIsInline(true) .WithAddingIncludedFile(currentFilePath) .Build(); _engine.ReportDependency(includeFilePath); // Do not need to check if content is a single paragragh // context.IsInline = true will force it into a single paragragh and render with no <p></p> var result = _engine.Markup(context, _parameters); renderer.Write(result); }
protected override void Write(HtmlRenderer renderer, InclusionBlock inclusion) { if (string.IsNullOrEmpty(inclusion.Context.IncludedFilePath)) { Logger.LogError("file path can't be empty or null in IncludeFile"); renderer.Write(inclusion.Context.GetRaw()); return; } if (!PathUtility.IsRelativePath(inclusion.Context.IncludedFilePath)) { var tag = "ERROR INCLUDE"; var message = $"Unable to resolve {inclusion.Context.GetRaw()}: Absolute path \"{inclusion.Context.IncludedFilePath}\" is not supported."; ExtensionsHelper.GenerateNodeWithCommentWrapper(renderer, tag, message, inclusion.Context.GetRaw(), inclusion.Line); return; } var currentFilePath = ((RelativePath)_context.FilePath).GetPathFromWorkingFolder(); var includedFilePath = ((RelativePath)inclusion.Context.IncludedFilePath).BasedOn(currentFilePath); if (!EnvironmentContext.FileAbstractLayer.Exists(includedFilePath)) { Logger.LogWarning($"Can't find {includedFilePath}."); renderer.Write(inclusion.Context.GetRaw()); return; } var parents = _context.InclusionSet; if (parents != null && parents.Contains(includedFilePath)) { string tag = "ERROR INCLUDE"; string message = $"Unable to resolve {inclusion.Context.GetRaw()}: Circular dependency found in \"{_context.FilePath}\""; ExtensionsHelper.GenerateNodeWithCommentWrapper(renderer, tag, message, inclusion.Context.GetRaw(), inclusion.Line); return; } var content = EnvironmentContext.FileAbstractLayer.ReadAllText(includedFilePath); var context = new MarkdownContextBuilder() .WithContext(_context) .WithFilePath(includedFilePath.RemoveWorkingFolder()) .WithContent(content) .WithAddingIncludedFile(currentFilePath) .Build(); _engine.ReportDependency(includedFilePath); var result = _engine.Markup(context, _parameters); result = SkipYamlHeader(result); renderer.Write(result); }