references.typ 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // ==========================================
  2. // DOMAIN: БИБЛИОГРАФИЧЕСКИЕ СЕКЦИИ
  3. // ==========================================
  4. #import "document.typ": fail
  5. #let bibliography-section(
  6. id,
  7. sources,
  8. title: auto,
  9. style: "gost-r-705-2008-numeric",
  10. target: auto,
  11. group: auto,
  12. full: false,
  13. page_break: true,
  14. ) = {
  15. if type(id) != str or id.trim() == "" {
  16. fail("bibliography.id", "нужна непустая строка")
  17. }
  18. let normalized-sources = if type(sources) == array { sources } else { (sources,) }
  19. if normalized-sources.len() == 0 {
  20. fail("bibliography.sources", "нужен хотя бы один источник")
  21. }
  22. for source in normalized-sources {
  23. if type(source) not in (str, path, bytes) {
  24. fail("bibliography.sources", "ожидались str, path или bytes")
  25. }
  26. }
  27. if type(full) != bool {
  28. fail("bibliography.full", "ожидался bool")
  29. }
  30. if type(page_break) != bool {
  31. fail("bibliography.page-break", "ожидался bool")
  32. }
  33. (
  34. kind: "bibliography-section",
  35. id: id,
  36. sources: normalized-sources,
  37. title: title,
  38. style: style,
  39. target: target,
  40. group: group,
  41. full: full,
  42. page-break: page_break,
  43. )
  44. }
  45. #let validate-bibliographies(sections) = {
  46. if type(sections) != array {
  47. fail("bibliographies", "ожидался array")
  48. }
  49. let seen = ()
  50. for section in sections {
  51. if type(section) != dictionary or section.at("kind", default: none) != "bibliography-section" {
  52. fail("bibliographies", "каждый элемент должен быть bibliography-section")
  53. }
  54. if section.id in seen {
  55. fail("bibliographies", "повторяющийся id " + repr(section.id))
  56. }
  57. seen.push(section.id)
  58. }
  59. sections
  60. }