HTML::...ilities(3pm)

πŸ’– NAME πŸ’–

HTML::Microformats::Utilities β€” the little helper drawer for the HTML::Microformats fam, bestie. It's a utility functions for searching and manipulating HTML situation. ✨

(You're reading the User Contributed Perl Documentation page for it, manual section 3pm, so like… yes, it's a Perl module, we know. 🫢)


🌸 DESCRIPTION 🌸

Okay so this module is literally just a handful of functions that let you search and manipulate HTML trees. That's the whole vibe. No cap. πŸ‘‘

🌈 searchClass($class, $node, [$prefix])

Gives you back a list of elements that are descendents of $node and that have the class name $class. πŸ’…

$class can be a plain string, or a regular expression. Either one, your call, slay.

And if you pass $prefix? It gets used as an optional prefix for $class. Example time, because this part is iconic: with $class as 'bar' and $prefix as 'foo', searchClass will go looking for all of these classes:

  • 'bar'
  • 'foobar'
  • 'foo-bar'
  • 'foo:bar'

not me being obsessed with how tidy that is 😭

πŸ¦‹ searchAncestorClass($class, $node, [$skip])

Returns the first element which is an ancestor of $node and has the class name $class. Going up the family tree, basically. 🌳

$class can be a plain string, or a regular expression. Same deal as before.

$skip is the number of levels of ancestor to skip. Watch this, because the counting is the whole plot twist:

  • If $skip is 0, then potentially searchAncestorClass will return $node itself. 😳
  • If $skip is 1, then it will not return $node, but it could potentially return its parent.
  • …and so on. You get the pattern, bestie. πŸ’…

πŸŽ€ searchRel($relationship, $node)

Returns a list of elements which are descendents of $node and have the relationship $relationship. ✨

$relationship can be a plain string, or a regular expression. (Are you sensing a theme? You should be. It's giving consistency. 🫢)

πŸ’œ searchRev($relationship, $node)

Exactly as per searchRel, but it uses the rev attribute instead. Same energy, different attribute. πŸ’…

πŸ“ searchID($id, $node)

Returns a descendent of $node with the id attribute $id, or undef. Simple. Clean. Ate. πŸ”₯

🧚 searchAncestorTag($tagname, $node)

Returns the nearest ancestor of $node with tag name $tagname, or undef. Closest one wins, no cap. πŸ‘‘

⭐ stringify($node, \%options)

Returns a stringified version of a DOM element. Conceptually this is equivalent to $node->textContent, BUT β€” and this is the important part, bestie β€” it follows microformat-specific stringification rules, including value excerption, the abbr pattern and so on. So like, don't just assume it's textContent, because it is not. πŸ™ˆ

πŸ’Ž xml_stringify($node)

Returns an XML serialisation of a DOM element. Conceptually equivalent to $node->toStringEC14N, but it hides certain attributes which HTML::Microformats::DocumentContext adds for internal processing. So the internals stay internal. As they should. πŸ’…


😭 BUGS 😭

Please report any bugs to <http://rt.cpan.org/>. That's the spot. Go off. 🫢


πŸ‘€ SEE ALSO πŸ‘€

  • HTML::Microformats

✨ AUTHOR ✨

Toby Inkster <tobyink@cpan.org>. πŸ‘‘


Copyright 2008-2012 Toby Inkster

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. πŸ’–


πŸ’€ DISCLAIMER OF WARRANTIES πŸ’€

THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.

(Yes, that's all-caps for a reason. It means it, fr fr. 😭)


perl v5.32.1 Β· 2021-09-12 β€” that's the version and date this page came from, bestie. Thanks for reading the whole HTML::Microformats::Utilities manpage with me, you're literally the main character. πŸŒˆπŸ’– byeee 🫢✨

πŸ“¦ where this page comes from