//! Static metadata for HTML elements and attributes.
//!
//! This file is generated via build/generate.rb and the build/meta.rs.erb
//! template. It should not be manually edited. To avoid any rust build-time
//! dependency however, the resulting source file (src/dom/html/meta.rs) is
//! also checked in.
use std::collections::HashMap;
use lazy_static::lazy_static;
use crate::dom::LocalName;
lazy_static! {
/// A static lookup table for metadata on known HTML tags.
pub static ref TAG_META: HashMap = init_tag_metadata();
}
/// Metadata about HTML tags and their attributes.
pub struct TagMeta {
is_empty: bool,
is_deprecated: bool,
is_inline: bool,
is_meta: bool,
is_banned: bool,
basic_attrs: Vec,
}
impl TagMeta {
/// Return true if the element is defined to be empty: having no contents
/// or end tag.
///
/// Tags include: `<%=tags_with('empty')%>`.
pub fn is_empty(&self) -> bool {
self.is_empty
}
/// Return true if the tag is deprecated as of html5.
///
/// Tags include: `<%=tags_with('deprecated')%>`.
pub fn is_deprecated(&self) -> bool {
self.is_deprecated
}
/// Return true if the tag reprsents an _inline_ element: is not a block
/// layout producing element under normal use.
///
/// Because HTML 5 no longer specifies this property, this is a
/// somewhat arbitrary distinction maintained here, loosely based on HTML 4
/// but extending for new tags. One noteworthy exception is that `
` is
/// not considered inline.
///
/// Tags include: `<%=tags_with('inline')%>`.
pub fn is_inline(&self) -> bool {
self.is_inline
}
/// Return true if the tag represents metadata only, where any content is
/// not displayed text. e.g. ``.
///
/// Tags include: `<%=tags_with('meta')%>`.
pub fn is_meta(&self) -> bool {
self.is_meta
}
/// Return true if the tag is banned/blacklisted: where no content should
/// be extracted, displayed, or otherwise used.
///
/// Tags include: `<%=tags_with('banned')%>`.
pub fn is_banned(&self) -> bool {
self.is_banned
}
/// Return true if the given name is part of the _basic_ set of known
/// attributes for this element.
///
/// This _basic set_ of attributes excludes, among other things, attributes
/// that are used exclusively for styling purposes.
pub fn has_basic_attr(&self, name: &LocalName) -> bool {
self.basic_attrs.binary_search(name).is_ok()
}
}
impl Default for TagMeta {
fn default() -> TagMeta {
TagMeta {
is_empty: false,
is_deprecated: false,
is_inline: false,
is_meta: false,
is_banned: false,
basic_attrs: vec![],
}
}
}
/// `Namespace` constants
pub mod ns {
use html5ever::ns;
use crate::dom::Namespace;
pub const HTML: Namespace = ns!(html);
}
/// HTML tag constants
pub mod t {
use html5ever::local_name as lname;
use crate::dom::LocalName;
% tags.each do |tag|
% if tag.flags.include?('undefined')
lazy_static::lazy_static! {
% if tag.desc
/// Tag `<<%= tag.name %>>`: <%= tag.desc %>.
% unless tag.flags.empty?
/// (meta: <%= tag.flags.join(' ') %>)
% end
///
/// This is a lazy static (struct) as its not defined by html5ever.
% end
pub static ref <%=const(tag.name.upcase)%>: LocalName = "<%=tag.name%>".into();
}
% else
% if tag.desc
/// Tag `<<%= tag.name %>>`: <%= tag.desc %>.
% unless tag.flags.empty?
/// (meta: <%= tag.flags.join(' ') %>)
% end
% end
pub const <%=twidth(const(tag.name.upcase) + ':', 4)%> LocalName = lname!("<%=tag.name%>");
% end
% end
}
/// HTML attribute constants
pub mod a {
use html5ever::local_name as lname;
use crate::dom::LocalName;
% attributes.each do |a|
% if a.flags.include?('undefined')
lazy_static::lazy_static! {
% if a.desc
/// Attribute <%= a.name %>: <%= a.desc %>.
///
/// This is a lazy static (struct) as its not defined by html5ever.
% end
pub static ref <%=const(a.name.upcase)%>: LocalName = "<%=a.name%>".into();
}
% else
% if a.desc
/// Attribute <%= a.name %>: <%= a.desc %>.
% end
pub const <%=awidth(const(a.name.upcase) + ':', 4)%> LocalName = lname!("<%=a.name%>");
% end
% end
}
fn init_tag_metadata() -> HashMap {
let mut tag_meta = HashMap::with_capacity(<%= tags.length() %>);
% tags.each do |tag|
tag_meta.insert(t::<%=clone_if(tag, const(tag.name.upcase))%>, TagMeta {
% map_flags(tag).each do |f|
<%=f%>,
% end
basic_attrs: vec![
<%= tag.basic_atts.map { |a| clone_if(a, 'a::' + const(a.name.upcase)) }.join(', ') %>
],
.. TagMeta::default()
});
% end
tag_meta
}