CitesParagraph.php 961 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace App\Services\Markup\Templates\Concerns;
  3. use App\Services\Markup\Ir\Call;
  4. use App\Services\PaliSeriesesService;
  5. /**
  6. * 嵌入经文段落 / 章节的模板({{para}}、{{chapter}}、{{article|type=chapter|para}})的标题规则:
  7. * `style=reference`(行内引用)且没给标题时,标题用 wikipali 缩写 + 段号(如 `dī.ni.1.168`),
  8. * 查不到缩写时用 id 本身。
  9. */
  10. trait CitesParagraph
  11. {
  12. /**
  13. * @param string $id 段落 / 章节 id(`book-para`)
  14. */
  15. protected function citedTitle(Call $call, string $id): string
  16. {
  17. $title = (string) $call->param('title');
  18. if ($title !== '' || (string) $call->param('style') !== 'reference') {
  19. return $title;
  20. }
  21. $ref = self::paragraphRef($id)[0] ?? null;
  22. if ($ref === null) {
  23. return $id;
  24. }
  25. return app(PaliSeriesesService::class)->citation($ref[0], $ref[1]) ?? $id;
  26. }
  27. }