コード例 #1
0
        void HandleElement(Element e)
        {
            if (e.Kind == ElementKind.Element || e.Kind == ElementKind.StartTag)
            {
                // Start tag
                var name = e.StartTagTokens["name"] as Token;
                var suffix = e.StartTagTokens["suffix"] as Token;
                Location loc = name.Location;
                var tag = new Tag
                {
                    Name = name.ToString(),
                    Suffix = suffix.ToString(),
                    SourcePath = name.Filename,
                    LineNumber = loc.Line,
                    LinePosition = loc.Position,
                    Attributes = new List<TagAttribute>()
                };
                var attrs = e.StartTagTokens["attrs"] as List<Dictionary<string, object>>;
                foreach (var attr in attrs)
                {
                    var attrName = attr["name"] as Token;
                    var attrValue = attr["value"] as Token;
                    var attrEq = attr["eq"] as Token;
                    var attrQuote = attr["quote"] as Token;
                    var a = new TagAttribute
                    {
                        Name = attrName.ToString(),
                        Value = attrValue.ToString(),
                        Eq = attrEq.ToString(),
                        Quote = attrQuote.ToString(),
                        QuoteEntity = Utils.Char2Entity(attrQuote.ToString())
                    };
                    tag.Attributes.Add(a);
                }
                if ((e.Children.Count == 0 && suffix.ToString() == "/>") || e.EndTagTokens.Count == 0)
                {
                    // Singleton element
                    tag.Singleton = true;
                    HandleStartTag(tag);
                    HandleEndTag(tag);
                }
                else
                {
                    tag.Singleton = false;
                    HandleStartTag(tag);
                }

                // Children
                foreach (var item in e.Children)
                    HandleElement(item);

                // End tag
                if (e.EndTagTokens.Count > 0)
                {
                    var endName = e.EndTagTokens["name"] as Token;
                    var endSuffix = e.EndTagTokens["suffix"] as Token;
                    Location endLoc = endName.Location;
                    var endTag = new Tag
                    {
                        Name = endName.ToString(),
                        Suffix = endSuffix.ToString(),
                        SourcePath = endName.Filename,
                        LineNumber = endLoc.Line,
                        LinePosition = endLoc.Position
                    };
                    HandleEndTag(endTag);
                }
            }
            else if (e.Kind == ElementKind.Text)
            {
                foreach (Token token in e.StartTagTokens.Values)
                    HandleData(token.ToString());
            }
            else if (e.Kind == ElementKind.Comment)
            {
                foreach (Token token in e.StartTagTokens.Values)
                    HandleComment(token.ToString());
            }
            else if (e.Kind == ElementKind.CData)
            {
                foreach (Token token in e.StartTagTokens.Values)
                    HandleCData(token.ToString());
            }
            else if (e.Kind == ElementKind.ProcessingInstruction)
            {
                HandleProcessingInstruction(e);
            }
            else if (e.Kind == ElementKind.Default)
            {
                foreach (Token token in e.StartTagTokens.Values)
                    HandleDefault(token.ToString());
            }
        }
コード例 #2
0
 protected override void HandleProcessingInstruction(Element e)
 {
     var name = (e.StartTagTokens["name"]).ToString();
     var text = (e.StartTagTokens["text"]).ToString();
     if (name != "csharp")
     {
         HandleData(string.Format("<?{0}{1}?>", name, text));
         return;
     }
     _programCommands.Add(new CmdCodeBlock(name, text));
 }
コード例 #3
0
 protected abstract void HandleProcessingInstruction(Element e);