Common use of Selectors Clause in Contracts

Selectors. ‌ Selectors in rinohtype select elements of a particular type. The class of a document element serves as a selector for all instances of the class (and its subclasses). The Paragraph class is a selector that matches all paragraphs in the document, for example: Paragraph As with CSS selectors, elements can also be matched based on their context. For example, the following matches any paragraph that is a direct child of a list item or in other words, a list item label: ListItem / Paragraph Python’s ellipsis can be used to match any number of levels of elements in the document tree. The following selector matches paragraphs at any level inside a table cell: TableCell / ... / Paragraph To help avoid duplicating selector definitions, context selectors can reference other selectors defined in the same Section 5.3 using SelectorByName: SelectorByName('definition term') / ... / Paragraph Selectors can select all instances of Styled subclasses. These include Flowable and StyledText, but also TableSection, TableRow, Line and Shape. Elements of some of the latter classes only appear as children of other flowables (such as Table). Similar to a HTML element’s class attribute, Styled elements can have an optional style attribute which can be used when constructing a selector. This one selects all styled text elements with the emphasis style, for example: ▇▇▇▇▇▇▇▇▇▇.▇▇▇▇('emphasis') The ▇▇▇▇▇▇.▇▇▇▇() method can also match arbitrary attributes of elements by passing them as keyword arguments. This can be used to do more advanced things such as selecting the back- ground objects on all odd rows of a table, limited to the cells not spanning multiple rows: ▇▇▇▇▇▇▇▇▇.▇▇▇▇(row_index=slice(0, None, 2), rowspan=1) / TableCellBackground The argument passed as row_index is a slice object that is used for extended indexing2. To make this work, TableCell.row_index is an object with a custom eq () that allows compar- ▇▇▇▇ to a slice. Rinohtype borrows CSS’s concept of specificity to determine the “winning” selector when multiple selectors match a given document element. Each part of a selector adds to the speci- ficity of a selector. Roughly stated, the more specific selector will win. For example: ListItem / Paragraph # specificity (0, 0, 0, 0, 2) wins over: Paragraph # specificity (0, 0, 0, 0, 1) since it matches two elements instead of just one. Specificity is represented as a 5-tuple. The last four elements represent the number of location (currently not used), style, attribute and class matches. Here are some selectors along with their specificity: ▇▇▇▇▇▇▇▇▇▇.▇▇▇▇('emphasis') # specificity (0, 0, 1, 0, 1) TableCell / ... / Paragraph # specificity (0, 0, 0, 0, 2) ▇▇▇▇▇▇▇▇▇.▇▇▇▇(row_index=2, rowspan=1) # specificity (0, 0, 0, 2, 1) Specificity ordering is the same as tuple ordering, so (0, 0, 1, 0, 0) wins over (0, 0, 0, 5, 0) and (0, 0, 0, 0, 3) for example. Only when the number of style matches are equal, the attributes match count is compared and so on. In practice, the class match count is dependent on the element being matched. If the class of the element exactly matches the selector, the right-most specificity value is increased by 2. If the element’s class is a subclass of the selector, it is only increased by 1. The first element of the specificity tuple is the priority of the selector. For most selectors, the priority will have the default value of 0. The priority of a selector only needs to be set in some cases. For example, we want the CodeBlock selector to match a CodeBlock instance. However, because CodeBlock is a Paragraph subclass, another selector with a higher speci- ficity will also match it: CodeBlock # specificity (0, 0, 0, 0, 2) DefinitionList / Definition / Paragraph # specificity (0, 0, 0, 0, 3) To make sure the CodeBlock selector wins, we increase the priority of the CodeBlock selector by prepending it with a + sign: +CodeBlock # specificity (1, 0, 0, 0, 2) In general, you can use multiple + or - signs to adjust the priority: ++CodeBlock ---CodeBlock # specificity (2, 0, 0, 0, 2) # specificity (-3, 0, 0, 0, 2) 2 Indexing a list like this lst[slice(0, None, 2)] is equivalent to lst[0::2].

Appears in 1 contract

Sources: User Manual

Selectors. ‌ Selectors in rinohtype select elements of a particular type. The class of a document element serves as a selector for all instances of the class (and its subclasses). The Paragraph class is a selector that matches all paragraphs in the document, for example: Paragraph As with CSS selectors, elements can also be matched based on their context. For example, the following matches any paragraph that is a direct child of a list item or in other words, a list item label: ListItem / Paragraph Python’s ellipsis can be used to match any number of levels of elements in the document tree. The following selector matches paragraphs at any level inside a table cell: TableCell / ... / Paragraph To help avoid duplicating selector definitions, context selectors can reference other selectors defined in the same Section 5.3 using SelectorByName: SelectorByName('definition term') / ... / Paragraph Selectors can select all instances of Styled subclasses. These include Flowable and StyledText, but also TableSection, TableRow, Line and Shape. Elements of some of the latter classes only appear as children of other flowables (such as Table). Similar to a HTML element’s class attribute, Styled elements can have an optional style attribute which can be used when constructing a selector. This one selects all styled text elements with the emphasis style, for example: ▇▇▇▇▇▇▇▇▇▇.▇▇▇▇('emphasis') The ▇▇▇▇▇▇.▇▇▇▇() method can also match arbitrary attributes of elements by passing them as keyword arguments. This can be used to do more advanced things such as selecting the back- ground objects on all odd rows of a table, limited to the cells not spanning multiple rows: ▇▇▇▇▇▇▇▇▇.▇▇▇▇(row_index=slice(0, None, 2), rowspan=1) / TableCellBackground The argument passed as row_index is a slice object that is used for extended indexing2. To make this work, TableCell.row_index is an object with a custom eq () that allows compar- ▇▇▇▇ comparison to a slice. Rinohtype borrows CSS’s concept of specificity to determine the “winning” selector when multiple selectors match a given document element. Each part of a selector adds to the speci- ficity of a selector. Roughly stated, the more specific selector will win. For example: ListItem / Paragraph # specificity (0, 0, 0, 0, 2) wins over: Paragraph # specificity (0, 0, 0, 0, 1) since it matches two elements instead of just one. Specificity is represented as a 5-tuple. The last four elements represent the number of location (currently not used), style, attribute and class matches. Here are some selectors along with their specificity: ▇▇▇▇▇▇▇▇▇▇.▇▇▇▇('emphasis') # specificity (0, 0, 1, 0, 1) TableCell / ... / Paragraph # specificity (0, 0, 0, 0, 2) ▇▇▇▇▇▇▇▇▇.▇▇▇▇(row_index=2, rowspan=1) # specificity (0, 0, 0, 2, 1) Specificity ordering is the same as tuple ordering, so (0, 0, 1, 0, 0) wins over (0, 0, 0, 5, 0) and (0, 0, 0, 0, 3) for example. Only when the number of style matches are equal, the attributes match count is compared and so on. In practice, the class match count is dependent on the element being matched. If the class of the element exactly matches the selector, the right-most specificity value is increased by 2. If the element’s class is a subclass of the selector, it is only increased by 1. The first element of the specificity tuple is the priority of the selector. For most selectors, the priority will have the default value of 0. The priority of a selector only needs to be set in some cases. For example, we want the CodeBlock selector to match a CodeBlock instance. However, because CodeBlock is a Paragraph subclass, another selector with a higher speci- ficity specificity will also match it: CodeBlock # specificity (0, 0, 0, 0, 2) DefinitionList / Definition / Paragraph # specificity (0, 0, 0, 0, 3) To make sure the CodeBlock selector wins, we increase the priority of the CodeBlock selector by prepending it with a + sign: +CodeBlock # specificity (1, 0, 0, 0, 2) In general, you can use multiple + or - signs to adjust the priority: ++CodeBlock ---CodeBlock # specificity (2, 0, 0, 0, 2) # specificity (-3, 0, 0, 0, 2) 2 Indexing a list like this lst[slice(0, None, 2)] is equivalent to lst[0::2].

Appears in 1 contract

Sources: User Manual

Selectors. ‌ Selectors in rinohtype select elements of a particular type. The class of a document element serves as a selector for all instances of the class (and its subclasses). The Paragraph class is a selector that matches all paragraphs in the document, for example: Paragraph As with CSS selectors, elements can also be matched based on their context. For example, the following matches any paragraph that is a direct child of a list item or in other words, a list item label: ListItem / Paragraph Python’s ellipsis can be used to match any number of levels of elements in the document tree. The following selector matches paragraphs at any level inside a table cell: TableCell / ... / Paragraph To help avoid duplicating selector definitionsdefinitions, context selectors can reference other selectors defined defined in the same Section 5.3 using SelectorByName: SelectorByName('definition term') / ... / Paragraph Selectors can select all instances of Styled subclasses. These include Flowable and StyledText, but also TableSection, TableRow, Line and Shape. Elements of some of the latter classes only appear as children of other flowables flowables (such as Table). Similar to a HTML element’s class attribute, Styled elements can have an optional style attribute which can be used when constructing a selector. This one selects all styled text elements with the emphasis style, for example: ▇▇▇▇▇▇▇▇▇▇.▇▇▇▇('emphasis') The ▇▇▇▇▇▇.▇▇▇▇() method can also match arbitrary attributes of elements by passing them as keyword arguments. This can be used to do more advanced things such as selecting the back- ground objects on all odd rows of a table, limited to the cells not spanning multiple rows: ▇▇▇▇▇▇▇▇▇.▇▇▇▇(row_index=slice(0, None, 2), rowspan=1) / TableCellBackground The argument passed as row_index is a slice object that is used for extended indexing2. To make this work, TableCell.row_index is an object with a custom eq () that allows compar- ▇▇▇▇ to a slice. Rinohtype borrows CSS’s concept of specificity specificity to determine the “winning” selector when multiple selectors match a given document element. Each part of a selector adds to the speci- ficity ficity of a selector. Roughly stated, the more specific specific selector will win. For example: ListItem / Paragraph # specificity (0, 0, 0, 0, 2) wins over: Paragraph # specificity (0, 0, 0, 0, 1) since it matches two elements instead of just one. Specificity Specificity is represented as a 5-tuple. The last four elements represent the number of location (currently not used), style, attribute and class matches. Here are some selectors along with their specificityspecificity: ▇▇▇▇▇▇▇▇▇▇.▇▇▇▇('emphasis') # specificity (0, 0, 1, 0, 1) TableCell / ... / Paragraph # specificity (0, 0, 0, 0, 2) ▇▇▇▇▇▇▇▇▇.▇▇▇▇(row_index=2, rowspan=1) # specificity (0, 0, 0, 2, 1) Specificity Specificity ordering is the same as tuple ordering, so (0, 0, 1, 0, 0) wins over (0, 0, 0, 5, 0) and (0, 0, 0, 0, 3) for example. Only when the number of style matches are equal, the attributes match count is compared and so on. In practice, the class match count is dependent on the element being matched. If the class of the element exactly matches the selector, the right-most specificity specificity value is increased by 2. If the element’s class is a subclass of the selector, it is only increased by 1. The first first element of the specificity specificity tuple is the priority of the selector. For most selectors, the priority will have the default value of 0. The priority of a selector only needs to be set in some cases. For example, we want the CodeBlock selector to match a CodeBlock instance. However, because CodeBlock is a Paragraph subclass, another selector with a higher speci- ficity specificity will also match it: CodeBlock # specificity (0, 0, 0, 0, 2) DefinitionList / Definition / Paragraph # specificity (0, 0, 0, 0, 3) To make sure the CodeBlock selector wins, we increase the priority of the CodeBlock selector by prepending it with a + sign: +CodeBlock # specificity (1, 0, 0, 0, 2) In general, you can use multiple + or - signs to adjust the priority: ++CodeBlock ---CodeBlock # specificity (2, 0, 0, 0, 2) # specificity (-3, 0, 0, 0, 2) 2 Indexing a list like this lst[slice(0, None, 2)] is equivalent to lst[0::2].

Appears in 1 contract

Sources: User Manual