public object GetExtra(XElement element, dynamic currentModel) { var xAttribute = element.Attribute("Location"); if (xAttribute == null) { return(string.Empty); } var fileLocation = Path.Combine(configuration.TemplateRootFolder, xAttribute.Value); var options = new MarkdownOptions { AutoHyperlink = true, AutoNewlines = true, EmptyElementSuffix = "/>", EncodeProblemUrlCharacters = false, LinkEmails = true, StrictBoldItalic = true }; var parser = new Markdown(options); var result = parser.Transform(File.ReadAllText(fileLocation)); return(result); }
public static string GetHtmlFromMarkdown(this string markdownText, bool isLight = false) { var markdownOptions = new MarkdownOptions { AutoHyperlink = true, AutoNewlines = false, EncodeProblemUrlCharacters = false, LinkEmails = true, StrictBoldItalic = true }; var markdown = new Markdown(markdownOptions); var htmlContent = markdown.Transform(markdownText); var regex = new Regex("\n"); htmlContent = regex.Replace(htmlContent, "<br/>"); //if (isLight) //{ // htmlContent = MARKDOWN_STYLES_LIGHT + htmlContent; //} //else //{ // htmlContent = MARKDOWN_STYLES_DARK + htmlContent; //} var html = string.Format("<html><body>{0}</body></html>", htmlContent); var regex2 = new Regex("\r"); html = regex.Replace(html, string.Empty); html = regex2.Replace(html, string.Empty); return(html); }
public static string ConvertTextToHTML(string plainText) { string str = string.Empty; if (string.IsNullOrEmpty(plainText)) { return(str); } MarkdownOptions options = new MarkdownOptions { AutoHyperlink = _settings.Markdown_AutoHyperlink, // AutoNewLines = _settings.Markdown_AutoNewLines, LinkEmails = _settings.Markdown_LinkEmails, AsteriskIntraWordEmphasis = _settings.Markdown_EncodeProblemUrlCharacters }; Markdown markdown = new Markdown(options); markdown.AutoNewLines = _settings.Markdown_AutoNewLines; try { str = markdown.Transform(plainText); } catch (OutOfMemoryException) { throw; } catch (Exception) { throw; } return(str); }
/// <summary> /// Runs this process and performs the appropriate actions. /// </summary> public override void Run() { // Verify that the input file exists since if we can't, it is // meaningless to continue. if (this.Input == null) { throw new Exception("Input was not properly set to a value."); } // Open up a handle to the Markdown file that we are processing. This uses an // event-based reader to allow us to write the output file easily. var options = new MarkdownOptions() { AllowMetadata = true, }; using (var markdownReader = new MarkdownReader(this.Input, options)) { // We also need an XML writer for the resulting file. using (XmlWriter xmlWriter = this.CreateXmlWriter()) { // Convert the Markdown into XML. this.ConvertMarkdown( markdownReader, xmlWriter); } } }
public async Task <IActionResult> NewProject(ProjectViewModel proj) { var options = new MarkdownOptions { AutoHyperlink = true, AutoNewLines = true, LinkEmails = true, QuoteSingleLine = true, StrictBoldItalic = true }; KraudFan2_0.HelpClass.ProjectHelp.NewProjectHelpClass taghelp = new HelpClass.ProjectHelp.NewProjectHelpClass(db); List <Tag> tags = taghelp.TagsWork(proj.Tags); Markdown mark = new Markdown(options); string text = mark.Transform(proj.Content); var datetoEnter = DateTime.ParseExact(proj.DateEnd, "yyyy-MM-dd", CultureInfo.InvariantCulture); Project project = new Project { Image = await AddFileAsync(proj.Image), Name = proj.Name, Description = proj.Description, Content = text, Status = "In progress", DateCreate = DateTime.Now, DateEnd = datetoEnter, MinDonate = proj.MinDonate, MaxDonate = proj.MaxDonate, User = db.Users.Find(_userManager.GetUserId(User)), Targets = new List <FinancialTarget>(), }; foreach (var item in tags) { project.ProjectTags.Add(new ProjectTags { Project = project, Tag = item }); } foreach (var item in proj.Targets) { if (item == proj.Targets[0]) { } else { FinancialTarget temp = new FinancialTarget { TotalSum = item.TotalSum, Desctiprion = item.Desctiprion, DateEnd = item.DateEnd, }; project.Targets.Add(temp); } } db.Projects.Add(project); db.SaveChanges(); FullSearchAdd.PutElementInSearch(db.Projects.Last()); var id = db.Projects.Last().Id; return(RedirectToAction("ProjectShow", new { id = id })); }
public MarkdownConverter() { options = new MarkdownOptions { LinkEmails = true }; }
public string Process(string input) { var options = new MarkdownOptions(); var markdown = new Markdown(); var output = markdown.Transform(input); return(output); }
public MarkdownConverter(MarkdownOptions options) { if (options == null) { throw new ArgumentNullException("options"); } this.options = options; }
static string Markdown(string raw) { var options = new MarkdownOptions(); options.AutoHyperlink = true; options.LinkEmails = true; return(new Markdown(options).Transform(raw.Trim())); }
private void InitializeCompiler() { if (_compiler == null) { MarkdownOptions options = new MarkdownOptions(); options.AutoHyperlink = true; _compiler = new Markdown(options); } }
public IMarkdownOptions CreateMarkdownOptions() { var options = new MarkdownOptions(); options.AutoHyperlink = true; options.AutoNewLines = true; options.LinkEmails = true; return(options); }
private void InitializeCompiler() { if (_compiler == null) { MarkdownOptions options = new MarkdownOptions(); options.AutoHyperlink = true; _compiler = new Markdown(options); } }
public MarkdownSharpMarkdownToHtml() { MarkdownOptions options = new MarkdownOptions(); options.AutoHyperlink = true; // options.AutoNewLines = true; options.LinkEmails = true; this.Markdown = new Markdown(options); }
private void ShowReadme(string readmePath) { if (string.IsNullOrEmpty(readmePath)) { BEditReadme.Visibility = Visibility.Hidden; BAddReadme.Visibility = Visibility.Visible; WbReadme.Navigate("about:blank"); return; } BEditReadme.Visibility = Visibility.Visible; BAddReadme.Visibility = Visibility.Hidden; var strAppDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase); if (strAppDir == null) { return; } var strFullPathToMyFile = Path.Combine(strAppDir, "ReadMeStyle.less"); var source = File.ReadAllText(readmePath); var options = new MarkdownOptions { AutoHyperlink = true, AutoNewlines = true, LinkEmails = true, QuoteSingleLine = true, StrictBoldItalic = true }; var mark = new Markdown(options); var headerHtml = @"<!DOCTYPE html> <head> <meta charset='utf-8'> <link rel='stylesheet' type='text/css' href=' " + strFullPathToMyFile + @"' /> </head> <body> "; const string footerHtml = @"</body>"; var htmlString = headerHtml + mark.Transform(source) + footerHtml; WbReadme.NavigateToString(htmlString); }
static MarkdownHelper() { options = new MarkdownOptions { AutoHyperlink = true, AutoNewLines = true, LinkEmails = true, QuoteSingleLine = true, StrictBoldItalic = true }; converter = new Markdown(options); }
public static Markdown GetMarkdown() { var options = new MarkdownOptions() { AutoHyperlink = true, AutoNewlines = false, EmptyElementSuffix = " />", LinkEmails = false, StrictBoldItalic = true }; var m = new Markdown(options); return(m); }
private static Markdown CreateMarkdownTransformer() { var options = new MarkdownOptions { AutoHyperlink = false, AutoNewLines = false, EmptyElementSuffix = "/>", EncodeProblemUrlCharacters = true, LinkEmails = true, StrictBoldItalic = false, }; var markdown = new Markdown(options); return(markdown); }
public static string HtmlFromMarkdown(this string content) { var options = new MarkdownOptions { AutoHyperlink = true, AutoNewLines = true, EncodeProblemUrlCharacters = true, LinkEmails = true }; var md = new Markdown(options); return(md.Transform(content)); }
public static string LoadMarkdown(this HelpItem HelpItem) { if (HelpItem == null) { return(null); } HelpItem.LoadContent(); var opts = new MarkdownOptions(); opts.Strikethrough = true; var md = new Markdown(opts); HelpItem.HTML = md.Transform(HelpItem.Content ?? ""); return(HelpItem.HTML); }
public void ConvertMarkDown() { var options = new MarkdownOptions { AutoHyperlink = true, AutoNewLines = true, LinkEmails = true, QuoteSingleLine = true, StrictBoldItalic = true }; Markdown mark = new Markdown(options); var testo = mark.Transform("#testo"); Assert.Equal("<h1>testo</h1>", testo); }
public string Parse(string content) { if (string.IsNullOrWhiteSpace(content)) { return(string.Empty); } var markdownOptions = new MarkdownOptions { AutoHyperlink = true }; var markdown = new MarkdownSharp.Markdown(markdownOptions); return(markdown.Transform(content)); }
/* ******************************************************************* * Constructors * *******************************************************************/ /* ******************************************************************* * Methods * *******************************************************************/ protected override void ProcessRecord() { WriteVerbose("markdownConvertToHtml for file " + InputFile + " started."); var file = new FileInfo(InputFile); var outFile = new FileInfo(OutputFile); if (!file.Exists) { throw new FileNotFoundException($"File {InputFile} is missing", InputFile); } if (outFile.Exists) { throw new ApplicationException("Outfile " + OutputFile + " exists, cannot continue"); } //read markdown file var data = ReadFile(file); //convert to html var options = new MarkdownOptions { EmptyElementSuffix = "/>" }; var m = new Markdown.MarkdownParser(options); data = m.Transform(data); //apply template var templateData = FindTemplateData(file.Directory); var doclist = CreateDocList(file); if (!string.IsNullOrEmpty(templateData)) { var dict = new Dictionary <string, string> { { "doclist", doclist }, { "title", Path.GetFileNameWithoutExtension(InputFile) }, { "content", data } }; data = FillTemplate(templateData, dict); } //save html file using (var fs = new StreamWriter(outFile.Create())) { fs.Write(data); } WriteVerbose("Saved changes"); }
public LicenseDialog() { InitializeComponent(); Text = string.Format(Text, Assembly.GetExecutingAssembly().GetName().Version); _licenseBrowser = new Browser(); _licenseBrowser.Isolator = new NavigationIsolator(); // never used while other browsers are around _licenseBrowser.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; _licenseBrowser.Location = new Point(12, 12); _licenseBrowser.Name = "licenseBrowser"; _licenseBrowser.Size = new Size(_acceptButton.Right - 12, _acceptButton.Top - 24); Controls.Add(_licenseBrowser); var options = new MarkdownOptions() { LinkEmails = true, AutoHyperlink = true }; var m = new Markdown(options); var locale = CultureInfo.CurrentUICulture.Name; string licenseFilePath = BloomFileLocator.GetFileDistributedWithApplication("license.md"); var localizedLicenseFilePath = licenseFilePath.Substring(0, licenseFilePath.Length - 3) + "-" + locale + ".md"; if (RobustFile.Exists(localizedLicenseFilePath)) { licenseFilePath = localizedLicenseFilePath; } else { var index = locale.IndexOf('-'); if (index > 0) { locale = locale.Substring(0, index); localizedLicenseFilePath = licenseFilePath.Substring(0, licenseFilePath.Length - 3) + "-" + locale + ".md"; if (RobustFile.Exists(localizedLicenseFilePath)) { licenseFilePath = localizedLicenseFilePath; } } } var contents = m.Transform(RobustFile.ReadAllText(licenseFilePath, Encoding.UTF8)); var html = string.Format("<html><head><head/><body>{0}</body></html>", contents); _licenseBrowser.NavigateRawHtml(html); _licenseBrowser.Visible = true; }
protected override void ProcessRecord() { if (MarkdownContent != null && MarkdownContent.Length > 0) { MarkdownOptions options = new MarkdownOptions { AutoHyperlink = this.AutoHyperlink, AutoNewlines = this.AutoNewlines, EmptyElementSuffix = this.EmptyElementSuffix, LinkEmails = this.LinkEmails, StrictBoldItalic = this.StrictBoldItalic }; Markdown markyMark = new Markdown(options); WriteObject(markyMark.Transform(MarkdownContent)); } }
public ActionResult Details(int id) { News item = mapper.Map <NewsViewModel, News>(MainService.NewsService.GetNewsById(id)); string html = item.Content; var rating = item.Rating; var ratinCount = item.RatingCount; decimal totalRating; if (ratinCount == 0) { totalRating = 0.0M; } else { totalRating = rating / ratinCount; } if (totalRating % 1 >= 0.5M) { ViewBag.totalRating = Convert.ToInt32(Math.Round(totalRating)); } else { ViewBag.totalRating = Convert.ToInt32(Math.Floor(totalRating)); } ViewBag.AvgRating = Math.Round(totalRating, 3); ViewBag.RatingCount = ratinCount; var options = new MarkdownOptions { AutoHyperlink = true, AutoNewLines = true, LinkEmails = true, QuoteSingleLine = true, StrictBoldItalic = true }; Markdown markdown = new Markdown(options); var a = markdown.Transform(html); item.Content = a; return(View(item)); }
private void shareAssignment(DataTransferManager sender, DataRequestedEventArgs args) { string desc = vm.curAssignment.description; DateTimeOffset end = vm.curAssignment.endDate; var options = new MarkdownOptions { AutoHyperlink = true, LinkEmails = true, AutoNewlines = false, }; Markdown md = new Markdown(options); string html_description = md.Transform(desc); DataRequest request = args.Request; request.Data.Properties.Title = "Assignment Shared from Matrix_UWP"; request.Data.Properties.Description = vm.curAssignment.name; string html_content = HtmlFormatHelper.CreateHtmlFormat($"<h1>DDL: {end.LocalDateTime.ToString("yyyy-MM-dd HH:mm:ss")}</h1><div>{html_description}</div>"); System.Diagnostics.Debug.WriteLine(html_content); request.Data.SetHtmlFormat(html_content); }
public static Document Create(string filename) { Document doc = new Document(); doc.Filename = filename; string text = File.ReadAllText(doc.Filename).Trim(); Match metaMatch = metaAreaRegex.Match(text); if (metaMatch.Success && 0 == metaMatch.Index) { Match endMetaMatch = metaAreaRegex.Match(text, metaMatch.Length); if (endMetaMatch.Success) { string[] meta = text.Substring(metaMatch.Length, endMetaMatch.Index - metaMatch.Length).Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (string line in meta) { Match m = keyValuesRegex.Match(line); if (m.Success) { string key = m.Groups["key"].Value.ToLowerInvariant(); string value = m.Groups["value"].Value.Trim(); doc.Meta.Add(key, value); } } text = text.Substring(endMetaMatch.Index + endMetaMatch.Length).Trim(); } } var mdOptions = new MarkdownOptions { AutoHyperlink = true, EmptyElementSuffix = " />" }; var markdown = new Markdown(mdOptions); doc.Text = markdown.Transform(text).Trim().Replace("\n", Environment.NewLine).Replace("\r\r", "\r"); return(doc); }
protected string GetHtml() { try { var options = new MarkdownOptions { AutoHyperlink = true, LinkEmails = true, StrictBoldItalic = true }; Markdown mark = new Markdown(options); var html = mark.Transform(this.Markdown); return(html); } catch (Exception ex) { Logger.Writer.Write(ex); return("Error Rendering Markdown"); } }
public static string ToHtml(this string markdownText) { var markdownOptions = new MarkdownOptions { AutoHyperlink = true, AutoNewlines = false, EncodeProblemUrlCharacters = false, LinkEmails = true, StrictBoldItalic = true, EmptyElementSuffix = "/>" }; var markdown = new Markdown(markdownOptions); var htmlContent = markdown.Transform(markdownText); //var regex = new Regex("\n"); //htmlContent = regex.Replace(htmlContent, "<br/>"); var html = htmlContent.HtmlWrapped(); //var regex2 = new Regex("\r"); //html = regex.Replace(html, string.Empty); //html = regex2.Replace(html, string.Empty); return(html); }
private static void Main(string[] args) { CommandLine commandLine; if (!CommandLine.TryParseArguments(args, out commandLine)) { ShowHelp(); Environment.Exit(1); } string text = String.Empty; if (!String.IsNullOrEmpty(commandLine.Header)) { text = File.ReadAllText(commandLine.Header); } //var mdOptions = new MarkdownOptions { AutoHyperlink = options.AutoHyperlink, AutoNewlines = options.AutoNewLines, EmptyElementSuffix = options.OutputXHTML ? " />" : ">", EncodeProblemUrlCharacters = options.EncodeProblemUrlCharacters, LinkEmails = !options.DontLinkEmails, StrictBoldItalic = options.StrictBoldItalic }; var mdOptions = new MarkdownOptions { EmptyElementSuffix = " />" }; foreach (var fileName in commandLine.Files) { var markdown = new Markdown(mdOptions); text += markdown.Transform(File.ReadAllText(fileName)); } if (!String.IsNullOrEmpty(commandLine.Footer)) { text += File.ReadAllText(commandLine.Footer); } var preprocessor = new Preprocessor(commandLine.PreprocessorDefines); string[] lines = text.Replace("\r", String.Empty).Split(new char[] { '\n' }, StringSplitOptions.None); for (int i = 0; i < lines.Length; ++i) { lines[i] = preprocessor.Preprocess(i + 1, lines[i]); } text = String.Join(Environment.NewLine, lines); if (!String.IsNullOrEmpty(commandLine.Output)) { string outputPath = Path.GetFullPath(commandLine.Output); string outputFolder = Path.GetDirectoryName(outputPath); if (!Directory.Exists(outputFolder)) { Directory.CreateDirectory(outputFolder); } using (TextWriter output = new StreamWriter(outputPath)) { output.WriteLine(text); } } else { Console.Write(text); } }
public async Task Load(Tuple <Repository, string, string> repoPath) //This page recieves RepositoryId and name of the file { Content = ""; IsSupportedFile = true; Repository = repoPath.Item1; Path = repoPath.Item2; if (string.IsNullOrWhiteSpace(repoPath.Item3)) { SelectedBranch = await RepositoryUtility.GetDefaultBranch(Repository.Id); } else { SelectedBranch = repoPath.Item3; } MarkdownOptions options = new MarkdownOptions { AsteriskIntraWordEmphasis = true, AutoNewlines = true, StrictBoldItalic = true, AutoHyperlink = false, LinkEmails = true }; Markdown markDown = new Markdown(options); if (!GlobalHelper.IsInternet()) { Messenger.Default.Send(new GlobalHelper.NoInternetMessageType()); //Sending NoInternet message to all viewModels } else { Messenger.Default.Send(new GlobalHelper.HasInternetMessageType()); //Sending Internet available message to all viewModels isLoading = true; IsReadme = false; IsImage = false; if ((Path.ToLower().EndsWith(".exe")) || (Path.ToLower().EndsWith(".pdf")) || (Path.ToLower().EndsWith(".ttf")) || (Path.ToLower().EndsWith(".suo")) || (Path.ToLower().EndsWith(".mp3")) || (Path.ToLower().EndsWith(".mp4")) || (Path.ToLower().EndsWith(".avi"))) { /* * Unsupported file types */ IsSupportedFile = false; isLoading = false; return; } if ((Path.ToLower()).EndsWith(".png") || (Path.ToLower()).EndsWith(".jpg") || (Path.ToLower()).EndsWith(".jpeg") || (Path.ToLower().EndsWith(".gif"))) { /* * Image file types */ IsImage = true; var uri = (await RepositoryUtility.GetRepositoryContentByPath(Repository.Id, Path, SelectedBranch))[0].DownloadUrl; ImageFile = new BitmapImage(uri); isLoading = false; return; } if ((Path.ToLower()).EndsWith(".md")) { /* * Files with .md extension will be shown with full markdown */ IsReadme = true; var str = (await RepositoryUtility.GetRepositoryContentByPath(Repository.Id, Path, SelectedBranch))[0].Content; Content = "<html><head><meta charset = \"utf-8\" /></head><body style=\"font-family: sans-serif\">" + markDown.Transform(str) + "</body></html>"; isLoading = false; return; } Content = (await RepositoryUtility.GetRepositoryContentByPath(Repository.Id, Path, SelectedBranch))[0].Content; isLoading = false; } }