private string ParseInLineVariableOrMetadata(Match match, FileInfo currentFile, FileInfo originalScope, TransformationData data, EMDocument doc, Stack <Tuple <string, string> > visitedVariables)
        {
            var    pathToLinkedFile         = match.Groups["path"].Value;
            var    variableName             = match.Groups["variableName"].Value.ToLower();
            var    originalString           = match.Value;
            string relativePathToLinkedFile = null;

            var outString       = "";
            var isProblem       = false;
            var changedLanguage = false;

            var errorId = 0;
            var OnErrorStringToUseForMatch = originalString;

            //ignore if the value is STOPPUBLISH STARTPUBLISH
            if (variableName.Equals("STOPPUBLISH") || variableName.Equals("STARTPUBLISH") || originalString.ToUpper() == "%ROOT%" || VariableManager.IsKeywordToSkip(originalString))
            {
                return(originalString);
            }
            else
            {
                if (pathToLinkedFile.Equals("doxygen"))
                {
                    var excerptName = ("doxygen:" + match.Groups["variableName"].Value).Replace(':', 'x');

                    if (!doc.Excerpts.Exists(excerptName))
                    {
                        var content =
                            DoxygenHelper.GetSymbolDescriptionAndCatchExceptionIntoMarkdownErrors(
                                match.Groups["variableName"].Value,
                                match.Value,
                                DoxygenHelper.DescriptionType.Full,
                                data,
                                data.Markdown,
                                data.FoundDoxygenSymbols).Trim();

                        content = Normalizer.Normalize(content, null);

                        doc.Excerpts.AddExcerpt(
                            excerptName, new EMExcerpt(doc, 0, 0, content, data, excerptName == ""));
                    }

                    return(string.Format("[INCLUDE:#{0}]", excerptName));
                }
                if (pathToLinkedFile.Equals("orig"))
                {
                    currentFile = originalScope;
                    relativePathToLinkedFile = data.CurrentFolderDetails.CurrentFolderFromMarkdownAsTopLeaf;
                }
                else if (!String.IsNullOrWhiteSpace(pathToLinkedFile))
                {
                    // Link other file and get metadata from there.
                    var languageForFile = data.CurrentFolderDetails.Language;
                    relativePathToLinkedFile = pathToLinkedFile;

                    var linkedFileDir = new DirectoryInfo(Path.Combine(Path.Combine(data.CurrentFolderDetails.AbsoluteMarkdownPath, pathToLinkedFile)));

                    if (!linkedFileDir.Exists || linkedFileDir.GetFiles(string.Format("*.{0}.udn", data.CurrentFolderDetails.Language)).Length == 0)
                    {
                        // if this is not an INT file check for the INT version.
                        if (data.CurrentFolderDetails.Language != "INT")
                        {
                            if (!linkedFileDir.Exists || linkedFileDir.GetFiles("*.INT.udn").Length == 0)
                            {
                                errorId = data.ErrorList.Count;
                                data.ErrorList.Add(
                                    Markdown.GenerateError(
                                        Language.Message(
                                            "BadLinkOrMissingMarkdownFileAndNoINTFile", pathToLinkedFile, variableName),
                                        MessageClass.Error,
                                        Markdown.Unescape(OnErrorStringToUseForMatch),
                                        errorId,
                                        data));

                                isProblem = true;
                            }
                            else
                            {
                                // Found int file
                                languageForFile = "INT";

                                // Raise info so that now we are allowing missing linked files to still allow processing of the file if INT file is there
                                errorId = data.ErrorList.Count;
                                data.ErrorList.Add(
                                    Markdown.GenerateError(
                                        Language.Message(
                                            "BadLinkOrMissingMarkdownFileINTUsed", pathToLinkedFile, variableName),
                                        MessageClass.Info,
                                        Markdown.Unescape(OnErrorStringToUseForMatch),
                                        errorId,
                                        data));

                                isProblem = true;

                                changedLanguage = true;
                            }
                        }
                        else
                        {
                            errorId = data.ErrorList.Count;
                            data.ErrorList.Add(
                                Markdown.GenerateError(
                                    Language.Message("BadLinkOrMissingMarkdownFile", pathToLinkedFile, variableName),
                                    MessageClass.Error,
                                    Markdown.Unescape(OnErrorStringToUseForMatch),
                                    errorId,
                                    data));

                            isProblem = true;
                            outString = OnErrorStringToUseForMatch;
                        }
                    }

                    if (linkedFileDir.Exists && linkedFileDir.GetFiles(string.Format("*.{0}.udn", languageForFile)).Length > 0)
                    {
                        currentFile = linkedFileDir.GetFiles(string.Format("*.{0}.udn", languageForFile))[0];
                    }
                }

                // Cycle detection mechanism. First check if there was request for that variable in the visited stack.
                var currentVisitedVariableTuple = new Tuple <string, string>(currentFile.FullName, variableName);
                if (visitedVariables != null && visitedVariables.Contains(currentVisitedVariableTuple))
                {
                    // cycle detected
                    visitedVariables.Push(currentVisitedVariableTuple);
                    string visitedVariablesMessage = string.Join(", ", visitedVariables.Select(
                                                                     (v) =>
                    {
                        return(string.Format("[{0}, {1}]", v.Item1, v.Item2));
                    }));
                    visitedVariables.Pop();

                    data.ErrorList.Add(
                        Markdown.GenerateError(Language.Message("CycleDetectedInVariableRefs", visitedVariablesMessage), MessageClass.Error,
                                               "", data.ErrorList.Count, data));

                    return("");
                }

                if (!data.ProcessedDocumentCache.TryGetLinkedFileVariable(currentFile, variableName, out outString))
                {
                    if (doc.PerformStrictConversion())
                    {
                        //error
                        errorId = data.ErrorList.Count;
                        data.ErrorList.Add(
                            Markdown.GenerateError(
                                Language.Message("VariableOrMetadataNotFoundInFile", variableName, currentFile.FullName),
                                MessageClass.Error,
                                OnErrorStringToUseForMatch,
                                errorId,
                                data));

                        isProblem = true;
                    }
                    outString = OnErrorStringToUseForMatch.Replace("%", "&#37;");
                }
                else
                {
                    // If there was no request for this variable then push it.
                    visitedVariables.Push(currentVisitedVariableTuple);

                    outString = InLineVariableOrMetadata.Replace(
                        outString,
                        everyMatch =>
                        ParseInLineVariableOrMetadata(everyMatch, currentFile, originalScope, data, doc, visitedVariables));

                    // After parsing inner string pop visited variable from the stack.
                    visitedVariables.Pop();
                }

                if (changedLanguage)
                {
                    //If we had to replace the language with INT then update the linkText to include link to image of flag
                    outString += Templates.ImageFrame.Render(
                        Hash.FromAnonymousObject(
                            new
                    {
                        imageClass = "languageinline",
                        imagePath  = Path.Combine(
                            data.CurrentFolderDetails.RelativeHTMLPath,
                            "Include", "Images", "INT_flag.jpg")
                    }));
                }
            }

            if (data.Markdown.ThisIsPreview && isProblem)
            {
                return(Templates.ErrorHighlight.Render(
                           Hash.FromAnonymousObject(
                               new
                {
                    errorId = errorId,
                    errorText = outString
                })));
            }

            return(outString);
        }