Inheritance: ParseToken
Beispiel #1
0
        /// <summary>
        /// remove pre
        /// </summary>
        static void RemoveFormating(ElementToken root)
        {
            var node = root.Tokens.First;

            while (node != null)
            {
                var item = node.Value;
                if (!(item is ElementToken))
                {
                    node = node.Next;
                    continue;
                }

                var el = (ElementToken)item;
                RemoveFormating(el);

                if (el.Name == "pre")
                {
                    foreach (var subNode in el.Tokens)
                    {
                        root.Tokens.AddBefore(node, subNode);
                    }

                    var next = node.Next;
                    root.Tokens.Remove(node);
                    node = next;
                }
                else
                {
                    node = node.Next;
                    continue;
                }
            }
        }
Beispiel #2
0
        static int Clear(int i1, ElementToken root, RangeList list)
        {
            foreach (var node in root.Tokens)
            {
                var i2 = node.StartIndex;
                if (!(node is ElementToken))
                {
                    continue;
                }

                var el = (ElementToken)node;
                if (el.Name != "pre")
                {
                    i1 = Clear(i1, el, list);
                }
                else
                {
                    ClearParamsInPre(el, list);
                    // clear range
                    ClearRange(i1, i2, list);
                    i1 = el.EndIndex;
                }
            }
            return(i1);
        }
Beispiel #3
0
        private static Inline BuildFont(ElementToken token, Hint hint)
        {
            var span = new Span();

              string size;
              if (token.Attributes.TryGetValue("size", out size))
              {
            var fc = new FontSizeConverter();
            var sz = (double)fc.ConvertFromString(size);
            span.FontSize = sz;
              }

              string face;
              if (token.Attributes.TryGetValue("face", out face))
              {
            span.FontFamily = new FontFamily(face);
              }

              string color;
              if (token.Attributes.TryGetValue("color", out color))
              {
            var bc = new BrushConverter();
            var br = (Brush)bc.ConvertFromString(color);
            span.Foreground = br;
              }
              return span.Fill(token, hint);
        }
Beispiel #4
0
        static ElementToken InsertElement(ElementToken token, int i1, int i2, string name)
        {
            var newToken = Split(token, i1);
            newToken.Name = name;
            token.Tokens.AddLast(newToken);

            var tmp = SplitBack(newToken, i2);
            foreach (var t in tmp.Tokens)
            {
                token.Tokens.AddLast(t);
            }

            return newToken;
        }
Beispiel #5
0
 static ParseToken Create(XNode node, int index, RangeList list)
 {
     if (node is XText)
     {
         var len = ((XText)node).Value.Length;
         return new TextToken(index, len, list);
     }
     if (node is XElement)
     {
         var el = (XElement)node;
         var en = new ElementToken(index, list);
         ParseElement(en, el, index, list);
         return en;
     }
     throw new NotSupportedException(node.NodeType.ToString());
 }
Beispiel #6
0
 static ParseToken Create(XNode node, int index, RangeList list)
 {
     if (node is XText)
     {
         var len = ((XText)node).Value.Length;
         return(new TextToken(index, len, list));
     }
     if (node is XElement)
     {
         var el = (XElement)node;
         var en = new ElementToken(index, list);
         ParseElement(en, el, index, list);
         return(en);
     }
     throw new NotSupportedException(node.NodeType.ToString());
 }
Beispiel #7
0
        static ElementToken Split(ElementToken token, int index)
        {
            for (var node = token.Tokens.First; ; node = node.Next)
            {
                var r = node.Value;

                if (index == r.StartIndex)
                {
                    return(token.Split(node, false));
                }
                if (index < r.EndIndex)
                {
                    return(SplitNode(token, node, index, false));
                }
            }
        }
Beispiel #8
0
        static ElementToken InsertElement(ElementToken token, int i1, int i2, string name)
        {
            var newToken = Split(token, i1);

            newToken.Name = name;
            token.Tokens.AddLast(newToken);

            var tmp = SplitBack(newToken, i2);

            foreach (var t in tmp.Tokens)
            {
                token.Tokens.AddLast(t);
            }

            return(newToken);
        }
Beispiel #9
0
        static ElementToken SplitBack(ElementToken token, int index)
        {
            for (var node = token.Tokens.Last; ; node = node.Previous)
            {
                var r = node.Value;

                if (index == r.EndIndex)
                {
                    return(token.Split(node, true));
                }
                if (index > r.StartIndex)
                {
                    return(SplitNode(token, node, index, true));
                }
            }
        }
Beispiel #10
0
        static void ParseElement(ElementToken en, XElement el, int index, RangeList list)
        {
            // parse name & attributes
            en.Name = el.Name.ToString();
            foreach (var attr in el.Attributes())
            {
                en.Attributes[attr.Name.ToString()] = attr.Value;
            }

            // parse nodes
            foreach (var node in el.Nodes())
            {
                var pn = Create(node, index, list);
                en.Tokens.AddLast(pn);
                index += pn.Length;
            }
        }
Beispiel #11
0
        static void ParseElement(ElementToken en, XElement el, int index, RangeList list)
        {
            // parse name & attributes
            en.Name = el.Name.ToString();
            foreach (var attr in el.Attributes())
            {
                en.Attributes[attr.Name.ToString()] = attr.Value;
            }

            // parse nodes
            foreach (var node in el.Nodes())
            {
                var pn = Create(node, index, list);
                en.Tokens.AddLast(pn);
                index += pn.Length;
            }
        }
Beispiel #12
0
        private static Inline BuildHint(ElementToken token, Hint hint)
        {
            Trace.Assert(token.Name == "hint");

              string handler;
              token.Attributes.TryGetValue("handler", out handler);

              string key;
              token.Attributes.TryGetValue("key", out key);

              string value = token.Attributes["value"];

              var hc = key == null ? new HintControl(token.ToString(), handler)
                           : new HintControl(key, hint.RaiseGetHintContent, handler);
              //Fill(hc.Inlines, token);
              hc.Inlines.Add(new Run(value));
              return new InlineUIContainer { Child = hc };
        }
Beispiel #13
0
        static ElementToken FindParamToken(ElementToken rootToken, int i1, int i2)
        {
            foreach (var child in rootToken.Tokens)
            {
                var r = child;
                var a1 = r.Contains(i1);
                var a2 = r.Contains(i2);

                if (a1 && a2) // both
                {
                    if (child is TextToken) return rootToken;
                    return FindParamToken((ElementToken)child, i1, i2);
                }

                if (a1 || a2) return rootToken;
            }
            return null;
        }
Beispiel #14
0
        public ElementToken Split(LinkedListNode<ParseToken> splitNode, bool after)
        {
            var token = splitNode.Value;
            var index = after ? token.EndIndex : token.StartIndex;

            var newToken = new ElementToken(index, _rangeList) { Name = Name };
            newToken.Attributes = this.Attributes;

            // split nodes
            var cur = after ? splitNode.Next : splitNode;
            while (cur != null)
            {
                var tmp = cur.Next;
                Tokens.Remove(cur);
                newToken.Tokens.AddLast(cur);
                cur = tmp;
            }
            return newToken;
        }
Beispiel #15
0
        static void ClearParamsInPre(ElementToken token, RangeList list)
        {
            foreach (var node in token.Tokens)
            {
                if (!(node is ElementToken)) continue;

                var el = (ElementToken)node;
                if (el.Name != "params")
                {
                    ClearParamsInPre(el, list);
                }
                else
                {
                    var i1 = el.StartIndex;
                    var i2 = el.EndIndex;
                    // clear range
                    ClearRange(i1, i2, list);
                }
            }
        }
Beispiel #16
0
        static int Clear(int i1, ElementToken root, RangeList list)
        {
            foreach (var node in root.Tokens)
            {
                var i2 = node.StartIndex;
                if (!(node is ElementToken)) continue;

                var el = (ElementToken)node;
                if (el.Name != "pre")
                {
                    i1 = Clear(i1, el, list);
                }
                else
                {
                    ClearParamsInPre(el, list);
                    // clear range
                    ClearRange(i1, i2, list);
                    i1 = el.EndIndex;
                }
            }
            return i1;
        }
Beispiel #17
0
        static void ClearParamsInPre(ElementToken token, RangeList list)
        {
            foreach (var node in token.Tokens)
            {
                if (!(node is ElementToken))
                {
                    continue;
                }

                var el = (ElementToken)node;
                if (el.Name != "params")
                {
                    ClearParamsInPre(el, list);
                }
                else
                {
                    var i1 = el.StartIndex;
                    var i2 = el.EndIndex;
                    // clear range
                    ClearRange(i1, i2, list);
                }
            }
        }
Beispiel #18
0
        private static Inline BuildParam(ElementToken token, Hint hint)
        {
            var pp = new ParamPanel();
              foreach (ParseToken pt in token.Tokens)
              {
            var et = pt as ElementToken;
            if (et != null)
            {
              var tb = new TextBlock().Fill(et, hint);
              pp.Children.Add(tb);
              if (et.Name == "pname")
            ParamPanel.SetNameColumn(tb, true);

              continue;
            }

            var tt = pt as TextToken;
            if (tt != null && pp.Children.Count > 0)
            {
              var elem = pp.Children[pp.Children.Count - 1] as TextBlock;
              if (elem != null)
            elem.Inlines.Add(GetInline(tt, hint));

              continue;
            }
              }

              var span = new Span();
              span.Inlines.Add(new SoftBreak());
              span.Inlines.Add(new InlineUIContainer
                       {
                         Child = pp,
                         BaselineAlignment = BaselineAlignment.Bottom
                       });
              span.Inlines.Add(new SoftBreak());
              return span;
        }
Beispiel #19
0
        static ElementToken FindParamToken(ElementToken rootToken, int i1, int i2)
        {
            foreach (var child in rootToken.Tokens)
            {
                var r  = child;
                var a1 = r.Contains(i1);
                var a2 = r.Contains(i2);

                if (a1 && a2)                 // both
                {
                    if (child is TextToken)
                    {
                        return(rootToken);
                    }
                    return(FindParamToken((ElementToken)child, i1, i2));
                }

                if (a1 || a2)
                {
                    return(rootToken);
                }
            }
            return(null);
        }
Beispiel #20
0
        static ElementToken SplitNode(ElementToken token, LinkedListNode <ParseToken> node, int index, bool back)
        {
            var curToken = node.Value;

            ParseToken newToken = null;

            if (curToken is TextToken)
            {
                // split text
                newToken = ((TextToken)curToken).Split(index);
            }
            else if (curToken is ElementToken)
            {
                newToken = back
                                                                                         ? SplitBack((ElementToken)curToken, index)
                                                                                         : Split((ElementToken)curToken, index);
            }

            // add new node after curNode
            token.Tokens.AddAfter(node, newToken);

            // split by node
            return(token.Split(node, true));
        }
Beispiel #21
0
        public ElementToken Split(LinkedListNode <ParseToken> splitNode, bool after)
        {
            var token = splitNode.Value;
            var index = after ? token.EndIndex : token.StartIndex;

            var newToken = new ElementToken(index, _rangeList)
            {
                Name = Name
            };

            newToken.Attributes = this.Attributes;

            // split nodes
            var cur = after ? splitNode.Next : splitNode;

            while (cur != null)
            {
                var tmp = cur.Next;
                Tokens.Remove(cur);
                newToken.Tokens.AddLast(cur);
                cur = tmp;
            }
            return(newToken);
        }
Beispiel #22
0
 private static TextBlock Fill(this TextBlock tb, ElementToken token, Hint hint)
 {
     Fill(tb.Inlines, token, hint);
       return tb;
 }
Beispiel #23
0
 private static Span Fill(this Span span, ElementToken token, Hint hint)
 {
     Fill(span.Inlines, token, hint);
       return span;
 }
Beispiel #24
0
        static ElementToken SplitBack(ElementToken token, int index)
        {
            for (var node = token.Tokens.Last; ; node = node.Previous)
            {
                var r = node.Value;

                if (index == r.EndIndex) return token.Split(node, true);
                if (index > r.StartIndex) return SplitNode(token, node, index, true);
            }
        }
Beispiel #25
0
        static ElementToken Split(ElementToken token, int index)
        {
            for (var node = token.Tokens.First; ; node = node.Next)
            {
                var r = node.Value;

                if (index == r.StartIndex) return token.Split(node, false);
                if (index < r.EndIndex) return SplitNode(token, node, index, false);
            }
        }
Beispiel #26
0
        private static Inline BuildRef(ElementToken token, Hint hint)
        {
            string handler;
              token.Attributes.TryGetValue("handler", out handler);

              string hintStr;
              token.Attributes.TryGetValue("hint", out hintStr);
              if (hintStr != null)
              {
            hintStr = "<code>" + hintStr + "</code>";
              }
              var hc = new HintControl(hintStr, handler);
              Fill(hc.Inlines, token, hint);
              return new InlineUIContainer { Child = hc };
        }
Beispiel #27
0
        static ElementToken SplitNode(ElementToken token, LinkedListNode<ParseToken> node, int index, bool back)
        {
            var curToken = node.Value;

            ParseToken newToken = null;
            if (curToken is TextToken)
            {
                // split text
                newToken = ((TextToken)curToken).Split(index);
            }
            else if (curToken is ElementToken)
            {
                newToken = back
                                             ? SplitBack((ElementToken)curToken, index)
                                             : Split((ElementToken)curToken, index);
            }

            // add new node after curNode
            token.Tokens.AddAfter(node, newToken);

            // split by node
            return token.Split(node, true);
        }
Beispiel #28
0
        /// <summary>
        /// remove pre
        /// </summary>
        static void RemoveFormating(ElementToken root)
        {
            var node = root.Tokens.First;
            while (node != null)
            {
                var item = node.Value;
                if (!(item is ElementToken))
                {
                    node = node.Next;
                    continue;
                }

                var el = (ElementToken)item;
                RemoveFormating(el);

                if (el.Name == "pre")
                {
                    foreach (var subNode in el.Tokens)
                    {
                        root.Tokens.AddBefore(node, subNode);
                    }

                    var next = node.Next;
                    root.Tokens.Remove(node);
                    node = next;
                }
                else
                {
                    node = node.Next;
                    continue;
                }
            }
        }
Beispiel #29
0
 private static void Fill(InlineCollection inlines, ElementToken token, Hint hint)
 {
     foreach (var t in token.Tokens)
       {
     inlines.Add(GetInline(t, hint));
       }
 }
Beispiel #30
0
 private static Inline BuildSymbol(ElementToken token, Hint hint)
 {
     string spanClass = token.Attributes["SpanClass"];
       string value     = token.Text;
       return new Run(value) { Foreground = hint.MapBrush(spanClass) };
 }
Beispiel #31
0
        private static Inline BuildSymbolHint(ElementToken token, Hint hint)
        {
            Trace.Assert(token.Name == "Symbol");

              string handler;
              token.Attributes.TryGetValue("handler", out handler);

              string key       = token.Attributes["id"];
              string spanClass = token.Attributes["SpanClass"];

              string value = token.Text;

              var hc = new HintControl(key, hint.RaiseGetHintContent, handler);
              hc.Inlines.Add(new Run(value) { Foreground = hint.MapBrush(spanClass) });
              return new InlineUIContainer { Child = hc };
        }