Пример #1
0
        public void ConvertDoc(string inputDoc, string rootOutputDirectory)
        {
            var outputDir  = GetOutputDirectory(inputDoc, rootOutputDirectory);
            var outputFile = Path.Combine(outputDir, GetOuputFilename(inputDoc));

            if (!Directory.Exists(outputDir))
            {
                Console.WriteLine("Output Directory Doesn't Exist: '" + outputDir + "'");
                return;
            }
            if (!File.Exists(inputDoc))
            {
                Console.WriteLine("Input File Doesn't Exist: '" + inputDoc + "'");
                return;
            }

            var converter = new Html2Markdown.Converter();
            var markdown  = converter.ConvertFile(inputDoc);

            markdown = ReplaceCodeLinks(markdown);
            markdown = ReplaceRepoLinks(markdown);

            // Remove <doctype>
            markdown = DocType.Replace(markdown, string.Empty);

            File.WriteAllText(outputFile, markdown, Encoding.UTF8);
        }
Пример #2
0
        public void ConvertDoc(string inputDoc, string rootOutputDirectory)
        {
            var outputDir  = GetOutputDirectory(inputDoc, rootOutputDirectory);
            var outputFile = Path.Combine(outputDir, GetOuputFilename(inputDoc));

            if (!Directory.Exists(outputDir))
            {
                Console.WriteLine("Output Directory Doesn't Exist: '" + outputDir + "'");
                return;
            }
            if (!File.Exists(inputDoc))
            {
                Console.WriteLine("Input File Doesn't Exist: '" + inputDoc + "'");
                return;
            }

            var converter = new Html2Markdown.Converter();
            var markdown  = converter.ConvertFile(inputDoc);

            var ns = ExtractNamespaceFromFile(outputFile);

            if (NamespaceFileMappings.TryGetValue(ns, out var realNs))
            {
                ns = realNs;
            }

            foreach (var r in JavaDocFormatters.Replacers)
            {
                markdown = r.Replace(markdown);
            }
            if (JavaDocFormatters.CustomReplacers.TryGetValue(ns, out var replacers))
            {
                foreach (var r in replacers)
                {
                    markdown = r.Replace(markdown);
                }
            }

            var appendYamlHeader = ShouldAppendYamlHeader(inputDoc, ns);

            var fileContent = appendYamlHeader ? AppendYamlHeader(ns, markdown) : markdown;

            File.WriteAllText(outputFile, fileContent, Encoding.UTF8);
        }