buildMetaInfo method
Construct MetaInfo with given Document
.
If <meta>
Element
's property prefix hasBeenRegistered,
it refers to the first matched prefix given from an order
of Document
and apply all available fields in MetaInfo.
Otherwise, it will return MetaInfo with all empty field
when it cannot be able to find matched prefix.
Update in 1.1.1
: This method no longer available
for non testing purpose.
Implementation
@visibleForTesting
MetaInfo buildMetaInfo(Document htmlDocument) {
Iterable<String> prefixSequence() sync* {
final offeredPropPrefix = htmlDocument.head
?.querySelectorAll("meta[property][content]")
.map((e) => e.attributes["property"]!.split(":").first)
.toSet() ??
HashSet<String>();
if (primaryPrefix != null && offeredPropPrefix.contains(primaryPrefix)) {
yield primaryPrefix!;
offeredPropPrefix.remove(primaryPrefix);
}
for (String remainPrefix in offeredPropPrefix) {
yield remainPrefix;
}
}
MetaInfo parsedResult = MetaInfo();
for (String prefix in prefixSequence()) {
try {
var parser = _findCorrespondedParser(prefix);
parsedResult = parser.parse(htmlDocument.head!);
break;
} on StateError {
// If the prefix does not supported.
continue;
}
}
return parsedResult;
}