-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRendered.php
More file actions
61 lines (53 loc) · 1.44 KB
/
Copy pathRendered.php
File metadata and controls
61 lines (53 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
/**
* Italix Documents - Rendered
*
* @package Italix\Documents
*/
declare(strict_types=1);
namespace Italix\Documents;
/**
* The output of a renderer: HTML, plus the plain text and the links found.
*
* All three come out of one parse because that parse already walked the whole
* document. Extracting links by re-reading the HTML afterwards would be a second
* pass over the same data and a worse one — the parser knows a link inside a
* code fence is not a link, and a regular expression does not.
*/
final class Rendered
{
private string $html;
private string $text;
/** @var string[] raw link targets, in document order, deduplicated */
private array $links;
/**
* @param string[] $links
*/
public function __construct(string $html, string $text = '', array $links = [])
{
$this->html = $html;
$this->text = $text;
$this->links = array_values(array_unique($links));
}
public function html(): string
{
return $this->html;
}
/** For the search index. */
public function text(): string
{
return $this->text;
}
/**
* @return string[]
*/
public function links(): array
{
return $this->links;
}
}