unprint 0.16.1 → 0.16.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/package.json +1 -1
- package/src/app.js +3 -3
- package/tests/init.js +1 -0
package/README.md
CHANGED
|
@@ -52,7 +52,9 @@ query.element('h1#title'); // HTMLHeadingElement
|
|
|
52
52
|
**From here on, the query methods will be described in their initialized form.** The API for the *uninitialized* methods is identical, except for the element passed as the first argument
|
|
53
53
|
|
|
54
54
|
#### Selector
|
|
55
|
-
The selector can be a CSS selector, an XPath selector starting with
|
|
55
|
+
The selector can be a CSS selector, an XPath selector starting with `/` or `(`, or an array of either or both acting as fallbacks. If the selector is falsy, the input element will be used.
|
|
56
|
+
|
|
57
|
+
* XPath Caveat: `//` and `(//` at the *start* of the selector are converted to `.//` and `(.//` for more intuitive relative selection, but any consecutive `//` will be absolute.
|
|
56
58
|
|
|
57
59
|
#### Querying multiple elements
|
|
58
60
|
Most methods can be used in plural, returning an array of results, i.e. `query.elements()`, `query.dates()`.
|
package/package.json
CHANGED
package/src/app.js
CHANGED
|
@@ -74,9 +74,9 @@ function getElements(context, selector, firstOnly = false) {
|
|
|
74
74
|
return context.element;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
if (
|
|
78
|
-
// XPath selector
|
|
79
|
-
const iterator = globalWindow.document.evaluate(
|
|
77
|
+
if (selector.startsWith('/') || selector.startsWith('(')) {
|
|
78
|
+
// XPath selector, . prefix ensures selector is relative to current node, won't work for deeper selections
|
|
79
|
+
const iterator = globalWindow.document.evaluate(selector.replace(/^\//, './').replace(/^\(\//, '(./'), context.element, null, globalWindow.XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
|
|
80
80
|
|
|
81
81
|
if (firstOnly) {
|
|
82
82
|
return iterator.iterateNext();
|
package/tests/init.js
CHANGED
|
@@ -37,6 +37,7 @@ async function initTest() {
|
|
|
37
37
|
console.log('title', res.context.query.content('//*[contains(text(), "Test")]'));
|
|
38
38
|
console.log('date', res.context.query.date('#date', 'DD-MM-YYYY HH:mm'));
|
|
39
39
|
console.log('date xpath', res.context.query.date('//div[contains(text(), "Today:")]', 'MMM DD, YYYY'));
|
|
40
|
+
console.log('date grouped xpath', res.context.query.date('(//div[contains(text(), "Today:")])', 'MMM DD, YYYY'));
|
|
40
41
|
console.log('duration', res.context.query.duration('#duration'));
|
|
41
42
|
console.log('timestamp', res.context.query.duration('#timestamp'));
|
|
42
43
|
console.log('timestring', res.context.query.duration('#timestring'));
|