Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
ConvertOffsets | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
run | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | declare( strict_types = 1 ); |
3 | |
4 | namespace Wikimedia\Parsoid\Wt2Html\DOM\Processors; |
5 | |
6 | use Wikimedia\Assert\Assert; |
7 | use Wikimedia\Parsoid\Config\Env; |
8 | use Wikimedia\Parsoid\DOM\Node; |
9 | use Wikimedia\Parsoid\Logger\LintLogger; |
10 | use Wikimedia\Parsoid\Utils\ContentUtils; |
11 | use Wikimedia\Parsoid\Wt2Html\Wt2HtmlDOMProcessor; |
12 | |
13 | /** |
14 | * Very thin shim to call ContentUtils::convertOffsets where requested |
15 | * in the environment. |
16 | */ |
17 | class ConvertOffsets implements Wt2HtmlDOMProcessor { |
18 | /** |
19 | * DOM Postprocessor entry function to walk DOM rooted at $root |
20 | * and convert the DSR offsets as needed. |
21 | * @see ConvertUtils::convertOffsets |
22 | * |
23 | * @inheritDoc |
24 | */ |
25 | public function run( |
26 | Env $env, Node $root, array $options = [], bool $atTopLevel = false |
27 | ): void { |
28 | Assert::invariant( $atTopLevel, 'This pass should only be run on the top-level' ); |
29 | $doc = $root->ownerDocument; |
30 | $offsetType = $env->getRequestOffsetType(); |
31 | ContentUtils::convertOffsets( |
32 | $env, $doc, 'byte', $offsetType |
33 | ); |
34 | // Because linter runs before this DOM pass, we need to convert offsets |
35 | // of collected lints from 'byte' to the requested type |
36 | if ( $offsetType !== 'byte' ) { |
37 | $lints = $env->getLints(); |
38 | LintLogger::convertDSROffsets( $env, $lints, 'byte', $offsetType ); |
39 | $env->setLints( $lints ); |
40 | } |
41 | } |
42 | } |