Beispiel #1
0
        void add_function(string fnc, string args)
        {
            var idx = html.value_index(fnc, "attr;counter;url");

            switch (idx)
            {
            // attr
            case 0:
            {
                var p_name    = args.Trim().ToUpperInvariant();
                var el_parent = parent();
                if (el_parent != null)
                {
                    var attr_value = el_parent.get_attr(p_name);
                    if (attr_value != null)
                    {
                        add_text(attr_value);
                    }
                }
            }
            break;

            // counter
            case 1:
                break;

            // url
            case 2:
            {
                var p_url = args.Trim();
                if (!string.IsNullOrEmpty(p_url) && p_url[0] == '\'' || p_url[0] == '\"')
                {
                    p_url = p_url.Substring(1);
                }
                if (!string.IsNullOrEmpty(p_url) && p_url[p_url.Length - 1] == '\'' || p_url[p_url.Length - 1] == '\"')
                {
                    p_url.Remove(p_url.Length - 1);
                }
                if (!string.IsNullOrEmpty(p_url))
                {
                    var el = new el_image(get_document());
                    el.set_attr("src", p_url);
                    el.set_attr("style", "display:inline-block");
                    el.set_tagName("img");
                    appendChild(el);
                    el.parse_attributes();
                }
            }
            break;
            }
        }
Beispiel #2
0
        public element create_element(string tag_name, Dictionary <string, string> attributes)
        {
            element newTag   = null;
            var     this_doc = this;

            if (_container != null)
            {
                newTag = _container.create_element(tag_name, attributes, this_doc);
            }
            if (newTag == null)
            {
                if (tag_name == "br")
                {
                    newTag = new el_break(this_doc);
                }
                else if (tag_name == "p")
                {
                    newTag = new el_para(this_doc);
                }
                else if (tag_name == "img")
                {
                    newTag = new el_image(this_doc);
                }
                else if (tag_name == "table")
                {
                    newTag = new el_table(this_doc);
                }
                else if (tag_name == "td" || tag_name == "th")
                {
                    newTag = new el_td(this_doc);
                }
                else if (tag_name == "link")
                {
                    newTag = new el_link(this_doc);
                }
                else if (tag_name == "title")
                {
                    newTag = new el_title(this_doc);
                }
                else if (tag_name == "a")
                {
                    newTag = new el_anchor(this_doc);
                }
                else if (tag_name == "tr")
                {
                    newTag = new el_tr(this_doc);
                }
                else if (tag_name == "style")
                {
                    newTag = new el_style(this_doc);
                }
                else if (tag_name == "base")
                {
                    newTag = new el_base(this_doc);
                }
                else if (tag_name == "body")
                {
                    newTag = new el_body(this_doc);
                }
                else if (tag_name == "div")
                {
                    newTag = new el_div(this_doc);
                }
                else if (tag_name == "script")
                {
                    newTag = new el_script(this_doc);
                }
                else if (tag_name == "font")
                {
                    newTag = new el_font(this_doc);
                }
                else
                {
                    newTag = new html_tag(this_doc);
                }
            }
            if (newTag != null)
            {
                newTag.set_tagName(tag_name);
                foreach (var iter in attributes)
                {
                    newTag.set_attr(iter.Key, iter.Value);
                }
            }
            return(newTag);
        }