Skip to content

Commit

Permalink
chore: Add internal list of built-in contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
scouten committed Jan 6, 2025
1 parent 9533264 commit 2d81ff4
Show file tree
Hide file tree
Showing 3 changed files with 231 additions and 5 deletions.
32 changes: 32 additions & 0 deletions parser/src/blocks/context.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
pub(crate) fn is_built_in_context(context: &str) -> bool {
matches!(
context,
"admonition"
| "audio"
| "colist"
| "dlist"
| "document"
| "example"
| "floating_title"
| "image"
| "list_item"
| "listing"
| "literal"
| "olist"
| "open"
| "page_break"
| "paragraph"
| "pass"
| "preamble"
| "quote"
| "section"
| "sidebar"
| "table"
| "table_cell"
| "thematic_break"
| "toc"
| "ulist"
| "verse"
| "video"

Check warning on line 30 in parser/src/blocks/context.rs

View check run for this annotation

Codecov / codecov/patch

parser/src/blocks/context.rs#L1-L30

Added lines #L1 - L30 were not covered by tests
)
}

Check warning on line 32 in parser/src/blocks/context.rs

View check run for this annotation

Codecov / codecov/patch

parser/src/blocks/context.rs#L32

Added line #L32 was not covered by tests
4 changes: 4 additions & 0 deletions parser/src/blocks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ pub use block::Block;
mod compound_delimited;
pub use compound_delimited::CompoundDelimitedBlock;

mod context;
#[allow(unused)] // TEMPORARY
pub(crate) use context::is_built_in_context;

mod is_block;
pub use is_block::{ContentModel, IsBlock};

Expand Down
200 changes: 195 additions & 5 deletions parser/src/tests/asciidoc_lang/blocks/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ mod context {
use std::ops::Deref;

use crate::{
blocks::{Block, ContentModel, IsBlock},
blocks::{is_built_in_context, Block, ContentModel, IsBlock},
tests::sdd::{non_normative, to_do_verifies, verifies},
Span,
};
Expand Down Expand Up @@ -191,88 +191,282 @@ Some processors, such as Asciidoctor.js, store the context as a string instead.
|===
|Name | Purpose
"#
);

verifies!(
r#"
|admonition
|One of five admonition blocks.
"#
);

assert!(is_built_in_context("admonition"));

verifies!(
r#"
|audio
|An audio block.
"#
);

assert!(is_built_in_context("audio"));

verifies!(
r#"
|colist
|A callout list.
"#
);

assert!(is_built_in_context("colist"));

verifies!(
r#"
|dlist
|A description list.
"#
);

assert!(is_built_in_context("dlist"));

verifies!(
r#"
|document
|The top-level document or the document in an AsciiDoc table cell
"#
);

assert!(is_built_in_context("document"));

verifies!(
r#"
|example
|An example block.
"#
);

assert!(is_built_in_context("example"));

verifies!(
r#"
|floating_title
|A discrete heading.
"#
);

assert!(is_built_in_context("floating_title"));

verifies!(
r#"
|image
|An image block.
"#
);

assert!(is_built_in_context("image"));

verifies!(
r#"
|list_item
|An item in an ordered, unordered, or description list (only relevant inside a list or description list block).
In a description list, this block is used to represent the term and the description.
"#
);

assert!(is_built_in_context("list_item"));

verifies!(
r#"
|listing
|A listing block.
"#
);

assert!(is_built_in_context("listing"));

verifies!(
r#"
|literal
|A literal block.
"#
);

assert!(is_built_in_context("literal"));

verifies!(
r#"
|olist
|An ordered list.
"#
);

assert!(is_built_in_context("olist"));

verifies!(
r#"
|open
|An open block.
"#
);

assert!(is_built_in_context("open"));

verifies!(
r#"
|page_break
|A page break.
"#
);

assert!(is_built_in_context("page_break"));

verifies!(
r#"
|paragraph
|A paragraph.
"#
);

assert!(is_built_in_context("paragraph"));

verifies!(
r#"
|pass
|A passthrough block.
"#
);

assert!(is_built_in_context("pass"));

verifies!(
r#"
|preamble
|The preamble of the document.
"#
);

assert!(is_built_in_context("preamble"));

verifies!(
r#"
|quote
|A quote block (aka blockquote).
"#
);

assert!(is_built_in_context("quote"));

verifies!(
r#"
|section
|A section.
May also be a part, chapter, or special section.
"#
);

assert!(is_built_in_context("section"));

verifies!(
r#"
|sidebar
|A sidebar block.
"#
);

assert!(is_built_in_context("sidebar"));

verifies!(
r#"
|table
|A table block.
"#
);

assert!(is_built_in_context("table"));

verifies!(
r#"
|table_cell
|A table cell (only relevant inside a table block).
"#
);

assert!(is_built_in_context("table_cell"));

verifies!(
r#"
|thematic_break
|A thematic break (aka horizontal rule).
"#
);

assert!(is_built_in_context("thematic_break"));

verifies!(
r#"
|toc
|A TOC block (to designate custom TOC placement).
"#
);

assert!(is_built_in_context("toc"));

verifies!(
r#"
|ulist
|An unordered list.
"#
);

assert!(is_built_in_context("ulist"));

verifies!(
r#"
|verse
|A verse block.
"#
);

assert!(is_built_in_context("verse"));

verifies!(
r#"
|video
|A video block.
"#
);

assert!(is_built_in_context("video"));

non_normative!(
r#"
|===
NOTE: Each inline element also has a context, but those elements are not (yet) accessible from the parsed document model.
Expand All @@ -281,10 +475,6 @@ Additional contexts may be introduced through the use of the block, block macro,
"#
);

// Deemed non-normative because in asciidoc-parser, we don't provide a
// list of built-in contexts. (Context is a string, which is inherently
// extensible.)
}

#[test]
Expand Down

0 comments on commit 2d81ff4

Please sign in to comment.