/// <summary> /// Chunk the text message and return it as WeChat response. /// </summary> /// <param name="activity">Message activity from bot.</param> /// <param name="text">Text content need to be chunked.</param> /// <returns>Response message list.</returns> private static IList <IResponseMessageBase> GetFixedMessages(IMessageActivity activity, string text) { var responses = new List <IResponseMessageBase>(); if (string.IsNullOrEmpty(text)) { return(responses); } if (activity.TextFormat == TextFormatTypes.Markdown) { var marked = new Marked { Options = { Sanitize = false, Mangle = false, }, }; marked.Options.Renderer = new TextMarkdownRenderer(marked.Options); // Marked package will return additional new line in the end. text = marked.Parse(text).Trim(); } responses.Add(new TextResponse(activity.From.Id, activity.Recipient.Id, text)); return(responses); }
public IActionResult EditThread(long id, string content) { var thread = DB.Threads .Where(x => x.Id == id) .SingleOrDefault(); if (thread == null) { return(Prompt(x => { x.Title = "资源没有找到"; x.Details = "您请求的资源没有找到,请返回重试!"; x.StatusCode = 404; })); } if (thread.UserId != User.Current.Id && !User.AnyRoles("Root, Master")) { return(Prompt(x => { x.Title = "权限不足"; x.Details = "您没有权限删除该主题"; x.StatusCode = 500; })); } thread.Content = content; DB.SaveChanges(); ForumHub.Clients.Group("Thread-" + thread.Id).OnThreadEdited(thread.Id); return(Content(Marked.Parse(content))); }
public IActionResult Get() { var pullrequestEvents = _pullRequestEventRepository.GetAll(null, null); var viewModel = new List<PullRequestEventViewModel>(); var marked = new Marked(); foreach (var pullRequestEvent in pullrequestEvents) { var itemViewModel = new PullRequestEventViewModel() { Action = pullRequestEvent.Action, Body = marked.Parse(pullRequestEvent.Body), CreatedAt = pullRequestEvent.CreatedAt, Merged = pullRequestEvent.Merged, MergedAt = pullRequestEvent.MergedAt, MergedBy = pullRequestEvent.MergedBy, RepositoryName = pullRequestEvent.RepositoryName, Title = pullRequestEvent.Title, Id = pullRequestEvent.Id }; //itemViewModel.Team = new Models.TeamResponse() //{ // Id = pullRequestEvent.Team.Id, // Name = pullRequestEvent.Team.Name, //}; //if(pullRequestEvent.Team.ChildrenTeams != null) //{ // itemViewModel.Team.ChildrenTeam = new List<Models.TeamResponse>(); // foreach (var childTeam in pullRequestEvent.Team.ChildrenTeams) // { // var childTeamResponse = new Models.TeamResponse() // { // Id = childTeam.Id, // Name = childTeam.Name // }; // itemViewModel.Team.ChildrenTeam.Add(childTeamResponse); // } //} itemViewModel.Labels = new List<LabelDTO>(); foreach (var label in pullRequestEvent.Labels) { var labelDTO = new LabelDTO() { Color = label.Color, Name = label.Name }; itemViewModel.Labels.Add(labelDTO); } viewModel.Add(itemViewModel); } return Ok(viewModel); }
public IActionResult PostEdit(string id, string newId, string content, string tags, bool isPage, string title, Guid?catalog) { var post = DB.Posts .Include(x => x.Tags) .Where(x => x.Url == id) .SingleOrDefault(); if (post == null) { return(Prompt(new Prompt { StatusCode = 404, Title = SR["Not Found"], Details = SR["The resources have not been found, please check your request."], RedirectUrl = Url.Link("default", new { controller = "Home", action = "Index" }), RedirectText = SR["Back to home"] })); } var summary = ""; var tmp = content.Split('\n'); if (tmp.Count() > 16) { for (var i = 0; i < 16; i++) { summary += tmp[i] + '\n'; } summary += $"\r\n[{SR["Read More"]} »](/post/{newId})"; } else { summary = content; } foreach (var t in post.Tags) { DB.PostTags.Remove(t); } post.Url = newId; post.Summary = summary; post.Title = title; post.Content = content; post.CatalogId = catalog; post.IsPage = isPage; if (!string.IsNullOrEmpty(tags)) { var _tags = tags.Split(','); foreach (var t in _tags) { post.Tags.Add(new PostTag { PostId = post.Id, Tag = t.Trim(' ') }); } } DB.SaveChanges(); return(Content(Marked.Parse(content))); }
private static void GenerateSchemaExplorerPage(string header, Marked marked) { string[] elements = new string[] { "TextBlock", "Image", "Input.Text", "Input.Number", "Input.Date", "Input.Time", "Input.Toggle", "Input.ChoiceSet", "Container", "ColumnSet", "Column", "FactSet", "ImageSet",/* "ActionSet",*/ "Action.OpenUrl", "Action.Submit", "Action.Http", "Action.ShowCard" }; using (TextWriter writer = new StreamWriter(File.Open(@"..\..\..\..\..\website\wwwroot\explorer\index.html", FileMode.Create))) { writer.WriteLine(header.Replace("$PAGE$", "explorer")); // side bar writer.WriteLine("<div id=\"sidebar\" class=\"w3-sidebar w3-light-grey w3-hide-small w3-bar-block\">"); string firstLink = null; foreach (var element in elements) { var id = element.Replace(".", string.Empty); if (firstLink == null) { firstLink = id; } writer.WriteLine($"<a href=\"#{id}\" id='{id}Link' class=\"elementLink w3-bar-item w3-button\">{element}</a>"); } WriteLoadFirstLink(writer, firstLink); writer.WriteLine("</div>"); writer.WriteLine("<div class=\"w3-container content-sidebar maincontent\">"); foreach (var element in elements) { writer.WriteLine($"<div class='element' id='{element.Replace(".", String.Empty)}Content' style='display:none'>"); writer.WriteLine($"<h1>{element}</h1>"); string path = $@"..\..\..\..\..\website\wwwroot\explorer\markdown\{element}.md"; if (File.Exists(path)) { string markdown = File.ReadAllText(path); writer.WriteLine(marked.Parse(markdown)); } foreach (var file in Directory.GetFiles($@"..\..\..\..\..\website\wwwroot\explorer\cards", element + "*.json").Where(f => f.Contains(element + "."))) { var name = Path.GetFileNameWithoutExtension(file); writer.WriteLine($"<h2 onclick='toggleContent(\"{name}Content\")'>{name}</h2>"); writer.WriteLine($"<div id='{name}Content' style='display:block'>"); var json = File.ReadAllText(file, Encoding.UTF8); writer.WriteLine($"<div id='{name}Card' class='card' ></div>"); writer.WriteLine($"<a class='trymelink' target='_blank' href='/visualizer?card=/explorer/cards/{Path.GetFileName(file)}'>Try it Yourself »</a>"); writer.WriteLine($"</div><script>renderCard('{name}Card', {json});</script>"); } writer.WriteLine($"</div>"); } writer.WriteLine("</div>"); writer.WriteLine("</body></html>"); writer.Flush(); } }
public static IEnumerable <HtmlTag> Convert(string markdown) { var marked = new Marked(); marked.Options.Mangle = false; marked.Options.Sanitize = true; marked.Options.XHtml = true; var rawXhtml = marked.Parse(markdown); var root = XElement.Parse($"<root>{rawXhtml}</root>"); return(root.Elements().Select(RawXhtmlToHtmlTag)); }
public string Get(string file) { var path = Path.Combine(_env.WebRootPath, file.Replace("/", "\\")); Marked marked = new Marked(); marked.Options.Renderer = new CodeMarkdown(); var text = System.IO.File.ReadAllText(path); HttpContext.Response.ContentType = "text/html"; return(marked.Parse(text)); }
public void Parse_Null_Null() { //action var actual = _marked.Parse(null); //assert Assert.IsNull(actual); }
public IActionResult ThreadContent(long id) { var thread = DB.Threads .Where(x => x.Id == id) .Select(x => x.Content) .SingleOrDefault(); if (thread == null) { return(Content("")); } else { return(Content(Marked.Parse(thread))); } }
public string ReadFile(string path) { //reading file in try { string text = File.ReadAllText(path); var marked = new Marked(); var html = marked.Parse(text); return(html); } catch (Exception) { return("Tiedosto puuttuu"); } }
private void LoadMdPaths() { Marked marked = new Marked(); string path = AppDomain.CurrentDomain.BaseDirectory + "api.md"; string txt = File.ReadAllText(path); string[] lines = File.ReadAllLines(path); List <string> urls = new List <string>(); foreach (string line in lines) { if (line.Trim().StartsWith("http:")) { urls.Add(line.Trim()); } } string result = marked.Parse(txt); DataGrid1.ItemsSource = urls; }
private static TextBlock CreateControl(AdaptiveTextBlock textBlock, AdaptiveRenderContext context) { Marked marked = new Marked(); marked.Options.Renderer = new AdaptiveXamlMarkdownRenderer(); marked.Options.Mangle = false; marked.Options.Sanitize = true; string text = RendererUtilities.ApplyTextFunctions(textBlock.Text); // uiTextBlock.Text = textBlock.Text; string xaml = $"<TextBlock xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">{marked.Parse(text)}</TextBlock>"; StringReader stringReader = new StringReader(xaml); XmlReader xmlReader = XmlReader.Create(stringReader); var uiTextBlock = (System.Windows.Controls.TextBlock)XamlReader.Load(xmlReader); uiTextBlock.Style = context.GetStyle($"Adaptive.{textBlock.Type}"); uiTextBlock.FontFamily = new FontFamily(context.Config.FontFamily); uiTextBlock.TextWrapping = TextWrapping.NoWrap; switch (textBlock.Weight) { case AdaptiveTextWeight.Bolder: uiTextBlock.FontWeight = FontWeight.FromOpenTypeWeight(700); break; case AdaptiveTextWeight.Lighter: uiTextBlock.FontWeight = FontWeight.FromOpenTypeWeight(300); break; case AdaptiveTextWeight.Default: default: uiTextBlock.FontWeight = FontWeight.FromOpenTypeWeight(400); break; } uiTextBlock.TextTrimming = TextTrimming.CharacterEllipsis; if (textBlock.HorizontalAlignment != AdaptiveHorizontalAlignment.Left) { System.Windows.HorizontalAlignment alignment; if (Enum.TryParse <System.Windows.HorizontalAlignment>(textBlock.HorizontalAlignment.ToString(), out alignment)) { uiTextBlock.HorizontalAlignment = alignment; } } if (textBlock.Wrap) { uiTextBlock.TextWrapping = TextWrapping.Wrap; } return(uiTextBlock); }
private static Inline FormatInlineTextRun(AdaptiveTextRun textRun, AdaptiveRenderContext context) { Marked marked = new Marked(); marked.Options.Renderer = new AdaptiveXamlMarkdownRenderer(); marked.Options.Mangle = false; marked.Options.Sanitize = true; // Handle Date/Time parsing string text = RendererUtilities.ApplyTextFunctions(textRun.Text, context.Lang); // Handle markdown string xaml = $"<Span xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xml:space=\"preserve\">{marked.Parse(text)}</Span>"; StringReader stringReader = new StringReader(xaml); XmlReader xmlReader = XmlReader.Create(stringReader); Span uiInlineElement = XamlReader.Load(xmlReader) as Span; uiInlineElement.Style = context.GetStyle($"Adaptive.{textRun.Type}"); uiInlineElement.FontFamily = new FontFamily(context.Config.GetFontFamily(textRun.FontStyle)); uiInlineElement.FontWeight = FontWeight.FromOpenTypeWeight(context.Config.GetFontWeight(textRun.FontStyle, textRun.Weight)); uiInlineElement.FontSize = context.Config.GetFontSize(textRun.FontStyle, textRun.Size); uiInlineElement.SetColor(textRun.Color, textRun.IsSubtle, context); return(uiInlineElement); }
private static TextBlock CreateControl(AdaptiveTextBlock textBlock, AdaptiveRenderContext context) { Marked marked = new Marked(); marked.Options.Renderer = new AdaptiveXamlMarkdownRenderer(); marked.Options.Mangle = false; marked.Options.Sanitize = true; string text = RendererUtilities.ApplyTextFunctions(textBlock.Text, context.Lang); // uiTextBlock.Text = textBlock.Text; string xaml = $"<TextBlock xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">{marked.Parse(text)}</TextBlock>"; StringReader stringReader = new StringReader(xaml); XmlReader xmlReader = XmlReader.Create(stringReader); var uiTextBlock = (System.Windows.Controls.TextBlock)XamlReader.Load(xmlReader); uiTextBlock.Style = context.GetStyle($"Adaptive.{textBlock.Type}"); uiTextBlock.TextWrapping = TextWrapping.NoWrap; uiTextBlock.FontFamily = new FontFamily(RendererUtil.GetFontFamilyFromList(context.Config.GetFontFamily(textBlock.FontType))); uiTextBlock.FontWeight = FontWeight.FromOpenTypeWeight(context.Config.GetFontWeight(textBlock.FontType, textBlock.Weight)); uiTextBlock.FontSize = context.Config.GetFontSize(textBlock.FontType, textBlock.Size); uiTextBlock.TextTrimming = TextTrimming.CharacterEllipsis; if (textBlock.Italic) { uiTextBlock.FontStyle = FontStyles.Italic; } if (textBlock.Strikethrough) { uiTextBlock.TextDecorations = TextDecorations.Strikethrough; } if (textBlock.HorizontalAlignment != AdaptiveHorizontalAlignment.Left) { System.Windows.TextAlignment alignment; if (Enum.TryParse <System.Windows.TextAlignment>(textBlock.HorizontalAlignment.ToString(), out alignment)) { uiTextBlock.TextAlignment = alignment; } } if (textBlock.Wrap) { uiTextBlock.TextWrapping = TextWrapping.Wrap; } return(uiTextBlock); }
protected static HtmlTag TextBlockRender(TypedElement element, RenderContext context) { TextBlock textBlock = (TextBlock)element; int fontSize; switch (textBlock.Size) { case TextSize.Small: fontSize = context.Config.FontSizes.Small; break; case TextSize.Medium: fontSize = context.Config.FontSizes.Medium; break; case TextSize.Large: fontSize = context.Config.FontSizes.Large; break; case TextSize.ExtraLarge: fontSize = context.Config.FontSizes.ExtraLarge; break; case TextSize.Normal: default: fontSize = context.Config.FontSizes.Normal; break; } int weight = 400; switch (textBlock.Weight) { case TextWeight.Lighter: weight = 200; break; case TextWeight.Bolder: weight = 600; break; } var lineHeight = fontSize * 1.2; var uiTextBlock = new DivTag() .AddClass($"ac-{element.Type.Replace(".", "").ToLower()}") .Style("text-align", textBlock.HorizontalAlignment.ToString().ToLower()) .Style("box-sizing", "border-box") .Style("color", context.GetColor(textBlock.Color, textBlock.IsSubtle)) .Style("line-height", $"{lineHeight.ToString("F")}px") .Style("font-size", $"{fontSize}px") .Style("font-weight", $"{weight}"); if (!String.IsNullOrEmpty(context.Config.FontFamily)) { uiTextBlock = uiTextBlock .Style("font-family", context.Config.FontFamily); } if (textBlock.MaxLines > 0) { uiTextBlock = uiTextBlock .Style("max-height", $"{lineHeight * textBlock.MaxLines}px") .Style("overflow", "hidden"); } var wrapStyle = ""; if (textBlock.Wrap == false) { uiTextBlock = uiTextBlock .Style("white-space", "nowrap"); wrapStyle = "text-overflow: ellipsis; overflow: hidden"; } else { uiTextBlock = uiTextBlock .Style("word-wrap", "break-word"); } var marked = new Marked(); marked.Options.Mangle = false; marked.Options.Sanitize = true; var html = marked.Parse(RendererUtilities.ApplyTextFunctions(textBlock.Text)) .Replace("<p>", $"<p style='margin-top: 0px;margin-bottom: 0px;width: 100%{wrapStyle}'>"); uiTextBlock.Children.Add(new LiteralTag(html)); return(uiTextBlock); }
public static string Render(string source) => _marked.Parse(source);