I am setting up a repository to store software documentation consisting of several documents which are written in Markdown, and I want to be able to embed PlantUML diagrams in them. The repository is hosted in Gitlab, which includes a PlantUML renderer but does not allow preprocessing and therefore using the !include
clause to reference diagrams in other files.
I would like to have a bash or python script that:
- Searches all .md files and append their content one after the other in a new file "all-docs.md".
- Searches in that file "all-docs.md" for all the
!include [FILEPATH]
clauses and replace the content which is between@startuml
and@enduml
from that file [FILEPATH] into "all-docs.md".
For example:
"all-docs.md" contains in certain part:
Here is the Profile class diagram:
``plantuml
@startuml
!include ./data-models/profile.puml
Profile o-- UidObject
@enduml
``
And profile.puml content is:
@startuml
class Profile <UidObject> {
+ string name
+ string email
+ string phone
+ Date birthDate
}
@enduml
The result after the script will be to have in "all-docs.md":
Here is the Profile class diagram:
``plantuml
@startuml
class Profile <UidObject> {
+ string name
+ string email
+ string phone
+ Date birthDate
}
Profile o-- UidObject
@enduml
``
The repo has the following structure.
/
├── assets/
├── docs/
├── uml/
- The
assets/
directory contains various assets such as images, icons, and other resources. - The
docs/
directory contains the documents (markdown files) - The
uml/
directory contains contains PlantUML source files that are used to generate diagrams for the software documentation.