section

assessments

Wire value: "assessments"

Appears on: Tutorial (Project), Tutorial Article

1. How swift-docc-render consumes this

The assessments section kind is dispatched from two different top-level page components, both of which ultimately delegate to the same interactive quiz component.

In tutorial pages, Tutorial.vue keeps a static SectionComponents lookup table keyed by section.kind and maps assessments straight to Tutorial/Assessments.vue:

const SectionComponents = {
  assessments: Assessments,
  hero: Hero,
  tasks: SectionList,
  callToAction: CallToAction,
};

See Tutorial.vue#L46-L66 for the dispatch table and the TutorialSection render function that instantiates the matched component with the section's own properties spread as props.

In free-standing Article pages (a DocC "article" that includes a @Assessments block, not a full tutorial), Article.vue has its own parallel SectionKind map and routes assessments to a thin wrapper, Article/Assessments.vue:

const SectionKind = {
  articleBody: 'articleBody',
  callToAction: 'callToAction',
  hero: 'hero',
  assessments: 'assessments',
};
...
[SectionKind.assessments]: Assessments,   // Article/Assessments.vue

See Article.vue#L45-L167 (the SectionKind table, componentFor, and propsFor, which forwards only anchor and assessments from the section payload).

Article/Assessments.vue does not reimplement anything — it simply re-exports the tutorial component's props and renders it, supplying a custom #success slot string appropriate for an article rather than a tutorial:

<template>
  <TutorialAssessments v-bind="$props">
    <template #success>
      <p>Great job, you've answered all the questions for this article.</p>
    </template>
  </TutorialAssessments>
</template>

See Article/Assessments.vue#L11-L28.

The real behavior lives in Tutorial/Assessments.vue. It renders a LinkableElement (root class assessments-wrapper, anchored at the section's anchor), and inside it a grid Row with class assessments. The component keeps local state: activeIndex (which question of the assessments array is showing) and completed (whether the user has finished the quiz). While incomplete, it shows an AssessmentsProgress "Question N of M" indicator plus a Quiz child bound to this.assessments[this.activeIndex]; once completed is true it swaps to a success slot message instead:

<div v-if="!completed">
  <Progress v-bind="progress" ref="progress"/>
  <Quiz :choices="activeAssessment.choices" :content="activeAssessment.content"
        :isLast="isLast" :key="activeIndex" :title="activeAssessment.title"
        @submit="onSubmit" @advance="onAdvance" @see-results="onSeeResults" />
</div>
<div v-else class="success">
  <slot name="success"><p>{{ SuccessMessage }}</p></slot>
</div>

See Tutorial/Assessments.vue#L11-L170. onAdvance increments activeIndex and re-mounts Quiz (the :key binding forces a fresh instance per question); onSeeResults sets completed = true.

The actual per-question interaction — selecting a radio choice, checking correctness, revealing justification text, and enabling "Next" — lives one level deeper in Tutorial/Assessments/Quiz.vue, which renders a <fieldset class="choices"> of radio-button <label>s (v-model="selectedIndex"), tracks a userChoices array of { checked } flags, and computes showNextQuestion as "every choice flagged isCorrect has been checked" — i.e. the learner must find all correct answers (there can be more than one) before advancing. See Quiz.vue#L11-L152. Question and choice text is itself further delegated to the generic block-content renderer, ContentNode (<ContentNode :content="choice.content" />, etc.), since title/content/choices[].content/justification are all arrays of RenderBlockContent.

2. Example JSON and rendered mockup

No fixture in this repository's test archives or in swift-docc's own JSON test corpus contains a raw "kind": "assessments" literal (swift-docc's own coverage for this section, SemaToRenderNodeTests.swift, asserts against decoded Swift values rather than embedding a JSON literal). The example below is hand-written to match the schema in the data sheet.

{
  "kind": "assessments",
  "anchor": "Check-Your-Understanding",
  "assessments": [
    {
      "type": "multiple-choice",
      "title": [
        { "type": "paragraph", "inlineContent": [
          { "type": "text", "text": "Which method starts the animation?" }
        ] }
      ],
      "content": [
        { "type": "paragraph", "inlineContent": [
          { "type": "codeVoice", "code": "anchor.hitTest(view)" }
        ] }
      ],
      "choices": [
        {
          "content": [
            { "type": "paragraph", "inlineContent": [
              { "type": "codeVoice", "code": "startAnimating()" }
            ] }
          ],
          "isCorrect": true,
          "justification": [
            { "type": "paragraph", "inlineContent": [
              { "type": "text", "text": "This is correct because it starts the run loop." }
            ] }
          ]
        },
        {
          "content": [
            { "type": "paragraph", "inlineContent": [
              { "type": "codeVoice", "code": "stopAnimating()" }
            ] }
          ],
          "isCorrect": false,
          "justification": [
            { "type": "paragraph", "inlineContent": [
              { "type": "text", "text": "This stops the animation instead of starting it." }
            ] }
          ],
          "reaction": "Not quite!"
        }
      ]
    }
  ]
}

Rendered mockup approximating question 1 of 1, before an answer is chosen:

Question 1 of 1

Check Your Understanding

anchor.hitTest(view) — Which method starts the animation?

  • startAnimating()
  • stopAnimating()

3. Data sheet

Schema objects, from Sources/DocCArchive/Vendored/RenderNode.spec.json, cross-checked against the generated Components.Schemas.AssessmentsSection / .Assessment / .Choice types in Sources/DocCArchive/generated/Types.swift.

AssessmentsSection

FieldTypeRequiredEnum / defaultNote
kindstringyes"assessments" (only value)Discriminator; generated as KindPayload single-case enum.
anchorstringyes—Section anchor id for deep-linking, e.g. Check-Your-Understanding.
assessmentsarray of Assessmentyes—One entry per question; rendered one at a time in the UI.

Assessment

FieldTypeRequiredEnum / defaultNote
typestringyes"multiple-choice" (only value)Generated as _TypePayload.multipleChoice; only assessment kind DocC currently emits.
titlearray of RenderBlockContentyes—The question phrasing, rendered by ContentNode.
contentarray of RenderBlockContentno—Optional introductory content (often a code block) shown above the choices.
choicesarray of Choiceyes—Rendered as radio-button <label>s in Quiz.vue.

Choice

FieldTypeRequiredEnum / defaultNote
contentarray of RenderBlockContentyes—The answer text shown in the choice label.
isCorrectbooleanyes—Drives correct/incorrect CSS classes and icon choice once checked; a question can have more than one correct choice.
justificationarray of RenderBlockContentno—Explanation revealed only after that choice is selected.
reactionstringno—Plain-text aside shown after the choice is selected, alongside justification.

Source: Sources/DocCArchive/Vendored/RenderNode.spec.json lines 216-297 (schema objects AssessmentsSection, Assessment, Choice); generated types at Sources/DocCArchive/generated/Types.swift lines 3278-3384.

4. HTML/CSS mapping in DocC-Render output

5. Modern CSS-only alternative

Partial

Current behavior in play: Tutorial/Assessments.vue holds activeIndex and completed as Vue component data(), and swaps which question/success view is shown via v-if="!completed" plus re-keying the Quiz child on activeIndex; separately, Quiz.vue holds per-question state (selectedIndex, userChoices[]) and toggles correct/incorrect classes and reveal of justification/reaction text via a v-model-bound native <input type="radio" name="assessment"> per choice, with button :disabled bindings computed from that state.

The per-question choice interaction (select one radio, reveal that choice's justification, style it correct/incorrect) maps cleanly onto native CSS today: it is already implemented with a real <input type="radio"> group, so the "which choice is active/selected" half of the state could be held purely by :checked plus a general sibling or :has() selector (e.g. label:has(input:checked) .answer { display: block; }) with zero JavaScript, replacing the v-if="userChoices[index].checked" conditional reveal of the justification text. This part is squarely applicable to a native mechanism.

However, the section as a whole is not just a single self-contained toggle: correctness must be checked against server-supplied isCorrect data (CSS cannot compare a selected choice's identity against a data-defined "correct answer" — it can only react to which native form control is :checked, not evaluate a boolean encoded in JSON), and advancing between questions (onAdvance) replaces the entire rendered question array element (a new Quiz instance keyed by activeIndex, driven by this.assessments[this.activeIndex]) rather than toggling visibility of pre-rendered siblings, and onSeeResults/onSubmit also perform imperative scroll-into-view logic (scrollTo/scrollIntoView with a navigation-bar height offset). None of that survives translation to a static selector — it depends on which answer the schema marks correct and on scripted scroll positioning. For that reason the overall assessments section is rated partial: the single-choice reveal/highlight interaction per question is a good :checked/:has() fit, but correctness evaluation against JSON data and multi-question progression/auto-scroll are not expressible in CSS alone.