Пример #1
0
        internal HtmlElementDefinition GetTag(string tagName)
        {
            if (tagName == null)
            {
                throw new ArgumentNullException(nameof(tagName));
            }

            tagName = tagName.Trim().ToLowerInvariant();
            if (tagName.Length == 0)
            {
                throw Failure.AllWhitespace(nameof(tagName));
            }

            // TODO This behavior causes any undefined tag to be
            // added to HTML 5 (need different behavior)

            var tags = this.ElementDefinitions;

            lock (tags) {
                var tag = (HtmlElementDefinition)tags[tagName];
                if (tag == null)
                {
                    // not defined: create default; go anywhere, do anything! (incl be inside a <p>)
                    tag = new HtmlElementDefinition(tagName);
                    tags.Add(tag);
                    tag.IsUnknownTag    = true;
                    tag.IsBlock         = false;
                    tag.CanContainBlock = true;
                }
                return(tag);
            }
        }
Пример #2
0
        public static void CopyTo(DomElementDefinitionCollection tags)
        {
            foreach (string tagName in blockTags)
            {
                HtmlElementDefinition tag = new HtmlElementDefinition(tagName);
                tags.Add(tag);
            }

            foreach (string tagName in inlineTags)
            {
                HtmlElementDefinition tag = new HtmlElementDefinition(tagName);
                tag.IsBlock         = false;
                tag.CanContainBlock = false;
                tag.FormatAsBlock   = false;
                tags.Add(tag);
            }

            // mods:
            foreach (string tagName in emptyTags)
            {
                HtmlElementDefinition tag = (HtmlElementDefinition)tags[tagName];

                tag.CanContainBlock  = false;
                tag.CanContainInline = false;

                // can self close (<foo />). used for unknown tags that self close, without forcing them as empty.
                tag.IsEmpty       = true; // can hold nothing; e.g. img
                tag.IsSelfClosing = true;
            }

            foreach (string tagName in formatAsInlineTags)
            {
                HtmlElementDefinition tag = (HtmlElementDefinition)tags[tagName];

                tag.FormatAsBlock = false;
            }

            // for pre, textarea, script etc
            foreach (string tagName in preserveWhitespaceTags)
            {
                HtmlElementDefinition tag = (HtmlElementDefinition)tags[tagName];

                tag.WhitespaceMode = DomWhitespaceMode.Preserve;
            }
        }