The CommonMark\CQL class
(cmark >= 1.1.0)
CommonMark Query Language is a DSL for describing how to travel through a CommonMark Node tree implemented as a parser and compiler for a small set of instructions, and a virtual machine for executing those instructions.
In it's most simplistic form, a CQL query combines the following paths and
/ to describe how to travel through a tree:
/firstChild/lastChildwould travel to the last child node of the first child node.
CQL can be instructed to loop, for example through the children of, or siblings to a particular node, by using the path
siblings. For example,
/firstChild/children will travel to all the children of the first child node.
CQL can be instructed how to travel by using a subquery like
[/firstChild]. For example,
/firstChild/children[/firstChild] will travel to the first child node of all the children of the first child node.
While looping, CQL can be instructed to constrict the travelled path to nodes of particular type. For example
/children(BlockQuote) will travel to the children of a node where the type is
BlockQuote. The following types are recognized (case insensitively):
/children(BlockQuote|List)will travel to the children of a node where the type is
List. Types, or unions of types, may be also negated. For example
/children(~BlockQuote)will travel to the children of a node where the type is not
/children(~BlockQuote|Paragraph)will travel to the children of a node where the type is not
CQL can be instructed to create a loop to travel to a node of a particular type, at a particular path. For example,
/firstChild(BlockQuote) will travel to the first child node where the type is
BlockQuote. Note that like other loops for
siblings, this kind of path can only be followed by a subquery.
While CQL has been implemented as part of the PHP CommonMark extension, it stands separately from PHP and does not use PHP's virtual machine or internal representation of values.