From 711b2599d8d32af652d27697ba55baaad896b57a Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 8 Dec 2018 23:08:51 +0900 Subject: [PATCH 01/18] fix CodeBlock contain "[]" will cause crash --- .../Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs index 7577529af3..768954bb50 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs @@ -34,7 +34,7 @@ public MarkdownFencedCodeBlock(FencedCodeBlock fencedCodeBlock) [BackgroundDependencyLoader] private void load() { - TextFlowContainer textFlowContainer; + MarkdownTextFlowContainer textFlowContainer; InternalChildren = new [] { CreateBackground(), From f9c3823a030ce11f577479123cc3c2693221d280 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 9 Dec 2018 00:01:39 +0900 Subject: [PATCH 02/18] convert relative url to absolute url ref : https://github.com/lunet-io/markdig/issues/74 --- .../Visual/TestCaseMarkdown.cs | 4 +- .../Containers/Markdown/MarkdownContainer.cs | 39 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/osu.Framework.Tests/Visual/TestCaseMarkdown.cs b/osu.Framework.Tests/Visual/TestCaseMarkdown.cs index cdc2a554e0..91840aee85 100644 --- a/osu.Framework.Tests/Visual/TestCaseMarkdown.cs +++ b/osu.Framework.Tests/Visual/TestCaseMarkdown.cs @@ -112,7 +112,9 @@ public TestCaseMarkdown() AddStep("MarkdownFromInternet", () => { - var req = new WebRequest("https://raw.githubusercontent.com/ppy/osu-wiki/master/wiki/Skinning/skin.ini/en.md"); + var url = "https://raw.githubusercontent.com/ppy/osu-wiki/master/wiki/Skinning/skin.ini/en.md"; + markdownContainer.RootUrl = url; + var req = new WebRequest(url); req.Finished += () => markdownContainer.Text = req.ResponseString; Task.Run(() => req.PerformAsync()); diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownContainer.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownContainer.cs index 320957a28d..a040c400ef 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownContainer.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownContainer.cs @@ -1,10 +1,12 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE +using System.Linq; using Markdig; using Markdig.Extensions.AutoIdentifiers; using Markdig.Extensions.Tables; using Markdig.Syntax; +using Markdig.Syntax.Inlines; using osu.Framework.Allocation; using osu.Framework.Caching; using osu.Framework.Graphics.Sprites; @@ -23,6 +25,8 @@ public class MarkdownContainer : CompositeDrawable, IMarkdownTextComponent, IMar private string text = string.Empty; + private string rootUrl = string.Empty; + /// /// The text to visualise. /// @@ -39,6 +43,26 @@ public string Text } } + /// + /// The root url to visualise. + /// + public string RootUrl + { + get => rootUrl; + set + { + if (rootUrl == value) + return; + + rootUrl = value; + + if (string.IsNullOrEmpty(Text)) + return; + + contentCache.Invalidate(); + } + } + /// /// The vertical spacing between lines. /// @@ -106,6 +130,21 @@ private void validateContent() var pipeline = CreateBuilder(); var parsed = Markdig.Markdown.Parse(markdownText, pipeline); + //convert relative path to absolute path + if (!string.IsNullOrEmpty(RootUrl)) + { + var linkInlines = parsed.Descendants().OfType(); + foreach (var linkInline in linkInlines) + { + if (!linkInline.Url.ToLower().StartsWith("http")) + { + var newUrl = rootUrl.Split('/'); + newUrl[newUrl.Length - 1] = linkInline.Url; + linkInline.Url = string.Join("/", newUrl); + } + } + } + document.Clear(); foreach (var component in parsed) AddMarkdownComponent(component, document, root_level); From 54f2356a90580d34efda615d57e8cf4eca292ade Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 9 Dec 2018 01:01:45 +0900 Subject: [PATCH 03/18] oh i forgot Appvery --- osu.Framework.Tests/Visual/TestCaseMarkdown.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Framework.Tests/Visual/TestCaseMarkdown.cs b/osu.Framework.Tests/Visual/TestCaseMarkdown.cs index 91840aee85..b8e91940c5 100644 --- a/osu.Framework.Tests/Visual/TestCaseMarkdown.cs +++ b/osu.Framework.Tests/Visual/TestCaseMarkdown.cs @@ -112,7 +112,7 @@ public TestCaseMarkdown() AddStep("MarkdownFromInternet", () => { - var url = "https://raw.githubusercontent.com/ppy/osu-wiki/master/wiki/Skinning/skin.ini/en.md"; + const string url = "https://raw.githubusercontent.com/ppy/osu-wiki/master/wiki/Skinning/skin.ini/en.md"; markdownContainer.RootUrl = url; var req = new WebRequest(url); req.Finished += () => markdownContainer.Text = req.ResponseString; From 1cf2943478e32894fadbb1470f5c4985f921b432 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Thu, 13 Dec 2018 23:03:45 +0900 Subject: [PATCH 04/18] i don't know why but sometimes markdig made some additional empty line --- .../Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs index 768954bb50..f2ed842f2d 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs @@ -42,7 +42,9 @@ private void load() }; foreach (var line in fencedCodeBlock.Lines.Lines) - textFlowContainer.AddParagraph(line.ToString()); + if (line.Line > 0) + textFlowContainer.AddParagraph(line.ToString()); + } protected virtual Drawable CreateBackground() => new Box From 19297c27087516031676d070064848b4367de8bf Mon Sep 17 00:00:00 2001 From: andy840119 Date: Fri, 14 Dec 2018 00:54:40 +0900 Subject: [PATCH 05/18] hmm... --- .../Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs index f2ed842f2d..8540f92148 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs @@ -44,7 +44,6 @@ private void load() foreach (var line in fencedCodeBlock.Lines.Lines) if (line.Line > 0) textFlowContainer.AddParagraph(line.ToString()); - } protected virtual Drawable CreateBackground() => new Box From 2c45eddfb14bad3ca9148540174349ab53db5c0c Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 16 Dec 2018 12:24:52 +0900 Subject: [PATCH 06/18] oops what am i writing ODOa --- .../Containers/Markdown/MarkdownContainer.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownContainer.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownContainer.cs index a040c400ef..e3a2aa13bf 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownContainer.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownContainer.cs @@ -1,7 +1,9 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE +using System; using System.Linq; +using System.Text.RegularExpressions; using Markdig; using Markdig.Extensions.AutoIdentifiers; using Markdig.Extensions.Tables; @@ -44,7 +46,7 @@ public string Text } /// - /// The root url to visualise. + /// Root url for relative link in document. /// public string RootUrl { @@ -136,11 +138,12 @@ private void validateContent() var linkInlines = parsed.Descendants().OfType(); foreach (var linkInline in linkInlines) { - if (!linkInline.Url.ToLower().StartsWith("http")) + var url = linkInline.Url; + if (!string.IsNullOrEmpty(url) && !Regex.IsMatch(url, @"(http|https)://(([www\.])?|([\da-z-\.]+))\.([a-z\.]{2,3})$")) { - var newUrl = rootUrl.Split('/'); - newUrl[newUrl.Length - 1] = linkInline.Url; - linkInline.Url = string.Join("/", newUrl); + var baseUri = new Uri(RootUrl); + var relativeUri = new Uri(baseUri, url); + linkInline.Url = relativeUri.AbsoluteUri; } } } From 74b2a01acfd0ff9e2c177a6ba835820881c621d8 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 23 Dec 2018 22:11:39 +0900 Subject: [PATCH 07/18] almost there maybe ODOa --- .../Visual/TestCaseMarkdown.cs | 22 +++ .../Markdown/MarkdownCodeFlowContainer.cs | 143 ++++++++++++++++++ .../Markdown/MarkdownFencedCodeBlock.cs | 6 +- osu.Framework/osu.Framework.csproj | 1 + 4 files changed, 169 insertions(+), 3 deletions(-) create mode 100644 osu.Framework/Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs diff --git a/osu.Framework.Tests/Visual/TestCaseMarkdown.cs b/osu.Framework.Tests/Visual/TestCaseMarkdown.cs index b8e91940c5..3ff4c232f5 100644 --- a/osu.Framework.Tests/Visual/TestCaseMarkdown.cs +++ b/osu.Framework.Tests/Visual/TestCaseMarkdown.cs @@ -70,6 +70,28 @@ public TestCaseMarkdown() ```"; }); + AddStep("Markdown Fenced Code (CSharp)", () => + { + markdownContainer.Text = @"```csharp +// A Hello World! program in C#. +using System; +namespace HelloWorld +{ + class Hello + { + static void Main() + { + Console.WriteLine(""Hello World!""); + + // Keep the console window open in debug mode. + Console.WriteLine(""Press any key to exit.""); + Console.ReadKey(); + } + } +} +```"; + }); + AddStep("Markdown Table", () => { markdownContainer.Text = diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs new file mode 100644 index 0000000000..52ef343339 --- /dev/null +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs @@ -0,0 +1,143 @@ +using ColorCode; +using ColorCode.Parsing; +using ColorCode.Styling; +using osu.Framework.Allocation; +using osu.Framework.Graphics.Sprites; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using osuTK.Graphics; + +namespace osu.Framework.Graphics.Containers.Markdown +{ + public class MarkdownCodeFlowContainer : CustomizableTextContainer, IMarkdownTextComponent + { + public float TotalTextWidth => Padding.TotalHorizontal + FlowingChildren.Sum(x => x.BoundingBox.Size.X); + + [Resolved] + private IMarkdownTextComponent parentTextComponent { get; set; } + + public MarkdownCodeFlowContainer() + { + RelativeSizeAxes = Axes.X; + AutoSizeAxes = Axes.Y; + } + + public new void AddText(string text, Action creationParameters = null) + => base.AddText(text.Replace("[", "[[").Replace("]", "]]"), creationParameters); + + public void AddCodeText(string codeText,string language) + { + if(string.IsNullOrEmpty(codeText)) + AddParagraph(""); + + if (string.IsNullOrEmpty(language)) + { + AddText(codeText); + } + else + { + var formatter = new LazerClassFormatter(); + var codeScopes = formatter.GetHtmlString(codeText, Languages.CSharp); + + foreach (var codeScope in codeScopes) + { + AddText(codeScope.ParsedSourceCode,x => x.Colour = codeScope.Foreground); + } + + AddParagraph(""); + } + } + + SpriteText IMarkdownTextComponent.CreateSpriteText() => CreateSpriteText(); + + public class LazerClassFormatter : CodeColorizerBase + { + /// + /// Creates a , for creating HTML to display Syntax Highlighted code, with Styles applied via CSS. + /// + /// The Custom styles to Apply to the formatted Code. + /// The language parser that the instance will use for its lifetime. + public LazerClassFormatter(StyleDictionary Style = null, ILanguageParser languageParser = null) : base(Style, languageParser) + { + + } + + private List CodeScopes = new List(); + + /// + /// Creates the HTML Markup, which can be saved to a .html file. + /// + /// The source code to colorize. + /// The language to use to colorize the source code. + /// Colorised HTML Markup. + public List GetHtmlString(string sourceCode, ILanguage language) + { + CodeScopes.Clear(); + + languageParser.Parse(sourceCode, language, (parsedSourceCode, captures) => Write(parsedSourceCode, captures)); + + return CodeScopes; + } + + protected override void Write(string parsedSourceCode, IList scopes) + { + var scopeName = scopes.FirstOrDefault()?.Name; + var color = Color4.White; + if (!string.IsNullOrEmpty(scopeName) && Styles.Contains(scopeName)) + { + var colorText = Styles[scopeName].Foreground; + color = Color4.Aqua; + } + + var codeScope = new CodeScope + { + ParsedSourceCode = parsedSourceCode, + Foreground = color + }; + + CodeScopes.Add(codeScope); + } + } + + public class CodeScope + { + /// + /// Gets or sets the parsed source code + /// + /// The background color. + public string ParsedSourceCode { get; set; } + + /// + /// Gets or sets the background color. + /// + /// The background color. + public Color4? BackgroundColour { get; set; } + + /// + /// Gets or sets the foreground color. + /// + /// The foreground color. + public Color4 Foreground { get; set; } + + /// + /// Gets or sets the name of the scope the style defines. + /// + /// The name of the scope the style defines. + public string ScopeName { get; set; } + + /// + /// Gets or sets italic font style. + /// + /// True if italic. + public bool Italic { get; set; } + + /// + /// Gets or sets bold font style. + /// + /// True if bold. + public bool Bold { get; set; } + } + } +} diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs index 8540f92148..06dbb2a3a4 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs @@ -34,16 +34,16 @@ public MarkdownFencedCodeBlock(FencedCodeBlock fencedCodeBlock) [BackgroundDependencyLoader] private void load() { - MarkdownTextFlowContainer textFlowContainer; + MarkdownCodeFlowContainer textFlowContainer; InternalChildren = new [] { CreateBackground(), - textFlowContainer = CreateTextFlow(), + textFlowContainer = new MarkdownCodeFlowContainer(), }; foreach (var line in fencedCodeBlock.Lines.Lines) if (line.Line > 0) - textFlowContainer.AddParagraph(line.ToString()); + textFlowContainer.AddCodeText(line.ToString(), fencedCodeBlock.Info); } protected virtual Drawable CreateBackground() => new Box diff --git a/osu.Framework/osu.Framework.csproj b/osu.Framework/osu.Framework.csproj index 8442821246..f137b2c672 100644 --- a/osu.Framework/osu.Framework.csproj +++ b/osu.Framework/osu.Framework.csproj @@ -32,6 +32,7 @@ $(DefineConstants);JETBRAINS_ANNOTATIONS + From 4c85d2205188be6fbfe5a5354e9a639825783df6 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 23 Dec 2018 22:39:33 +0900 Subject: [PATCH 08/18] change format . TODO : change string to Color4 first --- .../Markdown/MarkdownCodeFlowContainer.cs | 53 +-- .../Containers/Markdown/MarkdownCodeStyle.cs | 319 ++++++++++++++++++ 2 files changed, 335 insertions(+), 37 deletions(-) create mode 100644 osu.Framework/Graphics/Containers/Markdown/MarkdownCodeStyle.cs diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs index 52ef343339..59204aaedd 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs @@ -8,6 +8,7 @@ using System.Linq; using System.Text; using osuTK.Graphics; +using System.Collections.ObjectModel; namespace osu.Framework.Graphics.Containers.Markdown { @@ -38,12 +39,12 @@ public void AddCodeText(string codeText,string language) } else { - var formatter = new LazerClassFormatter(); + var formatter = new LazerClassFormatter(Styles); var codeScopes = formatter.GetHtmlString(codeText, Languages.CSharp); foreach (var codeScope in codeScopes) { - AddText(codeScope.ParsedSourceCode,x => x.Colour = codeScope.Foreground); + AddText(codeScope.ParsedSourceCode,x => x.Colour = codeScope.CodeStyle.Foreground); } AddParagraph(""); @@ -52,20 +53,24 @@ public void AddCodeText(string codeText,string language) SpriteText IMarkdownTextComponent.CreateSpriteText() => CreateSpriteText(); + protected virtual MarkdownCodeStyle Styles => new MarkdownCodeStyle().CreateDefaultStyle(); + public class LazerClassFormatter : CodeColorizerBase { /// /// Creates a , for creating HTML to display Syntax Highlighted code, with Styles applied via CSS. /// - /// The Custom styles to Apply to the formatted Code. + /// The Custom styles to Apply to the formatted Code. /// The language parser that the instance will use for its lifetime. - public LazerClassFormatter(StyleDictionary Style = null, ILanguageParser languageParser = null) : base(Style, languageParser) + public LazerClassFormatter(MarkdownCodeStyle style, ILanguageParser languageParser = null) : base(null, languageParser) { - + markdownCodeStyle = style; } private List CodeScopes = new List(); + private MarkdownCodeStyle markdownCodeStyle; + /// /// Creates the HTML Markup, which can be saved to a .html file. /// @@ -84,17 +89,16 @@ public List GetHtmlString(string sourceCode, ILanguage language) protected override void Write(string parsedSourceCode, IList scopes) { var scopeName = scopes.FirstOrDefault()?.Name; - var color = Color4.White; - if (!string.IsNullOrEmpty(scopeName) && Styles.Contains(scopeName)) + var style = new MarkdownCodeStyle.Style("unknown"); + if (!string.IsNullOrEmpty(scopeName) && markdownCodeStyle.Contains(scopeName)) { - var colorText = Styles[scopeName].Foreground; - color = Color4.Aqua; + style = markdownCodeStyle[scopeName]; } var codeScope = new CodeScope { ParsedSourceCode = parsedSourceCode, - Foreground = color + CodeStyle = style }; CodeScopes.Add(codeScope); @@ -110,34 +114,9 @@ public class CodeScope public string ParsedSourceCode { get; set; } /// - /// Gets or sets the background color. - /// - /// The background color. - public Color4? BackgroundColour { get; set; } - - /// - /// Gets or sets the foreground color. - /// - /// The foreground color. - public Color4 Foreground { get; set; } - - /// - /// Gets or sets the name of the scope the style defines. - /// - /// The name of the scope the style defines. - public string ScopeName { get; set; } - - /// - /// Gets or sets italic font style. - /// - /// True if italic. - public bool Italic { get; set; } - - /// - /// Gets or sets bold font style. + /// Gets or sets the parsed code style /// - /// True if bold. - public bool Bold { get; set; } + public MarkdownCodeStyle.Style CodeStyle { get; set; } } } } diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeStyle.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeStyle.cs new file mode 100644 index 0000000000..c6539ae9f6 --- /dev/null +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeStyle.cs @@ -0,0 +1,319 @@ +using osuTK.Graphics; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using ColorCode.Common; + +namespace osu.Framework.Graphics.Containers.Markdown +{ + public class MarkdownCodeStyle : KeyedCollection + { + protected override string GetKeyForItem(Style item) + { + return item.ScopeName; + } + + protected virtual string Blue => "#FF0000FF"; + protected virtual string White => "#FFFFFFFF"; + protected virtual string Black => "#FF000000"; + protected virtual string DullRed => "#FFA31515"; + protected virtual string Yellow => "#FFFFFF00"; + protected virtual string Green => "#FF008000"; + protected virtual string PowderBlue => "#FFB0E0E6"; + protected virtual string Teal => "#FF008080"; + protected virtual string Gray => "#FF808080"; + protected virtual string Navy => "#FF000080"; + protected virtual string OrangeRed => "#FFFF4500"; + protected virtual string Purple => "#FF800080"; + protected virtual string Red => "#FFFF0000"; + protected virtual string MediumTurqoise => "FF48D1CC"; + protected virtual string Magenta => "FFFF00FF"; + protected virtual string OliveDrab => "#FF6B8E23"; + protected virtual string DarkOliveGreen => "#FF556B2F"; + protected virtual string DarkCyan => "#FF008B8B"; + + protected virtual string VSDarkBackground => "#FF1E1E1E"; + protected virtual string VSDarkPlainText => "#FFDADADA"; + + protected virtual string VSDarkXMLDelimeter => "#FF808080"; + protected virtual string VSDarkXMLName => "#FF#E6E6E6"; + protected virtual string VSDarkXMLAttribute => "#FF92CAF4"; + protected virtual string VSDarkXAMLCData => "#FFC0D088"; + protected virtual string VSDarkXMLComment => "#FF608B4E"; + + protected virtual string VSDarkComment => "#FF57A64A"; + protected virtual string VSDarkKeyword => "#FF569CD6"; + protected virtual string VSDarkGray => "#FF9B9B9B"; + protected virtual string VSDarkNumber => "#FFB5CEA8"; + protected virtual string VSDarkClass => "#FF4EC9B0"; + protected virtual string VSDarkString => "#FFD69D85"; + + public virtual MarkdownCodeStyle CreateDefaultStyle() + { + return new MarkdownCodeStyle + { + new Style(ScopeName.PlainText) + { + Foreground = VSDarkPlainText, + Background = VSDarkBackground, + }, + new Style(ScopeName.HtmlServerSideScript) + { + Background = Yellow, + }, + new Style(ScopeName.HtmlComment) + { + Foreground = VSDarkComment, + }, + new Style(ScopeName.HtmlTagDelimiter) + { + Foreground = VSDarkKeyword, + }, + new Style(ScopeName.HtmlElementName) + { + Foreground = DullRed, + }, + new Style(ScopeName.HtmlAttributeName) + { + Foreground = Red, + }, + new Style(ScopeName.HtmlAttributeValue) + { + Foreground = VSDarkKeyword, + }, + new Style(ScopeName.HtmlOperator) + { + Foreground = VSDarkKeyword, + }, + new Style(ScopeName.Comment) + { + Foreground = VSDarkComment, + }, + new Style(ScopeName.XmlDocTag) + { + Foreground = VSDarkXMLComment, + }, + new Style(ScopeName.XmlDocComment) + { + Foreground = VSDarkXMLComment, + }, + new Style(ScopeName.String) + { + Foreground = VSDarkString, + }, + new Style(ScopeName.StringCSharpVerbatim) + { + Foreground = VSDarkString, + }, + new Style(ScopeName.Keyword) + { + Foreground = VSDarkKeyword, + }, + new Style(ScopeName.PreprocessorKeyword) + { + Foreground = VSDarkKeyword, + }, + new Style(ScopeName.HtmlEntity) + { + Foreground = Red, + }, + new Style(ScopeName.XmlAttribute) + { + Foreground = VSDarkXMLAttribute, + }, + new Style(ScopeName.XmlAttributeQuotes) + { + Foreground = VSDarkKeyword, + }, + new Style(ScopeName.XmlAttributeValue) + { + Foreground = VSDarkKeyword, + }, + new Style(ScopeName.XmlCDataSection) + { + Foreground = VSDarkXAMLCData, + }, + new Style(ScopeName.XmlComment) + { + Foreground = VSDarkComment, + }, + new Style(ScopeName.XmlDelimiter) + { + Foreground = VSDarkXMLDelimeter, + }, + new Style(ScopeName.XmlName) + { + Foreground = VSDarkXMLName, + }, + new Style(ScopeName.ClassName) + { + Foreground = VSDarkClass, + }, + new Style(ScopeName.CssSelector) + { + Foreground = DullRed, + }, + new Style(ScopeName.CssPropertyName) + { + Foreground = Red, + }, + new Style(ScopeName.CssPropertyValue) + { + Foreground = VSDarkKeyword, + }, + new Style(ScopeName.SqlSystemFunction) + { + Foreground = Magenta, + }, + new Style(ScopeName.PowerShellAttribute) + { + Foreground = PowderBlue, + }, + new Style(ScopeName.PowerShellOperator) + { + Foreground = VSDarkGray, + }, + new Style(ScopeName.PowerShellType) + { + Foreground = Teal, + }, + new Style(ScopeName.PowerShellVariable) + { + Foreground = OrangeRed, + }, + + new Style(ScopeName.Type) + { + Foreground = Teal, + }, + new Style(ScopeName.TypeVariable) + { + Foreground = Teal, + Italic = true, + }, + new Style(ScopeName.NameSpace) + { + Foreground = Navy, + }, + new Style(ScopeName.Constructor) + { + Foreground = Purple, + }, + new Style(ScopeName.Predefined) + { + Foreground = Navy, + }, + new Style(ScopeName.PseudoKeyword) + { + Foreground = Navy, + }, + new Style(ScopeName.StringEscape) + { + Foreground = VSDarkGray, + }, + new Style(ScopeName.ControlKeyword) + { + Foreground = VSDarkKeyword, + }, + new Style(ScopeName.Number) + { + Foreground = VSDarkNumber + }, + new Style(ScopeName.Operator) + { + + }, + new Style(ScopeName.Delimiter) + { + + }, + + new Style(ScopeName.MarkdownHeader) + { + Foreground = VSDarkKeyword, + Bold = true, + }, + new Style(ScopeName.MarkdownCode) + { + Foreground = VSDarkString, + }, + new Style(ScopeName.MarkdownListItem) + { + Bold = true, + }, + new Style(ScopeName.MarkdownEmph) + { + Italic = true, + }, + new Style(ScopeName.MarkdownBold) + { + Bold = true, + }, + + new Style(ScopeName.BuiltinFunction) + { + Foreground = OliveDrab, + Bold = true, + }, + new Style(ScopeName.BuiltinValue) + { + Foreground = DarkOliveGreen, + Bold = true, + }, + new Style(ScopeName.Attribute) + { + Foreground = DarkCyan, + Italic = true, + }, + new Style(ScopeName.SpecialCharacter) + { + + }, + }; + } + + public class Style + { + /// + /// Initializes a new instance of the class. + /// + /// The name of the scope the style defines. + public Style(string scopeName) + { + ScopeName = scopeName; + } + + /// + /// Gets or sets the background color. + /// + /// The background color. + public Color4? Background{ get; set; } + + /// + /// Gets or sets the foreground color. + /// + /// The foreground color. + public Color4 Foreground { get; set; } + + /// + /// Gets or sets the name of the scope the style defines. + /// + /// The name of the scope the style defines. + public string ScopeName { get; set; } + + /// + /// Gets or sets italic font style. + /// + /// True if italic. + public bool Italic { get; set; } + + /// + /// Gets or sets bold font style. + /// + /// True if bold. + public bool Bold { get; set; } + } + } +} From 8cc7b2a230a4900add8d6faf0b4327eb5b5544d1 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 23 Dec 2018 23:29:38 +0900 Subject: [PATCH 09/18] 1. make it compilable 2. add IMarkdownCodeFlowComponent 3. mode something overridable --- .../Markdown/IMarkdownCodeFlowComponent.cs | 18 ++++++ .../Markdown/MarkdownCodeFlowContainer.cs | 9 +-- .../Containers/Markdown/MarkdownCodeStyle.cs | 63 ++++++++++--------- .../Containers/Markdown/MarkdownContainer.cs | 5 +- .../Markdown/MarkdownFencedCodeBlock.cs | 10 +-- 5 files changed, 64 insertions(+), 41 deletions(-) create mode 100644 osu.Framework/Graphics/Containers/Markdown/IMarkdownCodeFlowComponent.cs diff --git a/osu.Framework/Graphics/Containers/Markdown/IMarkdownCodeFlowComponent.cs b/osu.Framework/Graphics/Containers/Markdown/IMarkdownCodeFlowComponent.cs new file mode 100644 index 0000000000..3d8b3b23ad --- /dev/null +++ b/osu.Framework/Graphics/Containers/Markdown/IMarkdownCodeFlowComponent.cs @@ -0,0 +1,18 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE + +namespace osu.Framework.Graphics.Containers.Markdown +{ + public interface IMarkdownCodeFlowComponent + { + /// + /// Creates a to display text within this . + /// + /// + /// The defined by the is used by default, + /// but may be overridden via this method to provide additional styling local to this . + /// + /// The . + MarkdownCodeFlowContainer CreateCodeFlow(); + } +} diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs index 59204aaedd..b3c434a8c6 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs @@ -47,6 +47,7 @@ public void AddCodeText(string codeText,string language) AddText(codeScope.ParsedSourceCode,x => x.Colour = codeScope.CodeStyle.Foreground); } + //Change new line AddParagraph(""); } } @@ -67,7 +68,7 @@ public LazerClassFormatter(MarkdownCodeStyle style, ILanguageParser languagePars markdownCodeStyle = style; } - private List CodeScopes = new List(); + private List codeScopes = new List(); private MarkdownCodeStyle markdownCodeStyle; @@ -79,11 +80,11 @@ public LazerClassFormatter(MarkdownCodeStyle style, ILanguageParser languagePars /// Colorised HTML Markup. public List GetHtmlString(string sourceCode, ILanguage language) { - CodeScopes.Clear(); + codeScopes.Clear(); languageParser.Parse(sourceCode, language, (parsedSourceCode, captures) => Write(parsedSourceCode, captures)); - return CodeScopes; + return codeScopes; } protected override void Write(string parsedSourceCode, IList scopes) @@ -101,7 +102,7 @@ protected override void Write(string parsedSourceCode, IList scopes) CodeStyle = style }; - CodeScopes.Add(codeScope); + codeScopes.Add(codeScope); } } diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeStyle.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeStyle.cs index c6539ae9f6..51466af8ec 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeStyle.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeStyle.cs @@ -15,40 +15,40 @@ protected override string GetKeyForItem(Style item) return item.ScopeName; } - protected virtual string Blue => "#FF0000FF"; - protected virtual string White => "#FFFFFFFF"; - protected virtual string Black => "#FF000000"; - protected virtual string DullRed => "#FFA31515"; - protected virtual string Yellow => "#FFFFFF00"; - protected virtual string Green => "#FF008000"; - protected virtual string PowderBlue => "#FFB0E0E6"; - protected virtual string Teal => "#FF008080"; - protected virtual string Gray => "#FF808080"; - protected virtual string Navy => "#FF000080"; - protected virtual string OrangeRed => "#FFFF4500"; - protected virtual string Purple => "#FF800080"; - protected virtual string Red => "#FFFF0000"; - protected virtual string MediumTurqoise => "FF48D1CC"; - protected virtual string Magenta => "FFFF00FF"; - protected virtual string OliveDrab => "#FF6B8E23"; - protected virtual string DarkOliveGreen => "#FF556B2F"; - protected virtual string DarkCyan => "#FF008B8B"; + protected virtual Color4 Blue => new Color4(0,0,255,255); //"#0000FF" + protected virtual Color4 White => new Color4(255,255,255,255); //"#FFFFFF" + protected virtual Color4 Black => new Color4(0,0,0,255); //"#000000" + protected virtual Color4 DullRed => new Color4(163, 21, 21, 255);//"#A31515" + protected virtual Color4 Yellow => new Color4(255, 255, 0,255);//"#FFFF00" + protected virtual Color4 Green => new Color4(0, 128, 0,255);//"#008000" + protected virtual Color4 PowderBlue => new Color4(176, 224, 230,255);//"#B0E0E6"; + protected virtual Color4 Teal => new Color4(0, 128, 12,255);//"#008080"; + protected virtual Color4 Gray => new Color4(128, 128, 128,255);//"#808080"; + protected virtual Color4 Navy => new Color4(0, 0, 128,255);//"#000080"; + protected virtual Color4 OrangeRed => new Color4(255, 69, 0,255);//"#FF4500"; + protected virtual Color4 Purple => new Color4(128, 0, 128,255);//"#800080"; + protected virtual Color4 Red => new Color4(255, 0, 0,255);//"#FF0000"; + protected virtual Color4 MediumTurqoise => new Color4(72, 209, 204,255);//"48D1CC"; + protected virtual Color4 Magenta => new Color4(255, 0, 255,255);//"FF00FF"; + protected virtual Color4 OliveDrab =>new Color4(107, 142, 35,255);//"#6B8E23"; + protected virtual Color4 DarkOliveGreen => new Color4(85, 107, 47,255);//"#556B2F"; + protected virtual Color4 DarkCyan => new Color4(0, 139, 139,255);//"#008B8B"; - protected virtual string VSDarkBackground => "#FF1E1E1E"; - protected virtual string VSDarkPlainText => "#FFDADADA"; + protected virtual Color4 VSDarkBackground => new Color4(30, 30, 30,255);//"#1E1E1E"; + protected virtual Color4 VSDarkPlainText => new Color4(218, 218, 218,255);//"#DADADA"; - protected virtual string VSDarkXMLDelimeter => "#FF808080"; - protected virtual string VSDarkXMLName => "#FF#E6E6E6"; - protected virtual string VSDarkXMLAttribute => "#FF92CAF4"; - protected virtual string VSDarkXAMLCData => "#FFC0D088"; - protected virtual string VSDarkXMLComment => "#FF608B4E"; + protected virtual Color4 VSDarkXMLDelimeter => new Color4(128, 128, 128,255);//"#808080"; + protected virtual Color4 VSDarkXMLName => new Color4(230, 230, 230,255);//"#E6E6E6"; + protected virtual Color4 VSDarkXMLAttribute => new Color4(146, 202, 244,255);//"#92CAF4"; + protected virtual Color4 VSDarkXAMLCData => new Color4(192, 208, 136,255);//"#C0D088"; + protected virtual Color4 VSDarkXMLComment => new Color4(96, 139, 78,255);//"#608B4E"; - protected virtual string VSDarkComment => "#FF57A64A"; - protected virtual string VSDarkKeyword => "#FF569CD6"; - protected virtual string VSDarkGray => "#FF9B9B9B"; - protected virtual string VSDarkNumber => "#FFB5CEA8"; - protected virtual string VSDarkClass => "#FF4EC9B0"; - protected virtual string VSDarkString => "#FFD69D85"; + protected virtual Color4 VSDarkComment => new Color4(87, 166, 74,255);//"#57A64A"; + protected virtual Color4 VSDarkKeyword =>new Color4(86, 156, 214,255);//"#569CD6"; + protected virtual Color4 VSDarkGray => new Color4(155, 155, 155,255);//"#9B9B9B"; + protected virtual Color4 VSDarkNumber => new Color4(181, 206, 168,255);//"#B5CEA8"; + protected virtual Color4 VSDarkClass =>new Color4(78, 201, 176,255);//"#4EC9B0"; + protected virtual Color4 VSDarkString =>new Color4(214, 157, 133,255);//"#D69D85" public virtual MarkdownCodeStyle CreateDefaultStyle() { @@ -283,6 +283,7 @@ public class Style public Style(string scopeName) { ScopeName = scopeName; + Foreground = Color4.White; } /// diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownContainer.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownContainer.cs index e3a2aa13bf..15e86140f6 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownContainer.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownContainer.cs @@ -21,7 +21,8 @@ namespace osu.Framework.Graphics.Containers.Markdown /// [Cached(Type = typeof(IMarkdownTextComponent))] [Cached(Type = typeof(IMarkdownTextFlowComponent))] - public class MarkdownContainer : CompositeDrawable, IMarkdownTextComponent, IMarkdownTextFlowComponent + [Cached(Type = typeof(IMarkdownCodeFlowComponent))] + public class MarkdownContainer : CompositeDrawable, IMarkdownTextComponent, IMarkdownTextFlowComponent , IMarkdownCodeFlowComponent { private const int root_level = 0; @@ -165,6 +166,8 @@ protected override void Update() public virtual MarkdownTextFlowContainer CreateTextFlow() => new MarkdownTextFlowContainer(); + public virtual MarkdownCodeFlowContainer CreateCodeFlow() => new MarkdownCodeFlowContainer(); + public virtual SpriteText CreateSpriteText() => new SpriteText(); /// diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs index 06dbb2a3a4..6c011fcb42 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs @@ -16,12 +16,12 @@ namespace osu.Framework.Graphics.Containers.Markdown /// code /// ``` /// - public class MarkdownFencedCodeBlock : CompositeDrawable, IMarkdownTextFlowComponent + public class MarkdownFencedCodeBlock : CompositeDrawable, IMarkdownCodeFlowComponent { private readonly FencedCodeBlock fencedCodeBlock; [Resolved] - private IMarkdownTextFlowComponent parentFlowComponent { get; set; } + private IMarkdownCodeFlowComponent parentFlowComponent { get; set; } public MarkdownFencedCodeBlock(FencedCodeBlock fencedCodeBlock) { @@ -38,7 +38,7 @@ private void load() InternalChildren = new [] { CreateBackground(), - textFlowContainer = new MarkdownCodeFlowContainer(), + textFlowContainer = CreateCodeFlow(), }; foreach (var line in fencedCodeBlock.Lines.Lines) @@ -53,9 +53,9 @@ private void load() Alpha = 0.5f }; - public virtual MarkdownTextFlowContainer CreateTextFlow() + public virtual MarkdownCodeFlowContainer CreateCodeFlow() { - var textFlow = parentFlowComponent.CreateTextFlow(); + var textFlow = parentFlowComponent.CreateCodeFlow(); textFlow.Margin = new MarginPadding { Left = 10, Right = 10, Top = 10, Bottom = 10 }; return textFlow; } From 5b3d7f3bd0d3e3e651f0c056d2d7f1adb71d1f59 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 24 Dec 2018 01:00:43 +0900 Subject: [PATCH 10/18] modified some coding style --- .../Markdown/MarkdownCodeFlowContainer.cs | 98 ++++++------- .../Containers/Markdown/MarkdownCodeStyle.cs | 130 ++++++++---------- 2 files changed, 109 insertions(+), 119 deletions(-) diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs index b3c434a8c6..6374658094 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs @@ -1,21 +1,18 @@ -using ColorCode; +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE + +using ColorCode; using ColorCode.Parsing; -using ColorCode.Styling; using osu.Framework.Allocation; using osu.Framework.Graphics.Sprites; using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using osuTK.Graphics; -using System.Collections.ObjectModel; namespace osu.Framework.Graphics.Containers.Markdown { public class MarkdownCodeFlowContainer : CustomizableTextContainer, IMarkdownTextComponent { - public float TotalTextWidth => Padding.TotalHorizontal + FlowingChildren.Sum(x => x.BoundingBox.Size.X); - [Resolved] private IMarkdownTextComponent parentTextComponent { get; set; } @@ -28,27 +25,33 @@ public MarkdownCodeFlowContainer() public new void AddText(string text, Action creationParameters = null) => base.AddText(text.Replace("[", "[[").Replace("]", "]]"), creationParameters); - public void AddCodeText(string codeText,string language) + public void AddCodeText(string codeText,string languageCode) { if(string.IsNullOrEmpty(codeText)) AddParagraph(""); - if (string.IsNullOrEmpty(language)) - { - AddText(codeText); - } + var formatter = new ClassFormatter(Styles); + + var language = Languages.FindById(languageCode); + if (language == null) + AddParagraph(codeText); else { - var formatter = new LazerClassFormatter(Styles); - var codeScopes = formatter.GetHtmlString(codeText, Languages.CSharp); - - foreach (var codeScope in codeScopes) - { - AddText(codeScope.ParsedSourceCode,x => x.Colour = codeScope.CodeStyle.Foreground); - } - //Change new line AddParagraph(""); + + var codeSyntaxes = formatter.GetCodeSyntaxes(codeText, language); + + foreach (var codeSyntax in codeSyntaxes) + AddText(codeSyntax.ParsedSourceCode, + x => + { + var style = codeSyntax.CodeStyle; + if(style == null) + return; + + ApplyCodeText(x, style); + }); } } @@ -56,57 +59,54 @@ public void AddCodeText(string codeText,string language) protected virtual MarkdownCodeStyle Styles => new MarkdownCodeStyle().CreateDefaultStyle(); - public class LazerClassFormatter : CodeColorizerBase + protected virtual void ApplyCodeText(SpriteText text, MarkdownCodeStyle.Style codeStyle) { - /// - /// Creates a , for creating HTML to display Syntax Highlighted code, with Styles applied via CSS. - /// - /// The Custom styles to Apply to the formatted Code. - /// The language parser that the instance will use for its lifetime. - public LazerClassFormatter(MarkdownCodeStyle style, ILanguageParser languageParser = null) : base(null, languageParser) - { - markdownCodeStyle = style; - } + string font = "OpenSans-"; + if (codeStyle.Bold) + font += "Bold"; + if (codeStyle.Italic) + font += "Italic"; + + text.Colour = codeStyle.Foreground; + text.ShadowColour = codeStyle.Background ?? text.ShadowColour; + text.Font = font.Trim('-'); + } - private List codeScopes = new List(); + public class ClassFormatter : CodeColorizerBase + { + private readonly List codeSyntaxes = new List(); - private MarkdownCodeStyle markdownCodeStyle; + private readonly MarkdownCodeStyle markdownCodeStyle; - /// - /// Creates the HTML Markup, which can be saved to a .html file. - /// - /// The source code to colorize. - /// The language to use to colorize the source code. - /// Colorised HTML Markup. - public List GetHtmlString(string sourceCode, ILanguage language) + public ClassFormatter(MarkdownCodeStyle style, ILanguageParser languageParser = null) : base(null, languageParser) { - codeScopes.Clear(); + markdownCodeStyle = style; + } + public List GetCodeSyntaxes(string sourceCode, ILanguage language) + { + codeSyntaxes.Clear(); languageParser.Parse(sourceCode, language, (parsedSourceCode, captures) => Write(parsedSourceCode, captures)); - - return codeScopes; + return codeSyntaxes; } protected override void Write(string parsedSourceCode, IList scopes) { var scopeName = scopes.FirstOrDefault()?.Name; var style = new MarkdownCodeStyle.Style("unknown"); + if (!string.IsNullOrEmpty(scopeName) && markdownCodeStyle.Contains(scopeName)) - { style = markdownCodeStyle[scopeName]; - } - var codeScope = new CodeScope + codeSyntaxes.Add(new CodeSyntax { ParsedSourceCode = parsedSourceCode, CodeStyle = style - }; - - codeScopes.Add(codeScope); + }); } } - public class CodeScope + public class CodeSyntax { /// /// Gets or sets the parsed source code diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeStyle.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeStyle.cs index 51466af8ec..e0b86be3bf 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeStyle.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeStyle.cs @@ -1,9 +1,8 @@ -using osuTK.Graphics; -using System; -using System.Collections.Generic; +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE + +using osuTK.Graphics; using System.Collections.ObjectModel; -using System.Text; -using Microsoft.CodeAnalysis.CSharp.Syntax; using ColorCode.Common; namespace osu.Framework.Graphics.Containers.Markdown @@ -21,34 +20,34 @@ protected override string GetKeyForItem(Style item) protected virtual Color4 DullRed => new Color4(163, 21, 21, 255);//"#A31515" protected virtual Color4 Yellow => new Color4(255, 255, 0,255);//"#FFFF00" protected virtual Color4 Green => new Color4(0, 128, 0,255);//"#008000" - protected virtual Color4 PowderBlue => new Color4(176, 224, 230,255);//"#B0E0E6"; - protected virtual Color4 Teal => new Color4(0, 128, 12,255);//"#008080"; - protected virtual Color4 Gray => new Color4(128, 128, 128,255);//"#808080"; - protected virtual Color4 Navy => new Color4(0, 0, 128,255);//"#000080"; - protected virtual Color4 OrangeRed => new Color4(255, 69, 0,255);//"#FF4500"; - protected virtual Color4 Purple => new Color4(128, 0, 128,255);//"#800080"; - protected virtual Color4 Red => new Color4(255, 0, 0,255);//"#FF0000"; - protected virtual Color4 MediumTurqoise => new Color4(72, 209, 204,255);//"48D1CC"; - protected virtual Color4 Magenta => new Color4(255, 0, 255,255);//"FF00FF"; - protected virtual Color4 OliveDrab =>new Color4(107, 142, 35,255);//"#6B8E23"; - protected virtual Color4 DarkOliveGreen => new Color4(85, 107, 47,255);//"#556B2F"; - protected virtual Color4 DarkCyan => new Color4(0, 139, 139,255);//"#008B8B"; + protected virtual Color4 PowderBlue => new Color4(176, 224, 230,255);//"#B0E0E6" + protected virtual Color4 Teal => new Color4(0, 128, 12,255);//"#008080" + protected virtual Color4 Gray => new Color4(128, 128, 128,255);//"#808080" + protected virtual Color4 Navy => new Color4(0, 0, 128,255);//"#000080" + protected virtual Color4 OrangeRed => new Color4(255, 69, 0,255);//"#FF4500" + protected virtual Color4 Purple => new Color4(128, 0, 128,255);//"#800080" + protected virtual Color4 Red => new Color4(255, 0, 0,255);//"#FF0000" + protected virtual Color4 MediumTurqoise => new Color4(72, 209, 204,255);//"48D1CC" + protected virtual Color4 Magenta => new Color4(255, 0, 255,255);//"FF00FF" + protected virtual Color4 OliveDrab =>new Color4(107, 142, 35,255);//"#6B8E23" + protected virtual Color4 DarkOliveGreen => new Color4(85, 107, 47,255);//"#556B2F" + protected virtual Color4 DarkCyan => new Color4(0, 139, 139,255);//"#008B8B" - protected virtual Color4 VSDarkBackground => new Color4(30, 30, 30,255);//"#1E1E1E"; - protected virtual Color4 VSDarkPlainText => new Color4(218, 218, 218,255);//"#DADADA"; + protected virtual Color4 DarkBackground => new Color4(30, 30, 30,255);//"#1E1E1E" + protected virtual Color4 DarkPlainText => new Color4(218, 218, 218,255);//"#DADADA" - protected virtual Color4 VSDarkXMLDelimeter => new Color4(128, 128, 128,255);//"#808080"; - protected virtual Color4 VSDarkXMLName => new Color4(230, 230, 230,255);//"#E6E6E6"; - protected virtual Color4 VSDarkXMLAttribute => new Color4(146, 202, 244,255);//"#92CAF4"; - protected virtual Color4 VSDarkXAMLCData => new Color4(192, 208, 136,255);//"#C0D088"; - protected virtual Color4 VSDarkXMLComment => new Color4(96, 139, 78,255);//"#608B4E"; + protected virtual Color4 DarkXmlDelimeter => new Color4(128, 128, 128,255);//"#808080" + protected virtual Color4 DarkXmlName => new Color4(230, 230, 230,255);//"#E6E6E6" + protected virtual Color4 DarkXmlAttribute => new Color4(146, 202, 244,255);//"#92CAF4" + protected virtual Color4 DarkXamlCData => new Color4(192, 208, 136,255);//"#C0D088" + protected virtual Color4 DarkXmlComment => new Color4(96, 139, 78,255);//"#608B4E" - protected virtual Color4 VSDarkComment => new Color4(87, 166, 74,255);//"#57A64A"; - protected virtual Color4 VSDarkKeyword =>new Color4(86, 156, 214,255);//"#569CD6"; - protected virtual Color4 VSDarkGray => new Color4(155, 155, 155,255);//"#9B9B9B"; - protected virtual Color4 VSDarkNumber => new Color4(181, 206, 168,255);//"#B5CEA8"; - protected virtual Color4 VSDarkClass =>new Color4(78, 201, 176,255);//"#4EC9B0"; - protected virtual Color4 VSDarkString =>new Color4(214, 157, 133,255);//"#D69D85" + protected virtual Color4 DarkComment => new Color4(87, 166, 74,255);//"#57A64A" + protected virtual Color4 DarkKeyword =>new Color4(86, 156, 214,255);//"#569CD6" + protected virtual Color4 DarkGray => new Color4(155, 155, 155,255);//"#9B9B9B" + protected virtual Color4 DarkNumber => new Color4(181, 206, 168,255);//"#B5CEA8" + protected virtual Color4 DarkClass =>new Color4(78, 201, 176,255);//"#4EC9B0" + protected virtual Color4 DarkString =>new Color4(214, 157, 133,255);//"#D69D85" public virtual MarkdownCodeStyle CreateDefaultStyle() { @@ -56,8 +55,8 @@ public virtual MarkdownCodeStyle CreateDefaultStyle() { new Style(ScopeName.PlainText) { - Foreground = VSDarkPlainText, - Background = VSDarkBackground, + Foreground = DarkPlainText, + Background = DarkBackground, }, new Style(ScopeName.HtmlServerSideScript) { @@ -65,11 +64,11 @@ public virtual MarkdownCodeStyle CreateDefaultStyle() }, new Style(ScopeName.HtmlComment) { - Foreground = VSDarkComment, + Foreground = DarkComment, }, new Style(ScopeName.HtmlTagDelimiter) { - Foreground = VSDarkKeyword, + Foreground = DarkKeyword, }, new Style(ScopeName.HtmlElementName) { @@ -81,39 +80,39 @@ public virtual MarkdownCodeStyle CreateDefaultStyle() }, new Style(ScopeName.HtmlAttributeValue) { - Foreground = VSDarkKeyword, + Foreground = DarkKeyword, }, new Style(ScopeName.HtmlOperator) { - Foreground = VSDarkKeyword, + Foreground = DarkKeyword, }, new Style(ScopeName.Comment) { - Foreground = VSDarkComment, + Foreground = DarkComment, }, new Style(ScopeName.XmlDocTag) { - Foreground = VSDarkXMLComment, + Foreground = DarkXmlComment, }, new Style(ScopeName.XmlDocComment) { - Foreground = VSDarkXMLComment, + Foreground = DarkXmlComment, }, new Style(ScopeName.String) { - Foreground = VSDarkString, + Foreground = DarkString, }, new Style(ScopeName.StringCSharpVerbatim) { - Foreground = VSDarkString, + Foreground = DarkString, }, new Style(ScopeName.Keyword) { - Foreground = VSDarkKeyword, + Foreground = DarkKeyword, }, new Style(ScopeName.PreprocessorKeyword) { - Foreground = VSDarkKeyword, + Foreground = DarkKeyword, }, new Style(ScopeName.HtmlEntity) { @@ -121,35 +120,35 @@ public virtual MarkdownCodeStyle CreateDefaultStyle() }, new Style(ScopeName.XmlAttribute) { - Foreground = VSDarkXMLAttribute, + Foreground = DarkXmlAttribute, }, new Style(ScopeName.XmlAttributeQuotes) { - Foreground = VSDarkKeyword, + Foreground = DarkKeyword, }, new Style(ScopeName.XmlAttributeValue) { - Foreground = VSDarkKeyword, + Foreground = DarkKeyword, }, new Style(ScopeName.XmlCDataSection) { - Foreground = VSDarkXAMLCData, + Foreground = DarkXamlCData, }, new Style(ScopeName.XmlComment) { - Foreground = VSDarkComment, + Foreground = DarkComment, }, new Style(ScopeName.XmlDelimiter) { - Foreground = VSDarkXMLDelimeter, + Foreground = DarkXmlDelimeter, }, new Style(ScopeName.XmlName) { - Foreground = VSDarkXMLName, + Foreground = DarkXmlName, }, new Style(ScopeName.ClassName) { - Foreground = VSDarkClass, + Foreground = DarkClass, }, new Style(ScopeName.CssSelector) { @@ -161,7 +160,7 @@ public virtual MarkdownCodeStyle CreateDefaultStyle() }, new Style(ScopeName.CssPropertyValue) { - Foreground = VSDarkKeyword, + Foreground = DarkKeyword, }, new Style(ScopeName.SqlSystemFunction) { @@ -173,7 +172,7 @@ public virtual MarkdownCodeStyle CreateDefaultStyle() }, new Style(ScopeName.PowerShellOperator) { - Foreground = VSDarkGray, + Foreground = DarkGray, }, new Style(ScopeName.PowerShellType) { @@ -211,33 +210,27 @@ public virtual MarkdownCodeStyle CreateDefaultStyle() }, new Style(ScopeName.StringEscape) { - Foreground = VSDarkGray, + Foreground = DarkGray, }, new Style(ScopeName.ControlKeyword) { - Foreground = VSDarkKeyword, + Foreground = DarkKeyword, }, new Style(ScopeName.Number) { - Foreground = VSDarkNumber - }, - new Style(ScopeName.Operator) - { - - }, - new Style(ScopeName.Delimiter) - { - + Foreground = DarkNumber }, + new Style(ScopeName.Operator), + new Style(ScopeName.Delimiter), new Style(ScopeName.MarkdownHeader) { - Foreground = VSDarkKeyword, + Foreground = DarkKeyword, Bold = true, }, new Style(ScopeName.MarkdownCode) { - Foreground = VSDarkString, + Foreground = DarkString, }, new Style(ScopeName.MarkdownListItem) { @@ -267,10 +260,7 @@ public virtual MarkdownCodeStyle CreateDefaultStyle() Foreground = DarkCyan, Italic = true, }, - new Style(ScopeName.SpecialCharacter) - { - - }, + new Style(ScopeName.SpecialCharacter), }; } From 0d2c5314b912b572b57b3a7ecce8ae8dbb99db96 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 24 Dec 2018 01:02:20 +0900 Subject: [PATCH 11/18] Foregound -> Colour Background -> BackgroundColour --- .../Markdown/MarkdownCodeFlowContainer.cs | 4 +- .../Containers/Markdown/MarkdownCodeStyle.cs | 100 +++++++++--------- 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs index 6374658094..3f54203962 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs @@ -67,8 +67,8 @@ protected virtual void ApplyCodeText(SpriteText text, MarkdownCodeStyle.Style co if (codeStyle.Italic) font += "Italic"; - text.Colour = codeStyle.Foreground; - text.ShadowColour = codeStyle.Background ?? text.ShadowColour; + text.Colour = codeStyle.Colour; + text.ShadowColour = codeStyle.BackgroundColour ?? text.ShadowColour; text.Font = font.Trim('-'); } diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeStyle.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeStyle.cs index e0b86be3bf..3ce98b7b30 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeStyle.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeStyle.cs @@ -55,182 +55,182 @@ public virtual MarkdownCodeStyle CreateDefaultStyle() { new Style(ScopeName.PlainText) { - Foreground = DarkPlainText, - Background = DarkBackground, + Colour = DarkPlainText, + BackgroundColour = DarkBackground, }, new Style(ScopeName.HtmlServerSideScript) { - Background = Yellow, + BackgroundColour = Yellow, }, new Style(ScopeName.HtmlComment) { - Foreground = DarkComment, + Colour = DarkComment, }, new Style(ScopeName.HtmlTagDelimiter) { - Foreground = DarkKeyword, + Colour = DarkKeyword, }, new Style(ScopeName.HtmlElementName) { - Foreground = DullRed, + Colour = DullRed, }, new Style(ScopeName.HtmlAttributeName) { - Foreground = Red, + Colour = Red, }, new Style(ScopeName.HtmlAttributeValue) { - Foreground = DarkKeyword, + Colour = DarkKeyword, }, new Style(ScopeName.HtmlOperator) { - Foreground = DarkKeyword, + Colour = DarkKeyword, }, new Style(ScopeName.Comment) { - Foreground = DarkComment, + Colour = DarkComment, }, new Style(ScopeName.XmlDocTag) { - Foreground = DarkXmlComment, + Colour = DarkXmlComment, }, new Style(ScopeName.XmlDocComment) { - Foreground = DarkXmlComment, + Colour = DarkXmlComment, }, new Style(ScopeName.String) { - Foreground = DarkString, + Colour = DarkString, }, new Style(ScopeName.StringCSharpVerbatim) { - Foreground = DarkString, + Colour = DarkString, }, new Style(ScopeName.Keyword) { - Foreground = DarkKeyword, + Colour = DarkKeyword, }, new Style(ScopeName.PreprocessorKeyword) { - Foreground = DarkKeyword, + Colour = DarkKeyword, }, new Style(ScopeName.HtmlEntity) { - Foreground = Red, + Colour = Red, }, new Style(ScopeName.XmlAttribute) { - Foreground = DarkXmlAttribute, + Colour = DarkXmlAttribute, }, new Style(ScopeName.XmlAttributeQuotes) { - Foreground = DarkKeyword, + Colour = DarkKeyword, }, new Style(ScopeName.XmlAttributeValue) { - Foreground = DarkKeyword, + Colour = DarkKeyword, }, new Style(ScopeName.XmlCDataSection) { - Foreground = DarkXamlCData, + Colour = DarkXamlCData, }, new Style(ScopeName.XmlComment) { - Foreground = DarkComment, + Colour = DarkComment, }, new Style(ScopeName.XmlDelimiter) { - Foreground = DarkXmlDelimeter, + Colour = DarkXmlDelimeter, }, new Style(ScopeName.XmlName) { - Foreground = DarkXmlName, + Colour = DarkXmlName, }, new Style(ScopeName.ClassName) { - Foreground = DarkClass, + Colour = DarkClass, }, new Style(ScopeName.CssSelector) { - Foreground = DullRed, + Colour = DullRed, }, new Style(ScopeName.CssPropertyName) { - Foreground = Red, + Colour = Red, }, new Style(ScopeName.CssPropertyValue) { - Foreground = DarkKeyword, + Colour = DarkKeyword, }, new Style(ScopeName.SqlSystemFunction) { - Foreground = Magenta, + Colour = Magenta, }, new Style(ScopeName.PowerShellAttribute) { - Foreground = PowderBlue, + Colour = PowderBlue, }, new Style(ScopeName.PowerShellOperator) { - Foreground = DarkGray, + Colour = DarkGray, }, new Style(ScopeName.PowerShellType) { - Foreground = Teal, + Colour = Teal, }, new Style(ScopeName.PowerShellVariable) { - Foreground = OrangeRed, + Colour = OrangeRed, }, new Style(ScopeName.Type) { - Foreground = Teal, + Colour = Teal, }, new Style(ScopeName.TypeVariable) { - Foreground = Teal, + Colour = Teal, Italic = true, }, new Style(ScopeName.NameSpace) { - Foreground = Navy, + Colour = Navy, }, new Style(ScopeName.Constructor) { - Foreground = Purple, + Colour = Purple, }, new Style(ScopeName.Predefined) { - Foreground = Navy, + Colour = Navy, }, new Style(ScopeName.PseudoKeyword) { - Foreground = Navy, + Colour = Navy, }, new Style(ScopeName.StringEscape) { - Foreground = DarkGray, + Colour = DarkGray, }, new Style(ScopeName.ControlKeyword) { - Foreground = DarkKeyword, + Colour = DarkKeyword, }, new Style(ScopeName.Number) { - Foreground = DarkNumber + Colour = DarkNumber }, new Style(ScopeName.Operator), new Style(ScopeName.Delimiter), new Style(ScopeName.MarkdownHeader) { - Foreground = DarkKeyword, + Colour = DarkKeyword, Bold = true, }, new Style(ScopeName.MarkdownCode) { - Foreground = DarkString, + Colour = DarkString, }, new Style(ScopeName.MarkdownListItem) { @@ -247,17 +247,17 @@ public virtual MarkdownCodeStyle CreateDefaultStyle() new Style(ScopeName.BuiltinFunction) { - Foreground = OliveDrab, + Colour = OliveDrab, Bold = true, }, new Style(ScopeName.BuiltinValue) { - Foreground = DarkOliveGreen, + Colour = DarkOliveGreen, Bold = true, }, new Style(ScopeName.Attribute) { - Foreground = DarkCyan, + Colour = DarkCyan, Italic = true, }, new Style(ScopeName.SpecialCharacter), @@ -273,20 +273,20 @@ public class Style public Style(string scopeName) { ScopeName = scopeName; - Foreground = Color4.White; + Colour = Color4.White; } /// /// Gets or sets the background color. /// /// The background color. - public Color4? Background{ get; set; } + public Color4? BackgroundColour{ get; set; } /// /// Gets or sets the foreground color. /// /// The foreground color. - public Color4 Foreground { get; set; } + public Color4 Colour { get; set; } /// /// Gets or sets the name of the scope the style defines. From 57100252e75647da059fceabc761837ddfd26e63 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 24 Dec 2018 01:24:17 +0900 Subject: [PATCH 12/18] make appveyor happy --- .../Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs index 3f54203962..66a6743492 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs @@ -86,7 +86,7 @@ public ClassFormatter(MarkdownCodeStyle style, ILanguageParser languageParser = public List GetCodeSyntaxes(string sourceCode, ILanguage language) { codeSyntaxes.Clear(); - languageParser.Parse(sourceCode, language, (parsedSourceCode, captures) => Write(parsedSourceCode, captures)); + languageParser.Parse(sourceCode, language, Write); return codeSyntaxes; } From 2147b9f8ccfa9ef579691f637a2ccc5150add472 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 24 Dec 2018 01:47:46 +0900 Subject: [PATCH 13/18] makes codefactor happy --- .../Containers/Markdown/MarkdownCodeStyle.cs | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeStyle.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeStyle.cs index 3ce98b7b30..ffec1b823a 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeStyle.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeStyle.cs @@ -14,40 +14,40 @@ protected override string GetKeyForItem(Style item) return item.ScopeName; } - protected virtual Color4 Blue => new Color4(0,0,255,255); //"#0000FF" - protected virtual Color4 White => new Color4(255,255,255,255); //"#FFFFFF" - protected virtual Color4 Black => new Color4(0,0,0,255); //"#000000" - protected virtual Color4 DullRed => new Color4(163, 21, 21, 255);//"#A31515" - protected virtual Color4 Yellow => new Color4(255, 255, 0,255);//"#FFFF00" - protected virtual Color4 Green => new Color4(0, 128, 0,255);//"#008000" - protected virtual Color4 PowderBlue => new Color4(176, 224, 230,255);//"#B0E0E6" - protected virtual Color4 Teal => new Color4(0, 128, 12,255);//"#008080" - protected virtual Color4 Gray => new Color4(128, 128, 128,255);//"#808080" - protected virtual Color4 Navy => new Color4(0, 0, 128,255);//"#000080" - protected virtual Color4 OrangeRed => new Color4(255, 69, 0,255);//"#FF4500" - protected virtual Color4 Purple => new Color4(128, 0, 128,255);//"#800080" - protected virtual Color4 Red => new Color4(255, 0, 0,255);//"#FF0000" - protected virtual Color4 MediumTurqoise => new Color4(72, 209, 204,255);//"48D1CC" - protected virtual Color4 Magenta => new Color4(255, 0, 255,255);//"FF00FF" - protected virtual Color4 OliveDrab =>new Color4(107, 142, 35,255);//"#6B8E23" - protected virtual Color4 DarkOliveGreen => new Color4(85, 107, 47,255);//"#556B2F" - protected virtual Color4 DarkCyan => new Color4(0, 139, 139,255);//"#008B8B" + protected virtual Color4 Blue => new Color4(0,0,255,255); + protected virtual Color4 White => new Color4(255,255,255,255); + protected virtual Color4 Black => new Color4(0,0,0,255); + protected virtual Color4 DullRed => new Color4(163, 21, 21, 255); + protected virtual Color4 Yellow => new Color4(255, 255, 0,255); + protected virtual Color4 Green => new Color4(0, 128, 0,255); + protected virtual Color4 PowderBlue => new Color4(176, 224, 230,255); + protected virtual Color4 Teal => new Color4(0, 128, 12,255); + protected virtual Color4 Gray => new Color4(128, 128, 128,255); + protected virtual Color4 Navy => new Color4(0, 0, 128,255); + protected virtual Color4 OrangeRed => new Color4(255, 69, 0,255); + protected virtual Color4 Purple => new Color4(128, 0, 128,255); + protected virtual Color4 Red => new Color4(255, 0, 0,255); + protected virtual Color4 MediumTurqoise => new Color4(72, 209, 204,255); + protected virtual Color4 Magenta => new Color4(255, 0, 255,255); + protected virtual Color4 OliveDrab =>new Color4(107, 142, 35,255); + protected virtual Color4 DarkOliveGreen => new Color4(85, 107, 47,255); + protected virtual Color4 DarkCyan => new Color4(0, 139, 139,255); - protected virtual Color4 DarkBackground => new Color4(30, 30, 30,255);//"#1E1E1E" - protected virtual Color4 DarkPlainText => new Color4(218, 218, 218,255);//"#DADADA" + protected virtual Color4 DarkBackground => new Color4(30, 30, 30,255); + protected virtual Color4 DarkPlainText => new Color4(218, 218, 218,255); - protected virtual Color4 DarkXmlDelimeter => new Color4(128, 128, 128,255);//"#808080" - protected virtual Color4 DarkXmlName => new Color4(230, 230, 230,255);//"#E6E6E6" - protected virtual Color4 DarkXmlAttribute => new Color4(146, 202, 244,255);//"#92CAF4" - protected virtual Color4 DarkXamlCData => new Color4(192, 208, 136,255);//"#C0D088" - protected virtual Color4 DarkXmlComment => new Color4(96, 139, 78,255);//"#608B4E" + protected virtual Color4 DarkXmlDelimeter => new Color4(128, 128, 128,255); + protected virtual Color4 DarkXmlName => new Color4(230, 230, 230,255); + protected virtual Color4 DarkXmlAttribute => new Color4(146, 202, 244,255); + protected virtual Color4 DarkXamlCData => new Color4(192, 208, 136,255); + protected virtual Color4 DarkXmlComment => new Color4(96, 139, 78,255); - protected virtual Color4 DarkComment => new Color4(87, 166, 74,255);//"#57A64A" - protected virtual Color4 DarkKeyword =>new Color4(86, 156, 214,255);//"#569CD6" - protected virtual Color4 DarkGray => new Color4(155, 155, 155,255);//"#9B9B9B" - protected virtual Color4 DarkNumber => new Color4(181, 206, 168,255);//"#B5CEA8" - protected virtual Color4 DarkClass =>new Color4(78, 201, 176,255);//"#4EC9B0" - protected virtual Color4 DarkString =>new Color4(214, 157, 133,255);//"#D69D85" + protected virtual Color4 DarkComment => new Color4(87, 166, 74,255); + protected virtual Color4 DarkKeyword =>new Color4(86, 156, 214,255); + protected virtual Color4 DarkGray => new Color4(155, 155, 155,255); + protected virtual Color4 DarkNumber => new Color4(181, 206, 168,255); + protected virtual Color4 DarkClass =>new Color4(78, 201, 176,255); + protected virtual Color4 DarkString =>new Color4(214, 157, 133,255); public virtual MarkdownCodeStyle CreateDefaultStyle() { From 6c47492cf0fe5470754cbf3995b9bfe5002a02f4 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Wed, 9 Jan 2019 00:08:53 +0900 Subject: [PATCH 14/18] fix code quality issue. --- .../Containers/Markdown/MarkdownContainer.cs | 13 +++++++------ .../Containers/Markdown/MarkdownFencedCodeBlock.cs | 8 +++++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownContainer.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownContainer.cs index e3a2aa13bf..df933e728e 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownContainer.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownContainer.cs @@ -55,12 +55,8 @@ public string RootUrl { if (rootUrl == value) return; - rootUrl = value; - if (string.IsNullOrEmpty(Text)) - return; - contentCache.Invalidate(); } } @@ -129,6 +125,12 @@ private void validateContent() if (!contentCache.IsValid) { var markdownText = Text; + + document.Clear(); + + if (string.IsNullOrEmpty(Text)) + return; + var pipeline = CreateBuilder(); var parsed = Markdig.Markdown.Parse(markdownText, pipeline); @@ -147,8 +149,7 @@ private void validateContent() } } } - - document.Clear(); + foreach (var component in parsed) AddMarkdownComponent(component, document, root_level); diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs index 8540f92148..edff0f8ea5 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs @@ -41,9 +41,11 @@ private void load() textFlowContainer = CreateTextFlow(), }; - foreach (var line in fencedCodeBlock.Lines.Lines) - if (line.Line > 0) - textFlowContainer.AddParagraph(line.ToString()); + var lines = fencedCodeBlock.Lines; + for (int i = 0; i < lines.Count; i++) + { + textFlowContainer.AddParagraph(lines.Lines[i].ToString()); + } } protected virtual Drawable CreateBackground() => new Box From 5d689e3758384fb13a11f71d4a662221a005d944 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Wed, 9 Jan 2019 00:15:37 +0900 Subject: [PATCH 15/18] make appveyor happy again --- osu.Framework/Graphics/Containers/Markdown/MarkdownContainer.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownContainer.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownContainer.cs index df933e728e..81300abd66 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownContainer.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownContainer.cs @@ -149,7 +149,6 @@ private void validateContent() } } } - foreach (var component in parsed) AddMarkdownComponent(component, document, root_level); From cead122ab5d1ac7ec319428c91808879b89c4129 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 2 Mar 2019 00:06:07 +0900 Subject: [PATCH 16/18] fix issue appveyor hint --- .../Containers/Markdown/IMarkdownCodeFlowComponent.cs | 4 ++-- .../Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs | 4 ++-- .../Graphics/Containers/Markdown/MarkdownCodeStyle.cs | 4 ++-- .../Graphics/Containers/Markdown/MarkdownContainer.cs | 1 + 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/osu.Framework/Graphics/Containers/Markdown/IMarkdownCodeFlowComponent.cs b/osu.Framework/Graphics/Containers/Markdown/IMarkdownCodeFlowComponent.cs index 3d8b3b23ad..06c1e77f3f 100644 --- a/osu.Framework/Graphics/Containers/Markdown/IMarkdownCodeFlowComponent.cs +++ b/osu.Framework/Graphics/Containers/Markdown/IMarkdownCodeFlowComponent.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2007-2018 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. namespace osu.Framework.Graphics.Containers.Markdown { diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs index 66a6743492..b4b79859c7 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2007-2018 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. using ColorCode; using ColorCode.Parsing; diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeStyle.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeStyle.cs index ffec1b823a..ea4cf81c75 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeStyle.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeStyle.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2007-2018 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. using osuTK.Graphics; using System.Collections.ObjectModel; diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownContainer.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownContainer.cs index 0213ff1d41..3377eb6cb8 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownContainer.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownContainer.cs @@ -150,6 +150,7 @@ private void validateContent() } } } + foreach (var component in parsed) AddMarkdownComponent(component, document, root_level); From de82fabb425716439874d45826adeb1046531ecc Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 2 Mar 2019 00:18:41 +0900 Subject: [PATCH 17/18] change font usage --- .../Containers/Markdown/MarkdownCodeFlowContainer.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs index b4b79859c7..32935ee74d 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownCodeFlowContainer.cs @@ -61,15 +61,11 @@ public void AddCodeText(string codeText,string languageCode) protected virtual void ApplyCodeText(SpriteText text, MarkdownCodeStyle.Style codeStyle) { - string font = "OpenSans-"; - if (codeStyle.Bold) - font += "Bold"; - if (codeStyle.Italic) - font += "Italic"; + var textDrawable = CreateSpriteText(); text.Colour = codeStyle.Colour; text.ShadowColour = codeStyle.BackgroundColour ?? text.ShadowColour; - text.Font = font.Trim('-'); + text.Font = textDrawable.Font.With(weight: codeStyle.Bold ? "Bold" : null, italics: codeStyle.Italic); } public class ClassFormatter : CodeColorizerBase From 25000ec567c698951ec9f79c7b61ec9d24e29959 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 2 Mar 2019 00:34:15 +0900 Subject: [PATCH 18/18] fix broken code --- .../Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs index 3ddd36bc5f..d8ddecec83 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs @@ -44,7 +44,7 @@ private void load() var lines = fencedCodeBlock.Lines; for (int i = 0; i < lines.Count; i++) { - textFlowContainer.AddParagraph(lines.Lines[i].ToString()); + textFlowContainer.AddCodeText(lines.Lines[i].ToString(), fencedCodeBlock.Info); } }