Skip to content

Commit f67a81c

Browse files
[#8] Find specitems defined in table cells
[#8] Find specitems defined in table cells The Asciidoc Importer has been changed to also find specification items that are defined in table cells having the Asciidoc style. --------- Co-authored-by: Christoph Pirkl <4711730+kaklakariada@users.noreply.github.com>
1 parent 6fef78c commit f67a81c

File tree

3 files changed

+243
-168
lines changed

3 files changed

+243
-168
lines changed

doc/changes/changes_0.3.0.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# OpenFastTrace AsciiDoc Plugin 0.3.0, released YYYY-MM-DD
1+
# OpenFastTrace AsciiDoc Plugin 0.3.0, released 2025-03-05
22

33
Code name: Add support for Tags
44

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

1111
* [Issue #7](https://github.com/itsallcode/openfasttrace-asciidoc-plugin/issues/7): Add support for specifying OpenFastTrace Tags on specitems
12+
13+
## Bug Fixes
14+
15+
* [Issue #8](https://github.com/itsallcode/openfasttrace-asciidoc-plugin/issues/8): Asciidoc importer does not read specification items defined in table cells

src/main/java/org/itsallcode/openfasttrace/importer/asciidoc/AsciiDocImporter.java

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package org.itsallcode.openfasttrace.importer.asciidoc;
22

33
import java.util.*;
4+
import java.util.List;
45
import java.util.logging.Logger;
56
import java.util.stream.StreamSupport;
67

78
import org.asciidoctor.Asciidoctor;
89
import org.asciidoctor.Options;
9-
import org.asciidoctor.ast.Document;
10-
import org.asciidoctor.ast.StructuralNode;
10+
import org.asciidoctor.ast.*;
1111
import org.itsallcode.openfasttrace.api.core.Location;
1212
import org.itsallcode.openfasttrace.api.core.SpecificationItemId;
1313
import org.itsallcode.openfasttrace.api.importer.ImportEventListener;
@@ -31,7 +31,8 @@ class AsciiDocImporter implements Importer
3131
private static final String ROLE_COMMENT = ":comment";
3232
private static final String ROLE_DESCRIPTION = ":description";
3333
private static final String ROLE_RATIONALE = ":rationale";
34-
private static final String ROLE_SPECITEM = ":specitem";
34+
35+
private static final String ROLE_NAME_SPECITEM = "specitem";
3536

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

@@ -219,6 +220,9 @@ private void processForwardingBlock(final String skippedType, final StructuralNo
219220
// [impl->dsn~adoc-artifact-forwarding-notation~1]
220221
private void processSpecificationItem(final StructuralNode block)
221222
{
223+
LOG.fine(() -> String.format("found specitem block [id: %s]",
224+
block.getId()));
225+
222226
Optional.ofNullable(block.getAttribute(ATTRIBUTE_OFT_SID))
223227
.filter(String.class::isInstance)
224228
.map(String.class::cast)
@@ -237,6 +241,41 @@ private void processSpecificationItem(final StructuralNode block)
237241
""".formatted(getLocation(block)))));
238242
}
239243

244+
private void processDocument(final Document document)
245+
{
246+
document.getBlocks().forEach(this::processBlock);
247+
}
248+
249+
private void processBlock(final StructuralNode block)
250+
{
251+
if (block.hasRole(ROLE_NAME_SPECITEM))
252+
{
253+
processSpecificationItem(block);
254+
}
255+
else if (block instanceof final Table table)
256+
{
257+
processTable(table);
258+
}
259+
else
260+
{
261+
block.getBlocks().forEach(this::processBlock);
262+
}
263+
}
264+
265+
private void processTable(final Table table)
266+
{
267+
table.getBody().forEach(row -> row.getCells().forEach(cell -> {
268+
final Document innerDocument = cell.getInnerDocument();
269+
if (innerDocument != null)
270+
{
271+
// if the cell has the Asciidoc style, then the content
272+
// is itself an Asciidoc Document that may contain
273+
// specification items
274+
processDocument(innerDocument);
275+
}
276+
}));
277+
}
278+
240279
// [impl->dsn~adoc-specification-item-markup~1]
241280
private Document parseAsciiDoc()
242281
{
@@ -268,10 +307,6 @@ else if (this.content != null)
268307
public void runImport()
269308
{
270309
final Document document = parseAsciiDoc();
271-
272-
document.findBy(Map.of(KEY_ROLE, ROLE_SPECITEM)).forEach(node -> {
273-
LOG.fine(() -> String.format("found specitem block [id: %s]", node.getId()));
274-
processSpecificationItem(node);
275-
});
310+
processDocument(document);
276311
}
277312
}

0 commit comments

Comments
 (0)