private void InsertFontColor(Color fontColor)
            {
                var matchingColor = FONT_COLORS.LastOrDefault(c => c.Color.Equals(fontColor));

                if (matchingColor != null)
                {
                    this.OnSurroundTag(TMEditorHelper.ToFontColorTagName(matchingColor));
                }
            }
        private void UpdateHtmlOutput()
        {
            var htmlOut = new StringBuilder();

            var css = this.CssPart;

            if (css != null)
            {
                using (var reader = css.CreateReader())
                {
                    htmlOut.AppendFormat(@"
<style type=""text/css"">

{0}

</style>
", reader.ReadToEnd());
                }
            }

            var html = this.HtmlPart;

            if (html != null)
            {
                StringBuilder htmlSrc;
                using (var reader = html.CreateReader())
                {
                    htmlSrc = new StringBuilder(reader.ReadToEnd());
                }

                // replace tags
                {
                    var textReplacers = new Dictionary <string, Func <TMAuctionDesignerDocument, string> >()
                    {
                        { "BEZEICHNUNG", d => d.ArticleName },
                        { "HERSTELLER", d => d.Producer },
                        { "ZUSTAND", d => d.ArticleState },
                    };

                    foreach (var tr in textReplacers)
                    {
                        var tagName = tr.Key;
                        var func    = tr.Value;

                        htmlSrc.Replace(string.Format("<{0}>",
                                                      tagName),
                                        TMEditorHelper.ParseForHtml(func(this),
                                                                    false));
                    }

                    textReplacers = new Dictionary <string, Func <TMAuctionDesignerDocument, string> >()
                    {
                        { "BESCHREIBUNG", d => TMEditorHelper.ToString(d.ArticleDescription) },
                        { "LIEFERUMFANG", d => TMEditorHelper.ToString(d.ScopeOfSupply) },
                        { "VERSAND-INFORMATIONEN", d => TMEditorHelper.ToString(d.DeliveryInfo) },
                        { "KAUF-INFORMATIONEN", d => TMEditorHelper.ToString(d.BuyInfo) },
                        { "ANMERKUNGEN", d => TMEditorHelper.ToString(d.Remarks) },
                    };

                    foreach (var tr in textReplacers)
                    {
                        var tagName = tr.Key;
                        var func    = tr.Value;

                        htmlSrc.Replace(string.Format("<{0}>",
                                                      tagName),
                                        TMEditorHelper.ParseForHtml(func(this),
                                                                    true));
                    }
                }

                htmlOut.AppendFormat(@"
{0}
", htmlSrc);
            }

            this.HtmlOutput = new TextDocument(htmlOut.ToString());
        }
            private void InitializeEditorSyntaxDefinition()
            {
                // editor syntax
                using (var stream = this.GetType().Assembly.GetManifestResourceStream("MarcelJoachimKloubert.WpfAuctionDesigner._Res.AvalonEdit.Editor.xml"))
                {
                    var xmlDoc = XDocument.Load(stream);

                    // extend syntax definition dynamically
                    {
                        XElement fontXmlRootTag;
                        using (var reader = xmlDoc.CreateReader())
                        {
                            var nsManager = new XmlNamespaceManager(reader.NameTable);
                            nsManager.AddNamespace("tm", "http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008");

                            var fontColorXmlPlaceholderTag = xmlDoc.XPathSelectElements(@"//tm:SyntaxDefinition/tm:RuleSet/tm:Keywords/tm:Word[text() = 'UPcuJuU6t7ybW50VpgTgScQGBKQL2Omz']",
                                                                                        nsManager)
                                                             .First();

                            fontXmlRootTag = fontColorXmlPlaceholderTag.Parent;

                            fontColorXmlPlaceholderTag.Remove();
                        }

                        // font colors
                        foreach (var color in FONT_COLORS)
                        {
                            var tagName = TMEditorHelper.ToFontColorTagName(color);

                            var wordTagName = XName.Get("Word", "http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008");

                            var wordElementOpen = new XElement(wordTagName)
                            {
                                Value = string.Format("{{{0}}}", tagName),
                            };
                            fontXmlRootTag.Add(wordElementOpen);

                            var wordElementClose = new XElement(wordTagName)
                            {
                                Value = string.Format("{{/{0}}}", tagName),
                            };
                            fontXmlRootTag.Add(wordElementClose);
                        }

                        // font sizes
                        foreach (var size in FONT_SIZES)
                        {
                            var tagName = size.Value.AsString(true);

                            var wordTagName = XName.Get("Word", "http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008");

                            var wordElementOpen = new XElement(wordTagName)
                            {
                                Value = string.Format("{{{0}}}", tagName),
                            };
                            fontXmlRootTag.Add(wordElementOpen);

                            var wordElementClose = new XElement(wordTagName)
                            {
                                Value = string.Format("{{/{0}}}", tagName),
                            };
                            fontXmlRootTag.Add(wordElementClose);
                        }
                    }

                    using (var reader = xmlDoc.CreateReader())
                    {
                        this.EditorSyntax = HighlightingLoader.Load(reader, HighlightingManager.Instance);
                    }
                }
            }