requirements.definitions.phrase_rendering
Requirements index · View definition
Example
A definition named
glossary.first_parent_historydeclares 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.
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.mdchapter declaresfirst_parent_historywith:phrase: first-parent history. - A
guide.mdchapter 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 exactlyFollow 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 identifierglossary.first_parent_historyappears 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 containsid="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.iobadge. - 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*alpha* & <beta>. - 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]
- File:
tests/definitions.rs - Selector:
fn[phrases_are_plain_links_and_markdown_literals_are_preserved] - Kind:
fn tests/definitions.rs:590–633
// {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("*alpha* & <beta>")
);
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]
- File:
tests/definitions.rs - Selector:
fn[a_term_reference_renders_only_its_phrase_as_a_plain_link] - Kind:
fn tests/definitions.rs:635–666
// {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
requirements.definitions.references:md/requirements/definitions.md:9–13
:::{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
requirements.definitions.phrase_rendering:md/requirements/definitions.md:35–37
:::{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`
:::