Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion doc/changes/changes_0.3.0.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# OpenFastTrace AsciiDoc Plugin 0.3.0, released YYYY-MM-DD
# OpenFastTrace AsciiDoc Plugin 0.3.0, released 2025-03-05

Code name: Add support for Tags

Expand All @@ -9,3 +9,7 @@ Starting with this release, OpenFastTrace Tags can be set on specification items
## Features

* [Issue #7](https://github.com/itsallcode/openfasttrace-asciidoc-plugin/issues/7): Add support for specifying OpenFastTrace Tags on specitems

## Bug Fixes

* [Issue #8](https://github.com/itsallcode/openfasttrace-asciidoc-plugin/issues/8): Asciidoc importer does not read specification items defined in table cells
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.itsallcode.openfasttrace.importer.asciidoc;

import java.util.*;
import java.util.List;
import java.util.logging.Logger;
import java.util.stream.StreamSupport;

import org.asciidoctor.Asciidoctor;
import org.asciidoctor.Options;
import org.asciidoctor.ast.Document;
import org.asciidoctor.ast.StructuralNode;
import org.asciidoctor.ast.*;
import org.itsallcode.openfasttrace.api.core.Location;
import org.itsallcode.openfasttrace.api.core.SpecificationItemId;
import org.itsallcode.openfasttrace.api.importer.ImportEventListener;
Expand All @@ -31,7 +31,8 @@ class AsciiDocImporter implements Importer
private static final String ROLE_COMMENT = ":comment";
private static final String ROLE_DESCRIPTION = ":description";
private static final String ROLE_RATIONALE = ":rationale";
private static final String ROLE_SPECITEM = ":specitem";

private static final String ROLE_NAME_SPECITEM = "specitem";

private static final Logger LOG = Logger.getLogger(AsciiDocImporter.class.getName());

Expand Down Expand Up @@ -219,6 +220,9 @@ private void processForwardingBlock(final String skippedType, final StructuralNo
// [impl->dsn~adoc-artifact-forwarding-notation~1]
private void processSpecificationItem(final StructuralNode block)
{
LOG.fine(() -> String.format("found specitem block [id: %s]",
block.getId()));

Optional.ofNullable(block.getAttribute(ATTRIBUTE_OFT_SID))
.filter(String.class::isInstance)
.map(String.class::cast)
Expand All @@ -237,6 +241,41 @@ private void processSpecificationItem(final StructuralNode block)
""".formatted(getLocation(block)))));
}

private void processDocument(final Document document)
{
document.getBlocks().forEach(this::processBlock);
}

private void processBlock(final StructuralNode block)
{
if (block.hasRole(ROLE_NAME_SPECITEM))
{
processSpecificationItem(block);
}
else if (block instanceof final Table table)
{
processTable(table);
}
else
{
block.getBlocks().forEach(this::processBlock);
}
}

private void processTable(final Table table)
{
table.getBody().forEach(row -> row.getCells().forEach(cell -> {
final Document innerDocument = cell.getInnerDocument();
if (innerDocument != null)
{
// if the cell has the Asciidoc style, then the content
// is itself an Asciidoc Document that may contain
// specification items
processDocument(innerDocument);
}
}));
}

// [impl->dsn~adoc-specification-item-markup~1]
private Document parseAsciiDoc()
{
Expand Down Expand Up @@ -268,10 +307,6 @@ else if (this.content != null)
public void runImport()
{
final Document document = parseAsciiDoc();

document.findBy(Map.of(KEY_ROLE, ROLE_SPECITEM)).forEach(node -> {
LOG.fine(() -> String.format("found specitem block [id: %s]", node.getId()));
processSpecificationItem(node);
});
processDocument(document);
}
}
Loading