Skip to content

Commit

Permalink
docs: improve markdown rendering (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndr-brt authored Sep 23, 2024
1 parent 4dcb212 commit 35238b8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,24 @@ public MarkdownManifestRenderer(OutputStream output) {

@Override
public void renderDocumentHeader() {
stringBuilder.append(heading(DOCUMENT_HEADING, 1)).append(NEWLINE);
stringBuilder.append(NEWLINE);

}

@Override
public void renderModuleHeading(@Nullable String moduleName, @NotNull String modulePath, @NotNull String version) {
var name = ofNullable(moduleName).orElse(modulePath);
var modulePathTokens = modulePath.split(":");
var artifactId = modulePathTokens.length == 2 ? modulePathTokens[1] : modulePath;

var moduleHeading = heading(format("Module `%s:%s`", name, version), 2);
var moduleHeading = heading(format("Module `%s`", artifactId), 2);
stringBuilder.append(moduleHeading).append(NEWLINE);

if (moduleName != null) {
stringBuilder.append(italic(modulePath)).append(NEWLINE);
stringBuilder.append(italic("name: ")).append(moduleName).append(NEWLINE);
}
stringBuilder.append(NEWLINE);

stringBuilder
.append(italic("artifact: ")).append(modulePath).append(":").append(version).append(NEWLINE)
.append(NEWLINE);
}

@Override
Expand Down Expand Up @@ -122,7 +125,7 @@ public void renderConfigurations(List<ConfigurationSetting> configuration) {
.map(this::renderConfigurationSetting)
.forEach(tableBuilder::addRow);

stringBuilder.append(heading("Configuration: ", 5));
stringBuilder.append(heading("Configuration: ", 3));
if (!configuration.isEmpty()) {
stringBuilder.append(NEWLINE).append(NEWLINE).append(tableBuilder.build()).append(NEWLINE);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
* The ManifestRenderer interface provides callback methods to render a manifest document.
*/
public interface ManifestRenderer {
String DOCUMENT_HEADING = "EDC Autodoc Manifest";
String EXTENSION_POINTS = "Extension points";
String EXTENSIONS = "Extensions";
String NONE = "None";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,40 @@ void convert_simpleJson() {
assertThat(result).isNotNull().isEqualTo(testOutputStream);
}

@Test
void convert_emptyObject() {
var list = List.of(EdcModule.Builder.newInstance().modulePath("foo").version("0.1.0-bar").build());
@Nested
class Heading {

var result = writer.convert(list);
@Test
void shouldRenderHeading() {
var list = List.of(EdcModule.Builder.newInstance().modulePath("foo:bar").version("0.1.0-baz").build());

var result = writer.convert(list);

assertThat(result).isNotNull().isEqualTo(testOutputStream).extracting(Object::toString).satisfies(markdown -> {
assertThat(markdown).contains("Module `bar`");
assertThat(markdown).contains("_artifact: _foo:bar:0.1.0-baz");
assertThat(markdown).contains("### Extension points");
assertThat(markdown).contains("### Extensions");
assertThat(markdown).doesNotContain("Configuration:");
});
}

@Test
void shouldRenderHeading_whenModuleNameIsSet() {
var list = List.of(EdcModule.Builder.newInstance().name("module name").modulePath("foo:bar").version("0.1.0-baz").build());

var result = writer.convert(list);

assertThat(result).isNotNull().isEqualTo(testOutputStream).extracting(Object::toString).satisfies(markdown -> {
assertThat(markdown).contains("Module `bar`");
assertThat(markdown).contains("_name: _module name");
assertThat(markdown).contains("_artifact: _foo:bar:0.1.0-baz");
assertThat(markdown).contains("### Extension points");
assertThat(markdown).contains("### Extensions");
assertThat(markdown).doesNotContain("Configuration:");
});
}

assertThat(result).isNotNull().isEqualTo(testOutputStream).extracting(Object::toString).satisfies(markdown -> {
assertThat(markdown).contains("Module `foo:0.1.0-bar`");
assertThat(markdown).contains("### Extension points");
assertThat(markdown).contains("### Extensions");
assertThat(markdown).doesNotContain("Configuration:");
});
}

@Nested
Expand All @@ -83,7 +105,9 @@ void shouldRenderConfiguration() {

var result = writer.convert(list);

assertThat(result).isNotNull().extracting(Object::toString).asString().contains("Configuration:").contains("`test.key`");
assertThat(result).isNotNull().extracting(Object::toString).asString()
.contains("### Configuration:")
.contains("`test.key`");
}

@Test
Expand All @@ -94,7 +118,9 @@ void shouldRenderDeprecatedConfiguration() {

var result = writer.convert(list);

assertThat(result).isNotNull().extracting(Object::toString).asString().contains("Configuration:").contains("~~test.key~~");
assertThat(result).isNotNull().extracting(Object::toString).asString()
.contains("### Configuration:")
.contains("~~test.key~~");
}
}

Expand Down

0 comments on commit 35238b8

Please sign in to comment.