@@ -38,8 +38,8 @@ use crate::prelude::*;
38
38
/// >>> )
39
39
/// #set page(header: locate(loc => {
40
40
/// let elems = query(
41
- /// heading,
42
- /// before: loc,
41
+ /// selector( heading).before(loc) ,
42
+ /// loc,
43
43
/// )
44
44
/// let academy = smallcaps[
45
45
/// Typst Academy
@@ -102,8 +102,7 @@ pub fn query(
102
102
/// elements with an explicit label. As a result, you _can_ query for e.g.
103
103
/// [`strong`]($func/strong) elements, but you will find only those that
104
104
/// have an explicit label attached to them. This limitation will be
105
- /// resolved
106
- /// in the future.
105
+ /// resolved in the future.
107
106
target : LocatableSelector ,
108
107
109
108
/// Can be any location. Why is it required then? As noted before, Typst has
@@ -115,39 +114,25 @@ pub fn query(
115
114
/// could depend on the query's result.
116
115
///
117
116
/// Only one of this, `before`, and `after` shall be given.
118
- #[ external]
119
- #[ default]
120
117
location : Location ,
118
+ ) -> Value {
119
+ let _ = location;
120
+ vm. vt . introspector . query ( & target. 0 ) . into ( )
121
+ }
121
122
122
- /// If given, returns only those elements that are before the given
123
- /// location. A suitable location can be retrieved from
124
- /// [`locate`]($func/locate), but also through the
125
- /// [`location()`]($type/content.location) method on content returned by
126
- /// another query. Only one of `location`, this, and `after` shall be given.
127
- #[ named]
128
- #[ external]
129
- #[ default]
130
- before : Location ,
131
-
132
- /// If given, returns only those elements that are after the given location.
133
- /// A suitable location can be retrieved from [`locate`]($func/locate), but
134
- /// also through the [`location()`]($type/content.location) method on
135
- /// content returned by another query. Only one of `location`, `before`, and
136
- /// this shall be given.
137
- #[ named]
138
- #[ external]
139
- #[ default]
140
- after : Location ,
123
+ /// Turns a value into a selector. The following values are accepted:
124
+ /// - An element function like a `heading` or `figure`.
125
+ /// - A `{<label>}`.
126
+ /// - A more complex selector like `{heading.where(level: 1)}`.
127
+ ///
128
+ /// Display: Selector
129
+ /// Category: meta
130
+ /// Returns: content
131
+ #[ func]
132
+ pub fn selector (
133
+ /// Can be an element function like a `heading` or `figure`, a `{<label>}`
134
+ /// or a more complex selector like `{heading.where(level: 1)}`.
135
+ target : Selector ,
141
136
) -> Value {
142
- let selector = target. 0 ;
143
- let introspector = vm. vt . introspector ;
144
- let elements = if let Some ( location) = args. named ( "before" ) ? {
145
- introspector. query_before ( selector, location)
146
- } else if let Some ( location) = args. named ( "after" ) ? {
147
- introspector. query_after ( selector, location)
148
- } else {
149
- let _: Location = args. expect ( "location" ) ?;
150
- introspector. query ( selector)
151
- } ;
152
- elements. into ( )
137
+ target. into ( )
153
138
}
0 commit comments