Markdown in IntelliJ IDEA as a separate art form. Draw diagrams and call bash commands
Spring developers often write documentation and README/HELP files for their applications. This is often done in Markdown files. Markdown The plugin in IntelliJ IDEA recognizes files, provides a special editor with highlighting, autocomplete and formatting, and also provides a visual display in the preview panel in real time. In addition to the standard functionality, IntelliJ IDEA has a couple of unique features that the team Spring AIO I would like to highlight in particular.
Displaying Mermaid and PlantUML diagrams
What about display? Mermaid And PlantUML diagrams? To support their display, you will need to install the appropriate plugins. It is enough to declare a block of code in a markdown file with the indication plantuml
or mermaid
language, and in the tab with visual display you will see a full-fledged diagram.
By the way, the display of Mermaid charts also supports GitHub Markdown Preview. Unfortunately, there is no support for PlantUML on GitHub.
Executing terminal commands
When you clone a project, there is usually a README.md file with instructions and commands for running the application, setting up the environment, etc. IntelliJ IDEA detects these commands and provides icons to run them. The following code blocks will be executable in IDEA:
Since IDEA Ultimate supports http client is becoming further and further away from Russian developers (one, two and three), it is worth considering separately the execution of cURL commands through a markdown file. Just like in http files, you can describe GET, POST, DELETE and other HTTP requests and execute them from a markdown file to check the functionality of your endpoints.
Not only bash scripts
But if the functionality of bash is not enough (or you are allergic to bash), then you can use a full-fledged language such as kotlin, java, groovy, etc. It is enough to call pre-prepared scripts in kotlin/groovy scripts from markdown or JBANG (if anyone remembers what it is).
Let's try import replacing IntelliJ http client through one file again kotlinscript.
We create
.kts
file. There is an interesting feature here. In order for the file to start and support all auto-completions, adding dependencies, etc., the file must end in.main.kts
.Let's add a library to our script RestAssuredthrough a special design:
@file:DependsOn("io.rest-assured:rest-assured:5.4.0")
Let's write a simple test with verification and output of the result:
import io.restassured.RestAssured.* import org.hamcrest.Matchers.* baseURI = "http://localhost:8089/rest" get("/owners?city=Madison&sort=firstName") .then().log().body(true) .statusCode(200) .body("content[0].firstName", equalTo("David")) .body("content[1].firstName", equalTo("Maria")) .body("content[2].firstName", equalTo("Peter"))
We can now run this script by calling the command
Run .main.kts
from the context menu of this file.Let's add a call to this script via the utility kotlinc in markdown file:
kotlinc -script ./test/rest.main.kts
The advantages of this approach over http client are obvious, we have all the capabilities of the language and a real framework for testing.
You can read about other options for editing and viewing markdown files in documentation.
Join the Russian-speaking Spring Boot developer community in telegram – Spring AIOto stay up to date with the latest news from the world of Spring Boot development and everything related to it.
Waiting for everybody, join us!