Pandoc::Selector(3pm)
π Pandoc::Selector π
ok so bestie, this is a page from the User Contributed Perl Documentation for a module called Pandoc::Selector, and honestly? it ate. let's get into it π«Ά
β¨ NAME β¨
Pandoc::Selector β it's a whole document selector language for Pandoc. like, a language-language. not just a function. a vibe, a grammar, a lifestyle. π
π SYNOPSIS π
here's how you actually use it, no cap:
my $selector = Pandoc::Selector->new('Code.perl|CodeBlock.perl');
# check whether an element matches
$selector->match($element);
# use as element method
$element->match('Code.perl|CodeBlock.perl')
so you spin up a selector object with new, you check if some element matches it with match, and β plot twist β you can also call match straight on an element as a method. convenient? iconic. π
πΈ DESCRIPTION πΈ
Pandoc::Selector hands you a language for selecting elements out of a Pandoc document. it's giving big "I borrowed my fits from my older cousins" energy: the ideas come from CSS Selectors (https://www.w3.org/TR/selectors-3/), XPath (https://www.w3.org/TR/xpath/), and other languages in that same family. slay.
and here's the tea β the language is still being developed together with this implementation. so they're growing up side by side. main character duo fr fr. π¦
π EXAMPLES π
a lil taste test of what selectors look like:
Header#main
Code.perl
Code.perl.raw
:inline
that's it, that's the sampler platter. π
π SELECTOR GRAMMAR π
ok this is the part where we get technical, and lowkey it's the best part.
first up: whitespace between the parts of the syntax is optional, and it's not even represented in the grammar below. so breathe however you want, the grammar doesn't care.
a Selector is a list of one or more expression lists, separated by pipes (|). for instance, the selector Subscript|Superscript selects both Subscript elements and Superscript elements. two for one, we love a deal. π
Selector ::= ExpressionList ( '|' ExpressionList )*
an expression list is a list of one or more expressions:
ExpressionList ::= Expression ( Expression )*
and an expression is any one of these four: a name expression, an id expression, a class expression, or a type expression.
Expression ::= NameExpression
| IdExpression
| ClassExpression
| TypeExpression
NameExpression ::= Name
Name ::= [A-Za-z]+
IdExpression ::= '#' [\p{L}\p{N}_-]+
ClassExpression ::= '.' [\p{L}\p{N}_-]+
TypeExpression ::= ':' Name
so to recap the grammar in bestie terms: Name is letters only, ids start with a #, classes start with a ., types start with a :, and both ids and classes take letters, numbers, underscores and dashes (that's the \p{L}\p{N}_- situation right there). periodt. β¨
π SEE ALSO π
there's an example filter called select β go look at it if you wanna select parts of a document irl. that's the whole rec. iykyk. π§
fr fr, go read a manual page today. your future self will thank you. π
and that's a wrap, babe π β this page ships with perl v5.38.2, dated 2024-08-03, and it lives in Pandoc::Selector(3pm). love that for us. mwah. π β¨ πΈ
π¦ where this page comes from
- debian trixie: libpandoc-elements-perl 0.38-7 Β· GPL-2.0-only
- ubuntu resolute: libpandoc-elements-perl 0.38-7 Β· GPL-2.0-only
- ubuntu stonking: libpandoc-elements-perl 0.38-7 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms