RenderOptions.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace App\Services\Markup;
  3. /**
  4. * 一次渲染的选项。字段与 v2 MdRender 的 $options 一一对应(去掉了 debug / studioId / unity)。
  5. */
  6. final readonly class RenderOptions
  7. {
  8. /**
  9. * @param list<string> $channels 内容所属的 channel uid。句子模板默认读这些 channel 的译文,
  10. * 术语按第一个 channel 查;第一个 channel 的语言也是默认语言
  11. * @param string $mode read | edit:句子模板据此输出 sentread / sentedit
  12. * @param string $contentType markdown | markdown-e2 | json | html(取自 content_type 列)
  13. * @param string $channelType translation | nissaya:nissaya 的 `a=b` 行会转成 nissaya 模板
  14. * @param bool $footnote html / markdown 输出是否在末尾附脚注列表
  15. * @param bool $paragraph 巴汉逐段对读:只由句子模板组成的段落复制成原文段 + 译文段
  16. * @param bool $origin markdown 输出时句子模板是否带原文
  17. * @param bool $translation markdown 输出时句子模板是否带译文
  18. */
  19. public function __construct(
  20. public Format $format = Format::Tree,
  21. public array $channels = [],
  22. public string $mode = 'read',
  23. public string $contentType = 'markdown',
  24. public string $channelType = 'translation',
  25. public string $lang = 'zh-Hans',
  26. public bool $footnote = false,
  27. public bool $paragraph = false,
  28. public bool $origin = true,
  29. public bool $translation = true,
  30. ) {}
  31. public function dialect(): Dialect
  32. {
  33. return Dialect::fromContentType($this->contentType);
  34. }
  35. /**
  36. * @param array<string, mixed> $changes
  37. */
  38. public function with(array $changes): self
  39. {
  40. return new self(...array_merge(get_object_vars($this), $changes));
  41. }
  42. }