public MarkdownEscapeInlineToken(IMarkdownRule rule, IMarkdownContext context, string content, string rawMarkdown) { Rule = rule; Context = context; Content = content; RawMarkdown = rawMarkdown; }
public MarkdownEmInlineToken(IMarkdownRule rule, IMarkdownContext context, ImmutableArray <IMarkdownToken> content, string rawMarkdown) { Rule = rule; Context = context; Content = content; RawMarkdown = rawMarkdown; }
public DfmYamlHeaderBlockToken(IMarkdownRule rule, IMarkdownContext context, string content, string rawMarkdown) { Rule = rule; Context = context; Content = content; RawMarkdown = rawMarkdown; }
private string GenerateAzureVideoLink(IMarkdownContext context, string azureVideoId, string rawMarkdown, string line) { if (!context.Variables.TryGetValue("path", out object path)) { Logger.LogWarning("Can't get current file path. Skip video token rewriter."); return(azureVideoId); } if (!context.Variables.ContainsKey("azureVideoInfoMapping")) { Logger.LogWarning($"Can't find the whole azure video info mapping. Raw: {rawMarkdown}", null, path.ToString(), line); return(azureVideoId); } var azureVideoInfoMapping = (IReadOnlyDictionary <string, AzureVideoInfo>)context.Variables["azureVideoInfoMapping"]; if (azureVideoInfoMapping == null || !azureVideoInfoMapping.ContainsKey(azureVideoId)) { Logger.LogWarning($"Can't find video reference: {azureVideoId}. Raw: {rawMarkdown}", null, path.ToString(), line); return(azureVideoId); } var azureVideoInfo = azureVideoInfoMapping[azureVideoId]; return(azureVideoInfo.Link); }
public MarkdownBlockquoteBlockToken(IMarkdownRule rule, IMarkdownContext context, ImmutableArray <IMarkdownToken> tokens, string rawMarkdown) { Rule = rule; Context = context; Tokens = tokens; RawMarkdown = rawMarkdown; }
public DfmSectionBlockToken(IMarkdownRule rule, IMarkdownContext context, string attributes, string rawMarkdown) { Rule = rule; Context = context; Attributes = attributes; RawMarkdown = rawMarkdown; }
public StringBuffer Mark(SourceInfo sourceInfo, IMarkdownContext context) { var result = StringBuffer.Empty; var parser = Parser; if (context != null) { parser.SwitchContext(context); } var tokens = parser.Tokenize(sourceInfo.Copy(Preprocess(sourceInfo.Markdown))); var internalRewriteEngine = new MarkdownRewriteEngine( this, MarkdownTokenRewriterFactory.Loop( MarkdownTokenRewriterFactory.FromLambda <IMarkdownRewriteEngine, TwoPhaseBlockToken>( (e, t) => t.Extract(parser)), MaxExtractCount + 1)); tokens = internalRewriteEngine.Rewrite(tokens); var idTable = new Dictionary <string, int>(); var idRewriteEngine = new MarkdownRewriteEngine( this, MarkdownTokenRewriterFactory.FromLambda <IMarkdownRewriteEngine, MarkdownHeadingBlockToken>( (e, t) => t.RewriteId(idTable))); tokens = idRewriteEngine.Rewrite(tokens); tokens = RewriteEngine.Rewrite(tokens); var renderer = Renderer; foreach (var token in tokens) { result += renderer.Render(token); } return(result); }
public LuceneNoteBlockToken(IMarkdownRule rule, IMarkdownContext context, string label, SourceInfo sourceInfo) { Rule = rule; Context = context; Label = label; SourceInfo = sourceInfo; }
public MarkdownCodeInlineToken(IMarkdownRule rule, IMarkdownContext context, string content, SourceInfo sourceInfo) { Rule = rule; Context = context; Content = content; SourceInfo = sourceInfo; }
public MarkdownParagraphBlockToken(IMarkdownRule rule, IMarkdownContext context, InlineContent inlineTokens, SourceInfo sourceInfo) { Rule = rule; Context = context; InlineTokens = inlineTokens; SourceInfo = sourceInfo; }
public GfmDelInlineToken(IMarkdownRule rule, IMarkdownContext context, ImmutableArray <IMarkdownToken> content, SourceInfo sourceInfo) { Rule = rule; Context = context; Content = content; SourceInfo = sourceInfo; }
private string GenerateAzureVideoLink(IMarkdownContext context, string azureVideoId, string rawMarkdown) { object path; if (!context.Variables.TryGetValue("path", out path)) { Logger.LogWarning("Can't get current file path. Skip video token rewriter."); return(azureVideoId); } if (!context.Variables.ContainsKey("azureVideoInfoMapping")) { Logger.LogWarning($"Can't fild the whole azure video info mapping. Current processing file: {path}, Raw: {rawMarkdown}"); return(azureVideoId); } var azureVideoInfoMapping = (IReadOnlyDictionary <string, AzureVideoInfo>)context.Variables["azureVideoInfoMapping"]; if (azureVideoInfoMapping == null || !azureVideoInfoMapping.ContainsKey(azureVideoId)) { Logger.LogWarning($"Can't fild azure video info mapping for file: {path}. Raw: {rawMarkdown}"); return(azureVideoId); } var azureVideoInfo = azureVideoInfoMapping[azureVideoId]; return(azureVideoInfo.Link); }
public DfmSectionBlockToken(IMarkdownRule rule, IMarkdownContext context, string attributes, SourceInfo sourceInfo) { Rule = rule; Context = context; Attributes = attributes; SourceInfo = sourceInfo; }
public DfmVideoBlockToken(IMarkdownRule rule, IMarkdownContext context, string link, SourceInfo sourceInfo) { Rule = rule; Context = context; Link = link; SourceInfo = sourceInfo; }
public AzureVideoBlockToken(IMarkdownRule rule, IMarkdownContext context, string videoId, string rawMarkdown) { Rule = rule; Context = context; VideoId = videoId; RawMarkdown = rawMarkdown; }
public SDNSBlockToken(IMarkdownRule rule, IMarkdownContext context, SourceInfo sourceInfo, string text) { Rule = rule; Context = context; SourceInfo = sourceInfo; Text = text; }
public AzureVideoBlockToken(IMarkdownRule rule, IMarkdownContext context, string videoId, SourceInfo sourceInfo) { Rule = rule; Context = context; VideoId = videoId; SourceInfo = sourceInfo; }
public MarkdownTextToken(IMarkdownRule rule, IMarkdownContext context, string content, SourceInfo sourceInfo) { Rule = rule; Context = context; Content = content; SourceInfo = sourceInfo; }
public DfmTabContentBlockToken(IMarkdownRule rule, IMarkdownContext context, ImmutableArray <IMarkdownToken> content, SourceInfo sourceInfo) { Rule = rule; Context = context; Content = content; SourceInfo = sourceInfo; }
public MarkdownHtmlBlockToken(IMarkdownRule rule, IMarkdownContext context, InlineContent content, string rawMarkdown) { Rule = rule; Context = context; Content = content; RawMarkdown = rawMarkdown; }
private IMarkdownContext SwitchContextCore(IMarkdownContext context) { var result = Context; Context = context; return(result); }
public StringBuffer Mark(string markdown, IMarkdownContext context) { var result = StringBuffer.Empty; var parser = Parser; if (context != null) { parser.SwitchContext(context); } var tokens = parser.Tokenize(Preprocess(markdown)); var internalRewriteEngine = new MarkdownRewriteEngine( this, MarkdownTokenRewriterFactory.FromLambda <IMarkdownRewriteEngine, TwoPhaseBlockToken>( (e, t) => t.Extract(parser))); tokens = internalRewriteEngine.Rewrite(tokens); tokens = RewriteEngine.Rewrite(tokens); var renderer = Renderer; foreach (var token in tokens) { result += renderer.Render(token); } return(result); }
private StringBuffer RenderAzureIncludeToken(AzureIncludeBasicToken token, IMarkdownContext context) { StringBuffer content = StringBuffer.Empty; object path; if (!context.Variables.TryGetValue("path", out path)) { Logger.LogWarning($"Can't get path for the file that ref azure include file {token.Src}. Raw: {token.RawMarkdown}"); return(null); } if (PathUtility.IsRelativePath(token.Src)) { var includeFilePath = Path.Combine(Path.GetDirectoryName(path.ToString()), token.Src); if (!File.Exists(includeFilePath)) { Logger.LogWarning($"Can't get include file in path {includeFilePath}. Raw: {token.RawMarkdown}"); return(null); } // TODO: We should handle Azure syntax in the include file. Such as Azure Selector content += File.ReadAllText(includeFilePath); } else { Logger.LogWarning($"include path {token.Src} is not a relative path, can't expand it"); return(null); } return(content); }
public MarkdownTextToken(IMarkdownRule rule, IMarkdownContext context, string content, string rawMarkdown) { Rule = rule; Context = context; Content = content; RawMarkdown = rawMarkdown; }
public MarkdownParagraphBlockToken(IMarkdownRule rule, IMarkdownContext context, InlineContent inlineTokens, string rawMarkdown) { Rule = rule; Context = context; InlineTokens = inlineTokens; RawMarkdown = rawMarkdown; }
private StringBuffer RenderAzureIncludeToken(AzureIncludeBasicToken token, IMarkdownContext context) { StringBuffer content = StringBuffer.Empty; object path; if (!context.Variables.TryGetValue("path", out path)) { Logger.LogWarning($"Can't get path for the file that ref azure include file {token.Src}. Raw: {token.RawMarkdown}"); return null; } if (PathUtility.IsRelativePath(token.Src)) { var includeFilePath = Path.Combine(Path.GetDirectoryName(path.ToString()), token.Src); if (!File.Exists(includeFilePath)) { Logger.LogWarning($"Can't get include file in path {includeFilePath}. Raw: {token.RawMarkdown}"); return null; } // TODO: We should handle Azure syntax in the include file. Such as Azure Selector content += File.ReadAllText(includeFilePath); } else { Logger.LogWarning($"include path {token.Src} is not a relative path, can't expand it"); return null; } return content; }
public DfmTabTitleBlockToken(IMarkdownRule rule, IMarkdownContext context, InlineContent content, SourceInfo sourceInfo) { Rule = rule; Context = context; Content = content; SourceInfo = sourceInfo; }
public DfmYamlHeaderBlockToken(IMarkdownRule rule, IMarkdownContext context, string content, SourceInfo sourceInfo) { Rule = rule; Context = context; Content = content; SourceInfo = sourceInfo; }
public MarkdownNonParagraphBlockToken(IMarkdownRule rule, IMarkdownContext context, InlineContent content, SourceInfo sourceInfo) { Rule = rule; Context = context; Content = content; SourceInfo = sourceInfo; }
public MarkdownBlockquoteBlockToken(IMarkdownRule rule, IMarkdownContext context, ImmutableArray <IMarkdownToken> tokens, SourceInfo sourceInfo) { Rule = rule; Context = context; Tokens = tokens; SourceInfo = sourceInfo; }
public StringBuffer Mark(SourceInfo sourceInfo, IMarkdownContext context) { var result = StringBuffer.Empty; var parser = Parser; if (context != null) { parser.SwitchContext(context); } var preprocessedSourceInfo = sourceInfo.Copy(Preprocess(sourceInfo.Markdown)); var tokens = parser.Tokenize(preprocessedSourceInfo); if (parser.Context is MarkdownBlockContext) { tokens = TokenHelper.CreateParagraghs( parser, MarkdownParagraphBlockRule.Instance, tokens, true, preprocessedSourceInfo); } // resolve two phase token tokens = RewriteTokens( tokens, sourceInfo.File, new MarkdownRewriteEngine( this, MarkdownTokenRewriterFactory.Loop( MarkdownTokenRewriterFactory.FromLambda<IMarkdownRewriteEngine, TwoPhaseBlockToken>( (e, t) => t.Extract(parser)), MaxExtractCount + 1))); // fix id. var idTable = new Dictionary<string, int>(); tokens = RewriteTokens( tokens, sourceInfo.File, new MarkdownRewriteEngine( this, MarkdownTokenRewriterFactory.FromLambda<IMarkdownRewriteEngine, MarkdownHeadingBlockToken>( (e, t) => t.RewriteId(idTable)))); // customized rewriter. tokens = RewriteTokens( tokens, sourceInfo.File, RewriteEngine); if (TokenTreeValidator != null) { TokenTreeValidator.Validate(tokens); } var renderer = Renderer; foreach (var token in tokens) { result += renderer.Render(token); } return result; }
public static IMarkdownContext SetDependency(this IMarkdownContext context, HashSet <string> dependency) { if (context == null) { throw new ArgumentNullException(nameof(context)); } return(context.CreateContext(context.Variables.SetItem(DependencyKey, dependency))); }
protected MarkdownEngine(IMarkdownContext context, IMarkdownTokenRewriter rewriter, object renderer, Options options, Dictionary <string, LinkObj> links) { Context = context; Rewriter = rewriter ?? MarkdownTokenRewriterFactory.Null; RendererImpl = renderer; Options = options; Links = links; }
public IMarkdownContext SwitchContext(IMarkdownContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } return SwitchContextCore(context); }
public static IReadOnlyList <string> GetFallbackFolders(this IMarkdownContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } return((IReadOnlyList <string>)(context.Variables[FallbackFoldersKey]) ?? new List <string>()); }
public AzureSelectorBlockToken(IMarkdownRule rule, IMarkdownContext context, string selectorType, string selectorConditions, SourceInfo sourceInfo) { Rule = rule; Context = context; SelectorType = selectorType; SelectorConditions = selectorConditions; SourceInfo = sourceInfo; }
public GfmEmojiInlineToken(IMarkdownRule rule, IMarkdownContext context, string shortCode, string emoji, SourceInfo sourceInfo) { Rule = rule; Context = context; ShortCode = shortCode; Emoji = emoji; SourceInfo = sourceInfo; }
public DfmNoteBlockToken(IMarkdownRule rule, IMarkdownContext context, string noteType, string content, SourceInfo sourceInfo) { Rule = rule; Context = context; Content = content; NoteType = noteType; SourceInfo = sourceInfo; }
public MarkdownCodeBlockToken(IMarkdownRule rule, IMarkdownContext context, string code, string rawMarkdown, string lang = null) { Rule = rule; Context = context; Code = code; Lang = lang; RawMarkdown = rawMarkdown; }
public MarkdownCodeBlockToken(IMarkdownRule rule, IMarkdownContext context, string code, string lang, SourceInfo sourceInfo) { Rule = rule; Context = context; Code = code; Lang = lang; SourceInfo = sourceInfo; }
protected MarkdownEngine(IMarkdownContext context, IMarkdownTokenRewriter rewriter, object renderer, Options options, Dictionary<string, LinkObj> links) { Context = context; Rewriter = rewriter ?? MarkdownTokenRewriterFactory.Null; RendererImpl = renderer; Options = options; Links = links; }
public DfmNoteBlockToken(IMarkdownRule rule, IMarkdownContext context, string noteType, string content, string rawMarkdown) { Rule = rule; Context = context; Content = content; RawMarkdown = rawMarkdown; NoteType = noteType; }
protected AzureMigrationIncludeBasicToken(IMarkdownRule rule, IMarkdownContext context, string name, string src, string title, SourceInfo sourceInfo) { Rule = rule; Context = context; Name = name; Src = src; Title = title; SourceInfo = sourceInfo; }
private StringBuffer RenderAzureIncludeToken(IMarkdownRenderer render, AzureIncludeBasicToken token, IMarkdownContext context) { StringBuffer content = StringBuffer.Empty; foreach(var t in token.Tokens) { content += render.Render(t); } return content; }
public DfmXrefInlineToken(IMarkdownRule rule, IMarkdownContext context, string href, string name, string title, string rawMarkdown) { Rule = rule; Context = context; Href = href; Name = name; Title = title; RawMarkdown = rawMarkdown; }
public MarkdownImageInlineToken(IMarkdownRule rule, IMarkdownContext context, string href, string title, string text, string rawMarkdown) { Rule = rule; Context = context; Href = href; Title = title; Text = text; RawMarkdown = rawMarkdown; }
/// <summary> /// Get file path with fallback /// </summary> /// <param name="relativePath">original relative path in markdown.</param> /// <param name="context">markdown context</param> /// <returns>item1: acutal file path. item: true if it hit fallback file. Otherwise false</returns> public static Tuple<string, bool> GetFilePathWithFallback(string relativePath, IMarkdownContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (relativePath == null) { throw new ArgumentNullException(nameof(relativePath)); throw new FileNotFoundException($"Couldn't resolve path {relativePath}."); } // var currentFileFolder = Path.Combine(context.GetBaseFolder(), Path.Combine(context.GetFilePathStack().Select(path => Path.GetDirectoryName(path)).ToArray())); // var originalFilePath = Path.Combine(context.GetBaseFolder(), orginalRelativePath); var filePathToDocset = relativePath; string parentFileDirectoryToDocset = context.GetBaseFolder(); var parents = context.GetFilePathStack(); if(parents != null) { var parent = parents.Peek(); filePathToDocset = (RelativePath)parent + (RelativePath)filePathToDocset; parentFileDirectoryToDocset = Path.GetDirectoryName(Path.Combine(context.GetBaseFolder(), parent)); } var originalFilePath = Path.Combine(context.GetBaseFolder(), filePathToDocset); var actualFilePath = originalFilePath; bool hitFallback = false; if (!File.Exists(originalFilePath)) { var fallbackFolders = context.GetFallbackFolders(); foreach (var folder in fallbackFolders) { var fallbackFilePath = Path.Combine(folder, filePathToDocset); var fallbackFileRelativePath = PathUtility.MakeRelativePath(parentFileDirectoryToDocset, fallbackFilePath); context.ReportDependency(fallbackFileRelativePath); // All the high priority fallback files should be reported to the dependency. if (File.Exists(fallbackFilePath)) { actualFilePath = fallbackFilePath; hitFallback = true; break; } } if (!hitFallback) { if (fallbackFolders.Count > 0) { throw new FileNotFoundException($"Couldn't find file {filePathToDocset}. Fallback folders: {string.Join(",", fallbackFolders)}", filePathToDocset); } throw new FileNotFoundException($"Couldn't find file {filePathToDocset}.", originalFilePath); } } return Tuple.Create(actualFilePath, hitFallback); }
private string LoadCore(IMarkdownRenderer adapter, string currentPath, string raw, SourceInfo sourceInfo, IMarkdownContext context, DfmEngine engine) { try { if (!PathUtility.IsRelativePath(currentPath)) { return GenerateErrorNodeWithCommentWrapper("INCLUDE", $"Absolute path \"{currentPath}\" is not supported.", raw, sourceInfo); } // Always report original include file dependency var originalRelativePath = currentPath; context.ReportDependency(currentPath); var parents = context.GetFilePathStack(); string parent = string.Empty; if (parents == null) parents = ImmutableStack<string>.Empty; // Update currentPath to be referencing to sourcePath else if (!parents.IsEmpty) { parent = parents.Peek(); currentPath = ((RelativePath)currentPath).BasedOn((RelativePath)parent); } if (parents.Contains(currentPath, FilePathComparer.OSPlatformSensitiveComparer)) { return GenerateErrorNodeWithCommentWrapper("INCLUDE", $"Unable to resolve {raw}: Circular dependency found in \"{parent}\"", raw, sourceInfo); } // Add current file path to chain when entering recursion parents = parents.Push(currentPath); string result; HashSet<string> dependency; if (!_dependencyCache.TryGetValue(currentPath, out dependency) || !_cache.TryGet(currentPath, out result)) { var filePathWithStatus = DfmFallbackHelper.GetFilePathWithFallback(originalRelativePath, context); var src = File.ReadAllText(filePathWithStatus.Item1); dependency = new HashSet<string>(); src = engine.InternalMarkup(src, context.SetFilePathStack(parents).SetDependency(dependency).SetIsInclude()); result = UpdateToHrefFromWorkingFolder(src, currentPath); result = GenerateNodeWithCommentWrapper("INCLUDE", $"Include content from \"{currentPath}\"", result); _cache.Add(currentPath, result); _dependencyCache[currentPath] = dependency; } context.ReportDependency( from d in dependency select (string)((RelativePath)currentPath + (RelativePath)d - (RelativePath)parent)); return result; } catch (Exception e) { return GenerateErrorNodeWithCommentWrapper("INCLUDE", $"Unable to resolve {raw}:{e.Message}", raw, sourceInfo); } }
public DfmXrefInlineToken(IMarkdownRule rule, IMarkdownContext context, string href, string name, string title, bool throwIfNotResolved, string rawMarkdown) { Rule = rule; Context = context; Href = href; Name = name; Title = title; ThrowIfNotResolved = throwIfNotResolved; RawMarkdown = rawMarkdown; }
public DfmIncludeInlineToken(IMarkdownRule rule, IMarkdownContext context, string src, string name, string title, string raw, SourceInfo sourceInfo) { Rule = rule; Context = context; Src = src; Name = name; Title = title; Raw = raw; SourceInfo = sourceInfo; }
public AzureIncludeInlineToken(IMarkdownRule rule, IMarkdownContext context, string src, string name, string title, string raw, string rawMarkdown) { Rule = rule; Context = context; Src = src; Name = name; Title = title; Raw = raw; RawMarkdown = rawMarkdown; }
public DfmFencesToken(IMarkdownRule rule, IMarkdownContext context, string name, string path, SourceInfo sourceInfo, string lang, string title, IDfmFencesBlockPathQueryOption pathQueryOption) { Rule = rule; Context = context; Path = path; Lang = lang; Name = name; Title = title; PathQueryOption = pathQueryOption; SourceInfo = sourceInfo; }
public TwoPhaseBlockToken( IMarkdownRule rule, IMarkdownContext context, string rawMarkdown, Func<IMarkdownParser, TwoPhaseBlockToken, IMarkdownToken> extractor) { Rule = rule; Context = context; RawMarkdown = rawMarkdown; _extractor = extractor; }
public DfmFencesBlockToken(IMarkdownRule rule, IMarkdownContext context, string name, string path, string rawMarkdown, string lang = null, string title = null, DfmFencesBlockPathQueryOption pathQueryOption = null) { Rule = rule; Context = context; Path = path; Lang = lang; Name = name; Title = title; PathQueryOption = pathQueryOption; RawMarkdown = rawMarkdown; }
public MarkdownImageInlineToken(IMarkdownRule rule, IMarkdownContext context, string href, string title, string text, SourceInfo sourceInfo, MarkdownLinkType linkType, string refId) { Rule = rule; Context = context; Href = href; Title = title; Text = text; SourceInfo = sourceInfo; LinkType = linkType; RefId = refId; }