Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

requirements.definitions.phrase_rendering

Requirements index · View definition

evidence Valid

Example

A definition named glossary.first_parent_history declares the phrase “first-parent history”. A term reference to that name renders the phrase as an ordinary hyperlink to the declaration, without displaying the identifier or a badge. cite requirements.definitions.references

Rationale

The example requirements.definitions.phrase_rendering gives a concrete case. A definition glossary.first_parent_history declares the phrase “first-parent history”. A term reference to it must render that phrase as an ordinary hyperlink to the declaration, with no identifier shown and no badge.

tests/definitions.rs#fn[a_term_reference_renders_only_its_phrase_as_a_plain_link] is marked {test} for the example. It reproduces the case with these inputs:

  • A glossary.md chapter declares first_parent_history with :phrase: first-parent history.
  • A guide.md chapter contains “Follow the {term}glossary.first_parent_history.”

It then runs habeas::preprocess_book and checks each expected outcome:

  • Plain link, phrase only, no badge or identifier: assert_eq! on the whole guide content requires exactly Follow the <a href="glossary.html#habeas-definition-glossary.first_parent_history">first-parent history</a>. That is a bare <a> with no class, no badge image, and the phrase as the only link text. The identifier glossary.first_parent_history appears only inside the href, never as displayed text.
  • Link goes to the declaration: the href uses the anchor habeas-definition-glossary.first_parent_history. The test also asserts that the glossary chapter contains id="habeas-definition-glossary.first_parent_history", so the link target exists.

phrases_are_plain_links_and_markdown_literals_are_preserved is also marked {test} for the example, and it adds coverage for the cited requirements.definitions.references:

  • It checks that there is no shields.io badge.
  • It checks that exactly one relative link is produced for a chapter in a subdirectory.
  • It checks that the phrase *alpha* & <beta> is escaped to &#42;alpha&#42; &amp; &lt;beta&gt;.
  • It checks that inline code, fenced code and escaped \{term} references stay literal.

Together these check the example’s scenario and every outcome it states. I found no gap.

Inputs

Tests

Input 3: outline tests/definitions.rs fn[phrases_are_plain_links_and_markdown_literals_are_preserved]
// {test}`requirements.definitions.phrase_rendering`
// {test}`requirements.definitions.references`
// {test}`requirements.definitions.declaration`
#[test]
fn phrases_are_plain_links_and_markdown_literals_are_preserved() {
    let temp = fixture();
    let mut book = Book::new();
    book.push_item(Chapter::new(
        "Glossary",
        ":::{definition} a\n:phrase: *alpha* & <beta>\n\nThe body.\n:::\n".into(),
        "glossary.md",
        Vec::new(),
    ));
    let source = "Use {term}`glossary.a`.\n\n`{term}`glossary.a``\n\n```text\n{term}`glossary.a`\n```\n\n\\{term}`glossary.a`".to_owned();
    book.push_item(Chapter::new("Guide", source, "guide/deep.md", Vec::new()));
    habeas::preprocess_book(&mut book, temp.path()).unwrap();
    let chapters: Vec<_> = book.chapters().collect();
    assert!(
        chapters[0]
            .content
            .contains("id=\"habeas-definition-glossary.a\"")
    );
    assert!(!chapters[0].content.contains(":phrase:"));
    assert!(!chapters[1].content.contains("shields.io"));
    assert_eq!(
        chapters[1]
            .content
            .matches("href=\"../glossary.html#habeas-definition-glossary.a\"")
            .count(),
        1
    );
    assert!(
        chapters[1]
            .content
            .contains("&#42;alpha&#42; &amp; &lt;beta&gt;")
    );
    for literal in [
        "`{term}`glossary.a``",
        "```text\n{term}`glossary.a`\n```",
        r"\{term}`glossary.a`",
    ] {
        assert!(chapters[1].content.contains(literal), "{literal:?}");
    }
}
Input 4: outline tests/definitions.rs fn[a_term_reference_renders_only_its_phrase_as_a_plain_link]
// {test}`requirements.definitions.phrase_rendering`
#[test]
fn a_term_reference_renders_only_its_phrase_as_a_plain_link() {
    let temp = fixture();
    let mut book = Book::new();
    book.push_item(Chapter::new(
        "Glossary",
        ":::{definition} first_parent_history\n:phrase: first-parent history\n\nHistory along first parents.\n:::\n".into(),
        "glossary.md",
        Vec::new(),
    ));
    book.push_item(Chapter::new(
        "Guide",
        "Follow the {term}`glossary.first_parent_history`.\n".to_owned(),
        "guide.md",
        Vec::new(),
    ));
    habeas::preprocess_book(&mut book, temp.path()).unwrap();
    let chapters: Vec<_> = book.chapters().collect();
    let guide = &chapters[1].content;
    // The whole reference becomes exactly one ordinary hyperlink: no class,
    // badge image, or other markup, and the phrase is the only link text.
    assert_eq!(
        guide.trim_end(),
        "Follow the <a href=\"glossary.html#habeas-definition-glossary.first_parent_history\">first-parent history</a>."
    );
    assert!(
        chapters[0]
            .content
            .contains("id=\"habeas-definition-glossary.first_parent_history\"")
    );
}

Referenced definitions

Input 2: requirements selection requirements.definitions.references
:::{req} references
The `{term}` role followed by a backtick-delimited full definition name MUST reference a named definition. In rendered Markdown, the reference MUST display the definition's phrase as an ordinary hyperlink to its anchored declaration, without a badge. The phrase MUST be escaped appropriately for rendering.

Missing targets and targets of another kind MUST be reported. Escaped references and references in Markdown code examples MUST remain literal. A term reference MUST NOT satisfy a requirement citation or a Rust function's requirement-coverage obligation.
:::

Other sources

Input 1: requirements selection requirements.definitions.phrase_rendering
:::{example} phrase_rendering
A definition named `glossary.first_parent_history` declares the phrase "first-parent history". A term reference to that name renders the phrase as an ordinary hyperlink to the declaration, without displaying the identifier or a badge. {cite}`requirements.definitions.references`
:::