Cell.java
package pro.verron.asciidoc.core;
import org.jspecify.annotations.Nullable;
import java.util.List;
import java.util.Optional;
/// Table cell containing block-level content.
public class Cell {
private final @Nullable String style;
private final List<Block> blocks;
/// Constructs a [Cell] without a style.
///
/// @param blocks cell content blocks
public Cell(List<Block> blocks) {
this(blocks, null);
}
/// Constructs a [Cell] with an optional style.
///
/// @param blocks cell content blocks
/// @param style optional cell style, or `null`
public Cell(List<Block> blocks, @Nullable String style) {
this.blocks = List.copyOf(blocks);
this.style = style;
}
/// Creates a [Cell] by wrapping [Inline] elements into a [Paragraph].
///
/// @param inlines inline elements to wrap into a [Paragraph]
/// @return a [Cell] containing the specified inlines as a single [Paragraph]
public static Cell ofInlines(List<Inline> inlines) {
return new Cell(List.of(new Paragraph(inlines)));
}
/// Returns the cell content blocks.
///
/// @return the list of [Block] elements in this cell
public List<Block> blocks() {
return blocks;
}
/// Returns the cell style, if set.
///
/// @return an [Optional] containing the style name, or [Optional#empty()]
public Optional<String> style() {
return Optional.ofNullable(style);
}
}