From c59129b06dfb4aaf0fa4b7bed0d6ccb7e72ef45c Mon Sep 17 00:00:00 2001 From: Imanuel Ulbricht Date: Sun, 9 Oct 2016 17:04:00 +0200 Subject: [PATCH] Added list feature for BBCode --- .../Windows/Controls/BBCode/BBCodeParser.cs | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/1.0/FirstFloor.ModernUI/Shared/Windows/Controls/BBCode/BBCodeParser.cs b/1.0/FirstFloor.ModernUI/Shared/Windows/Controls/BBCode/BBCodeParser.cs index 008bd085..b447937e 100644 --- a/1.0/FirstFloor.ModernUI/Shared/Windows/Controls/BBCode/BBCodeParser.cs +++ b/1.0/FirstFloor.ModernUI/Shared/Windows/Controls/BBCode/BBCodeParser.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Text; using System.Xml; @@ -24,6 +24,8 @@ internal class BBCodeParser private const string TagSize = "size"; private const string TagUnderline = "u"; private const string TagUrl = "url"; + private const string TagList = "list"; + private const string TagListItem = "*"; class ParseContext { @@ -38,6 +40,8 @@ public ParseContext(Span parent) public Brush Foreground { get; set; } public TextDecorationCollection TextDecorations { get; set; } public string NavigateUri { get; set; } + public bool IsList { get; set; } + public bool IsListItem { get; set; } /// /// Creates a run reflecting the current context settings. @@ -143,6 +147,15 @@ private void ParseTag(string tag, bool start, ParseContext context) context.NavigateUri = null; } } + else if (tag == TagList) { + context.IsList = start; + if (!start) { + context.IsListItem = false; + } + } + else if (tag == TagListItem) { + context.IsListItem = true; + } } private void Parse(Span span) @@ -185,6 +198,20 @@ private void Parse(Span span) parent = link; span.Inlines.Add(parent); } + + var text = token.Value; + if (context.IsList && context.IsListItem) + { + text = "\u25CF" + "text"; + } + + var run = context.CreateRun(text); + parent.Inlines.Add(run); + + if (context.IsList) + { + parent.Inlines.Add(new LineBreak()); + } var run = context.CreateRun(token.Value); parent.Inlines.Add(run); }