public static String convertEmbeddedTablesIn(String text) { return new RenderMarkdown(text).convertTables(); }
public static String preprocessMarkdownTables(String text) { return new RenderMarkdown(text).injectNewLineBeforeTables(); }
private boolean switchingToATextSection(boolean inTable, String line) { return inTable && !isDataTableLine(line); }
private String convertTables() { if (noTablularLinesIn(lines)) { return originalText; } if (isRenderedMarkdownTableIn(tabularLinesIn(lines))) { return originalText; } return renderMarkdownTable(); }
private List<String> tabularLinesIn(List<String> lines) { List<String> tableLines = new ArrayList<>(); int row = lines.size() - 1; String line = lines.get(row); while (isDataTableLine(line) && row >= 0) { tableLines.add(trimSquareBracketsFrom(line)); line = lines.get(--row); } Collections.reverse(tableLines); return tableLines; }
private String injectNewLineBeforeTables() { List<NarrativeBlock> blocks = convertToBlocks(lines); List<String> spacedLines = new ArrayList<>(); for(NarrativeBlock block: blocks) { if (block.isTable()) { spacedLines.add(System.lineSeparator()); spacedLines.addAll(block.lines); } else { spacedLines.addAll(block.lines); } } return spacedLines.stream().collect(Collectors.joining(System.lineSeparator())); }
private List<String> markdownTable() { int columnCount = numberOfColumnsIn(lines); String separatorLine = "|" + StringUtils.repeat("---|", columnCount); List<String> markdownTable = new ArrayList<>(); markdownTable.add(System.lineSeparator()); markdownTable.add(lines.get(0)); markdownTable.add(separatorLine); for(int row = 1; row < lines.size(); row++) { markdownTable.add(lines.get(row)); } return markdownTable; } }
public static ScenarioOutcome outcomeFrom(TestOutcome testOutcome) { List<String> exampleTables = (testOutcome.isDataDriven()) ? Collections.singletonList(testOutcome.getDataTable().toMarkdown()) : Collections.EMPTY_LIST; String userStoryName = (testOutcome.getUserStory() != null) ? testOutcome.getUserStory().getName() : null; String userStoryReportName = (testOutcome.getUserStory() != null) ? testOutcome.getUserStory().getReportName() : null; List<String> steps = (testOutcome.getDataDrivenSampleScenario() != null && !testOutcome.getDataDrivenSampleScenario().isEmpty()) ? testStepsFromSampleScenario(testOutcome.getDataDrivenSampleScenario()) : testOutcome.getTestSteps() .stream().map(step -> RenderMarkdown.convertEmbeddedTablesIn(step.getDescription())).collect(Collectors.toList()); return new SingleScenarioOutcome( testOutcome.getQualified().withContext().getTitleWithLinks(), testOutcome.getName(), "Acceptance Test", testOutcome.getResult(), ReportNamer.forReportType(ReportType.HTML).getNormalizedTestNameFor(testOutcome), testOutcome.getStartTime(), testOutcome.getDuration(), testOutcome.isManual(), testOutcome.getDescription(), steps, exampleTables, testOutcome.getDataTableRowCount(), userStoryName, userStoryReportName); }
private String renderMarkdownTable() { List<NarrativeBlock> blocks = convertToBlocks(lines); List<String> markdownTable = new ArrayList<>(); blocks.forEach( block -> markdownTable.addAll(block.asMarkdown()) ); return markdownTable.stream().collect(Collectors.joining(System.lineSeparator())) + System.lineSeparator(); }
private boolean switchingToATableSection(boolean inTable, String line) { return !inTable && isDataTableLine(line); }