3.36. kink/doc/model/SECTION

Provides sections in docs.

A section is a tree node of a kink doc.

The top level section corresponds to an entire doc.

The second level sections correspond to mods.

Sections on the third and further levels typically correspond to funs, types and methods.

3.36.1. SECTION.new(Title Blocks Subsections)

SECTION.new makes a section.

Preconditions:

• Title must be a str

• Blocks must be a vec of blocks

• Subsections must be a vec of sections

3.36.2. SECTION.section?(Val)

section? returns whether Val is a section.

3.36.3. type section

A section in a doc.

Section.op_eq(Another_section) and Section.op_ne(Another_section)

Two sections are equal when they have the same title, blocks and subsections.

Section.title

title method returns the title of the section.

Section.blocks

blocks method returns the blocks in the section.

Section.subsections

subsections method returns the subsections of the section.

Section.to_json_val

to_json_val converts the Section to a JSON val.

Example:

:SECTION.require_from('kink/doc/model/')
:BLOCK.require_from('kink/doc/model/')
:JSON.require_from('kink/json/')

:Doc <- SECTION.new(
  'Doc title'
  [ BLOCK.new_paragraph('hey!') ]
  [ SECTION.new(
      'Section title'
      []
      []
    )
  ]
)
:Json_val <- Doc.to_json_val
stdout.print_line(JSON.stringify(Json_val))
# Output:
# {
#   "blocks": [
#     {
#       "text": "hey!",
#       "type": "paragraph"
#     }
#   ],
#   "subsections": [
#     {
#       "blocks": [],
#       "subsections": [],
#       "title": "Section title"
#     }
#   ],
#   "title": "Doc title"
# }