Document.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Services\Markup\Ir;
  3. /**
  4. * 一段内容的解析结果。
  5. *
  6. * - nodes:块级节点;inline 为真时整段只有一个段落,nodes 是该段落的行内节点(v2 的「单个 p 换成 span」)
  7. * - source:预扫描后的源码,模板位置是占位符 `\u{E000}n\u{E001}`,n 是 calls 的下标(markdown 输出用)
  8. * - calls:这段内容直接包含的全部模板调用(不含参数里嵌套的;那些在各自的 slot Document 里)
  9. * - fragment:一段行内节点的切片(如 issue 高亮包住的内容),原样渲染:html 不包 span、纯文本不按块换行
  10. */
  11. final class Document
  12. {
  13. /**
  14. * @param list<Node> $nodes
  15. * @param array<int, Call> $calls
  16. * @param array<int, Call> $annotationCalls 批注占位符下标 => 调用(只有点标记;markdown 输出替换源码里的占位符用)
  17. */
  18. public function __construct(
  19. public array $nodes,
  20. public bool $inline,
  21. public string $source,
  22. public array $calls,
  23. public Scope $scope,
  24. public bool $fragment = false,
  25. public array $annotationCalls = [],
  26. ) {}
  27. public static function empty(Scope $scope): self
  28. {
  29. return new self([], true, '', [], $scope);
  30. }
  31. public function isEmpty(): bool
  32. {
  33. return $this->nodes === [];
  34. }
  35. }