예제 #1
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));
        }
예제 #2
0
 private static Inline GetInline(ParseToken token, Hint hint)
 {
     if (token is TextToken)
     {
         var tt = (TextToken)token;
         return new Run(tt.Text);
     }
     if (token is ElementToken)
     {
         var et = (ElementToken)token;
         switch (et.Name)
         {
             case "b":
                 return new Bold().Fill(et, hint);
             case "u":
                 return new Underline().Fill(et, hint);
             case "i":
                 return new Italic().Fill(et, hint);
             case "lb":
                 return new LineBreak();
             case "code":
                 return new Span { FontFamily = new FontFamily("Consolas"), FontSize = 12.0d * (96d / 72d) }.Fill(et, hint);
             case "font":
                 return BuildFont(et, hint);
             case "keyword":
                 return new Span { Foreground = Brushes.Blue }.Fill(et, hint);
             //case "span":
             case "hint":
                 return BuildHint(et, hint);
             case "ref":
                 return BuildRef(et, hint);
             case "params":
                 return BuildParam(et, hint);
             default:
                 throw new NotSupportedException(et.Name);
         }
     }
     throw new NotSupportedException();
 }