Beispiel #1
0
        public static string Markup(
            string src,
            string path = null,
            IReadOnlyDictionary <string, AzureFileInfo> azureMarkdownFileInfoMapping = null,
            IReadOnlyDictionary <string, AzureVideoInfo> azureVideoInfoMapping       = null,
            IReadOnlyDictionary <string, AzureFileInfo> azureResourceFileInfoMapping = null)
        {
            var engine  = (MarkdownEngine)_builder.CreateEngine(_renderer);
            var context = engine.Context;

            if (path != null)
            {
                context = engine.Context.CreateContext(engine.Context.Variables.SetItem("path", path));
            }

            if (azureMarkdownFileInfoMapping != null && azureMarkdownFileInfoMapping.Count != 0)
            {
                context = context.CreateContext(context.Variables.SetItem("azureMarkdownFileInfoMapping", azureMarkdownFileInfoMapping));
            }

            if (azureVideoInfoMapping != null && azureVideoInfoMapping.Count != 0)
            {
                context = context.CreateContext(context.Variables.SetItem("azureVideoInfoMapping", azureVideoInfoMapping));
            }

            if (azureResourceFileInfoMapping != null && azureResourceFileInfoMapping.Count != 0)
            {
                context = context.CreateContext(context.Variables.SetItem("azureResourceFileInfoMapping", azureResourceFileInfoMapping));
            }

            return(engine.Mark(SourceInfo.Create(MarkdownEngine.Normalize(src), path), context));
        }
Beispiel #2
0
        private string GenerateYamlHeaderContent(IReadOnlyDictionary <string, string> properties, IReadOnlyDictionary <string, string> tags)
        {
            var propertiesSw = new StringWriter();

            YamlUtility.Serialize(propertiesSw, properties);
            var tagsSw = new StringWriter();

            YamlUtility.Serialize(tagsSw, tags);
            return(MarkdownEngine.Normalize(propertiesSw.ToString() + "\n" + tagsSw.ToString()));
        }
        public IMarkdownToken TryMatch(IMarkdownParser engine, ref string source)
        {
            var match = AzureIncludeRegex.Match(source);

            if (match.Length == 0)
            {
                return(null);
            }
            source = source.Substring(match.Length);

            // [!azure.include[title](path "optionalTitle")]
            // 1. Get include file path
            var path = match.Groups[2].Value;

            // 2. Get title
            var value = match.Groups[1].Value;
            var title = match.Groups[4].Value;

            if (!PathUtility.IsRelativePath(path))
            {
                Logger.LogWarning($"Azure inline include path {path} is not a relative path, can't expand it");
                return(new MarkdownTextToken(this, engine.Context, match.Value, match.Value));
            }

            object currentFilePath;

            if (!engine.Context.Variables.TryGetValue("path", out currentFilePath))
            {
                Logger.LogWarning($"Can't get path for the file that ref azure block include file, return MarkdownTextToken. Raw: {match.Value}");
                return(new MarkdownTextToken(this, engine.Context, match.Value, match.Value));
            }

            var includeFilePath = PathUtility.NormalizePath(Path.Combine(Path.GetDirectoryName(currentFilePath.ToString()), path));

            if (!File.Exists(includeFilePath))
            {
                Logger.LogWarning($"Can't get include file path {includeFilePath} in the file {currentFilePath}, return MarkdownTextToken. Raw: {match.Value}");
                return(new MarkdownTextToken(this, engine.Context, match.Value, match.Value));
            }

            return(new TwoPhaseBlockToken(this, engine.Context, match.Value, (p, t) =>
            {
                var blockTokens = p.Tokenize(MarkdownEngine.Normalize(File.ReadAllText(includeFilePath)));
                blockTokens = TokenHelper.ParseInlineToken(p, t.Rule, blockTokens, true);
                return new AzureIncludeBlockToken(t.Rule, t.Context, path, value, title, blockTokens, match.Groups[0].Value, match.Value);
            }));
        }
Beispiel #4
0
        public IMarkdownToken TryMatch(IMarkdownParser engine, IMarkdownParsingContext context)
        {
            var match = AzureIncludeRegex.Match(context.CurrentMarkdown);

            if (match.Length == 0)
            {
                return(null);
            }
            var sourceInfo = context.Consume(match.Length);

            // [!azure.include[title](path "optionalTitle")]
            // 1. Get include file path
            var path = match.Groups[2].Value;

            // 2. Get title
            var value = match.Groups[1].Value;
            var title = match.Groups[4].Value;

            if (!TypeForwardedToPathUtility.IsRelativePath(path))
            {
                Logger.LogWarning($"Azure inline include path {path} is not a relative path, can't expand it");
                return(new MarkdownTextToken(this, engine.Context, match.Value, sourceInfo));
            }

            // 3. Apply inline rules to the included content
            object currentFilePath;

            if (!engine.Context.Variables.TryGetValue("path", out currentFilePath))
            {
                Logger.LogWarning($"Can't get path for the file that ref azure inline include file, return MarkdownTextToken. Raw: {match.Value}");
                return(new MarkdownTextToken(this, engine.Context, match.Value, sourceInfo));
            }

            var includeFilePath = TypeForwardedToPathUtility.NormalizePath(Path.Combine(Path.GetDirectoryName(currentFilePath.ToString()), path));

            if (!File.Exists(includeFilePath))
            {
                Logger.LogWarning($"Can't get include file path {includeFilePath} in the file {currentFilePath}, return MarkdownTextToken. Raw: {match.Value}");
                return(new MarkdownTextToken(this, engine.Context, match.Value, sourceInfo));
            }

            return(new TwoPhaseBlockToken(this, engine.Context, sourceInfo, (p, t) =>
            {
                var inlineTokens = p.Tokenize(SourceInfo.Create(MarkdownEngine.Normalize(File.ReadAllText(includeFilePath)), includeFilePath));
                return new AzureIncludeInlineToken(t.Rule, t.Context, path, value, title, inlineTokens, match.Groups[0].Value, t.SourceInfo);
            }));
        }
Beispiel #5
0
        public IMarkdownToken TryMatch(IMarkdownParser parser, IMarkdownParsingContext context)
        {
            var match = AzureIncludeRegex.Match(context.CurrentMarkdown);

            if (match.Length == 0)
            {
                return(null);
            }
            var sourceInfo = context.Consume(match.Length);

            // [!azure.include[title](path "optionalTitle")]
            // 1. Get include file path
            var path = match.Groups[2].Value;

            // 2. Get title
            var value = match.Groups[1].Value;
            var title = match.Groups[4].Value;

            if (!PathUtility.IsRelativePath(path))
            {
                Logger.LogWarning($"Azure inline include path {path} is not a relative path, can't expand it");
                return(new MarkdownTextToken(this, parser.Context, match.Value, sourceInfo));
            }

            object currentFilePath;

            if (!parser.Context.Variables.TryGetValue("path", out currentFilePath))
            {
                Logger.LogWarning($"Can't get path for the file that ref azure block include file, return MarkdownTextToken. Raw: {match.Value}");
                return(new MarkdownTextToken(this, parser.Context, match.Value, sourceInfo));
            }

            var includeFilePath = PathUtility.NormalizePath(Path.Combine(Path.GetDirectoryName(currentFilePath.ToString()), path));

            if (!File.Exists(includeFilePath))
            {
                Logger.LogWarning($"Can't get include file path {includeFilePath} in the file {currentFilePath}, return MarkdownTextToken. Raw: {match.Value}");
                return(new MarkdownTextToken(this, parser.Context, match.Value, sourceInfo));
            }

            var blockTokens = parser.Tokenize(SourceInfo.Create(MarkdownEngine.Normalize(File.ReadAllText(includeFilePath)), includeFilePath));

            blockTokens = TokenHelper.CreateParagraghs(parser, this, blockTokens, true, sourceInfo);
            return(new AzureIncludeBlockToken(this, parser.Context, path, value, title, blockTokens, match.Groups[0].Value, sourceInfo));
        }