Пример #1
0
        public override void ExitAssignedAttr(HTMLParser.AssignedAttrContext ctx)
        {
            var attrNameCtx = ctx.htmlAttributeName();
            if (attrNameCtx == null)
            {
                return;
            }
            var attrValueCtx = ctx.htmlAttributeValue();
            if (attrValueCtx == null)
            {
                return;
            }

            var attrNameText = MyTreeProperty.Get(attrNameCtx);
            if (string.IsNullOrEmpty(attrNameText))
            {
                return;
            }
            var attrValueText = MyTreeProperty.Get(attrValueCtx);
            if (string.IsNullOrEmpty(attrValueText))
            {
                return;
            }

            //TODO swap attributes name & values here
            if (attrValueText.Length <= 2)
                FilteredPut(ctx, attrNameText + "=" + attrValueText);
            else
            {
                var openQuot = attrValueText.Substring(0, 1);
                var closeQuot = attrValueText.Substring(attrValueText.Length - 1, 1);
                var attrInnerValue =
                    attrValueText.Substring(1, attrValueText.Length - 2).EscapeString(EscapeStringType.XML);
                FilteredPut(ctx, attrNameText + "=" + openQuot + attrInnerValue + closeQuot);
            }
        }
Пример #2
0
        public override void ExitEmptyAttr(HTMLParser.EmptyAttrContext ctx)
        {
            var attrNameCtx = ctx.htmlAttributeName();
            if (attrNameCtx == null)
            {
                return;
            }
            var attrNameText = MyTreeProperty.Get(attrNameCtx);
            if (string.IsNullOrEmpty(attrNameText))
            {
                return;
            }

            //TODO swap attributes name with name-value pair here
            if(_results.EmptyAttrs.All(x => attrNameText != x))
                _results.EmptyAttrs.Add(attrNameText);

            FilteredPut(ctx, attrNameText + "='true'");
        }