private string FixBrokenCode(string markdown) { string str1 = markdown; int num; do { num = 0; List <string> originals = new List <string>(); List <string> replacements = new List <string>(); using (StringReader stringReader = new StringReader(str1)) { string str2; while ((str2 = stringReader.ReadLine()) != null) { if (str2.Contains("```") && !str2.StartsWith("```")) { ++num; originals.Add(str2.Trim()); replacements.Add("```\r\n"); string[] strArray = str2.Split(new char[] { '>' }, StringSplitOptions.None); for (int index = 0; index < strArray.Length - 1; ++index) { string wrongCasedClass = strArray[index].Replace("<", "").Replace(">", "").Replace("/", ""); originals.Add("<" + wrongCasedClass + ">()"); string correctClassCase = FindCorrectClassCase(wrongCasedClass); replacements.Add("<" + correctClassCase + ">()"); } } } } str1 = DragonUtil.BatchReplaceText(str1, originals, replacements); }while (num > 0); return(str1); }
public IEnumerator DownloadImagesRoutine() { CancelButton.SetActive(false); DownloadButton.SetActive(false); string imageDirectory = Path.GetDirectoryName(ConvMaster.HtmlFilePath) + "/images"; Directory.CreateDirectory(imageDirectory); List <string> imageUrls = Converter.FindAllImageLinksInHtml(ConvMaster.OriginalHTML); List <string> localImagePaths = new List <string>(); _downloadDictionary.Clear(); ConsoleText.text = ""; HtmlToMarkdownUIManager.Instance.SetProgressMaxValue(imageUrls.Count); HtmlToMarkdownUIManager.Instance.SetProgress(0); foreach (string fileUrl in imageUrls) { _downloadDictionary.Add(fileUrl, false); string fileName = Path.GetFileName(new Uri(fileUrl).LocalPath); localImagePaths.Add("images/" + fileName); //DragonUtil.DownloadFile(str, imageDirectory + "/" + fileName, null, 0, null); StartCoroutine(DownloadFile(fileUrl, imageDirectory + "/" + fileName)); } yield return(new WaitUntil(() => _amountOfImagesDownloaded == imageUrls.Count)); int failedDownloads = 0; foreach (var link in _downloadDictionary) { if (link.Value) // Image found { WriteToLinkConsole("[OK] " + link.Key); } else { WriteToLinkConsole("<color=#FF0000>[DOWNLOAD FAILED!] " + link.Key + "</color>"); failedDownloads++; } } ConvMaster.OriginalHTML = DragonUtil.BatchReplaceText(ConvMaster.OriginalHTML, imageUrls, localImagePaths); ConvMaster.Markdown = DragonUtil.BatchReplaceText(ConvMaster.Markdown, imageUrls, localImagePaths); CancelButton.SetActive(true); HtmlToMarkdownUIManager.Instance.LoadHtmlPage(0); HtmlToMarkdownUIManager.Instance.LoadMarkdownPage(0); //Console.WriteLine("Downloads complete!"); }
private static void ReplaceImageSources(ref string html, string folder) { var imageData = Converter.FindAllImageLinksInHtml(html, folder); List <string> localPaths = new List <string>(); List <string> fullPaths = new List <string>(); foreach (ImageLinkData data in imageData) { localPaths.Add(data.LocalImagePath); fullPaths.Add(data.FullImagePath); } html = DragonUtil.BatchReplaceText(html, localPaths, fullPaths); }
public static MarkdownAndHtml ReplaceLocalImageLinksWithUrls(string markdownPath, string markdownText, string htmlPath, string htmlText, bool onlyUpdateHtml, List <string> localImagePaths, List <string> imageUrls) { markdownText = DragonUtil.BatchReplaceText(markdownText, localImagePaths, imageUrls); htmlText = DragonUtil.BatchReplaceText(htmlText, localImagePaths, imageUrls); //var htmlText = ConvertMarkdownStringToHtml(markdownText,); if (htmlPath != null) { DragonUtil.QuickWriteFile(htmlPath, htmlText); Console.WriteLine("Replaced HTML!"); } if (!onlyUpdateHtml) { DragonUtil.QuickWriteFile(markdownPath, markdownText); Console.WriteLine("Replaced Markdown!"); } return(new MarkdownAndHtml { Markdown = markdownText, Html = htmlText }); }