/// <summary> /// Inline processing /// </summary> /// <param name="i"></param> /// <returns></returns> protected string ProcessInline(MarkdownInline i) { string para = string.Empty; switch (i.Type) { //case MarkdownInlineType.Comment: // break; //case MarkdownInlineType.TextRun: // break; case MarkdownInlineType.Bold: para += ANSI.WriteMode(ANSICodes.Modes.Bold) + i.ToString().Trim('*') + ANSI.WriteMode(); break; //case MarkdownInlineType.Italic: // break; case MarkdownInlineType.MarkdownLink: MarkdownLinkInline mitLink = (MarkdownLinkInline)i; if (mitLink.Url.ToLower().EndsWith(".md")) { actionsCount++; para += $"{mitLink.Inlines[0]}[{actionsCount}]"; Data.Actions.Add(actionsCount.ToString(), new BBSCodeResult.Action() { module = "MarkdownScreen", data = (mitLink.Url.StartsWith("http") ? "" : basePath) + mitLink.Url }); } else { para += mitLink.ToString(); } break; //case MarkdownInlineType.RawHyperlink: // break; //case MarkdownInlineType.RawSubreddit: // break; //case MarkdownInlineType.Strikethrough: // break; //case MarkdownInlineType.Superscript: // break; //case MarkdownInlineType.Subscript: // break; //case MarkdownInlineType.Code: // break; //case MarkdownInlineType.Image: // break; //case MarkdownInlineType.Emoji: // break; //case MarkdownInlineType.LinkReference: // break; default: para += i.ToString(); break; } return(para); }
/// <summary> /// Markdown blocks processing /// </summary> /// <param name="b"></param> /// <param name="recursionLevel"></param> protected List <string> BlockProcessing(MarkdownBlock b, int recursionLevel) { string forecolor = string.Empty; string backcolor = string.Empty; string underline = string.Empty; int maxWidth = client.screenWidth - recursionLevel * 2; List <string> Text = new List <string>(); switch (b.Type) { case MarkdownBlockType.Root: break; case MarkdownBlockType.Paragraph: string para = ""; foreach (var i in ((ParagraphBlock)b).Inlines) { para += ProcessInline(i); } Text.AddRange(TextHelper.WordWrap(para, maxWidth)); Text.Add(string.Empty); break; case MarkdownBlockType.Quote: break; case MarkdownBlockType.Code: forecolor = ANSI.GetStyleForeColor("Code_Color", mdStyles); backcolor = ANSI.GetStyleBackColor("Code_Back", mdStyles); List <string> rows = TextHelper.SplitString(((CodeBlock)b).Text); foreach (string s in rows) { Text.Add(backcolor + forecolor + ANSI.ClearCurrentLine + s + ANSI.WriteMode()); } Text.Add(ANSI.WriteMode()); break; case MarkdownBlockType.Header: HeaderBlock hb = (HeaderBlock)b; Text.AddRange(ANSI.Header(hb.ToString(), hb.HeaderLevel, maxWidth)); break; case MarkdownBlockType.List: ListBlock lb = (ListBlock)b; string indent = new string(' ', recursionLevel * 2); foreach (var li in lb.Items) { List <string> lir = new List <string>(); bool isFirst = true; foreach (var lib in li.Blocks) { lir.AddRange(BlockProcessing(lib, recursionLevel + 1)); } foreach (string s in lir) { Text.Add((isFirst ? "- " : " ") + s); isFirst = false; } } break; case MarkdownBlockType.ListItemBuilder: break; case MarkdownBlockType.HorizontalRule: Text.Add(TextHelper.HR('-', maxWidth)); break; case MarkdownBlockType.Table: TableBlock tb = (TableBlock)b; int colWidth = maxWidth / tb.ColumnDefinitions.Count; foreach (var tr in tb.Rows) { string trs = string.Empty; foreach (var tc in tr.Cells) { string tcs = string.Empty; foreach (var i in tc.Inlines) { tcs += ProcessInline(i); } trs += TextHelper.Truncate(tcs, colWidth - 1).PadRight(colWidth); } Text.Add(trs); } break; case MarkdownBlockType.LinkReference: break; case MarkdownBlockType.YamlHeader: break; default: break; } return(Text); }
/// <summary> /// Disables focused background /// </summary> protected void MarkCurrentLine() { Write(ANSI.Move(0, currentScreenLine) + ANSI.WriteBackColor(FocusedBackground) + ANSI.ClearCurrentLine + Text[currentLine] + ANSI.WriteMode() + ANSI.RestoreCursorPosition); }