marc0l92 / joplin-plugin-plantUML

Render PlantUML diagram inside your Joplin notes.
MIT License
47 stars 8 forks source link

Support for headers to be injected before all plantuml diagrams #1

Closed nsainaney closed 2 years ago

nsainaney commented 2 years ago

Thanks for the great plugin!

The Obsidian PlantUML plugin allows for injecting a header into every PlantUML diagram (after @startuml):

image

This makes it easy to inject headers like the following that are universal to all diagrams:

!theme cerulean-outline
skinparam linetype ortho
...etc

Would love to see this added!

marc0l92 commented 2 years ago

so you would like to have a new option: image

that you can use to add some plantUML commands that will be then injected at the begin of each diagram?

I think It is something we can do.

The only issue is related to the options api. At the moment I cannot create a textarea in the options but only a text input that can contain only one line.

I will ask to add the textarea in the options api and in the meanwhile we will find a workaround.

Do you prefer to have the limitation of only one line of header? or maybe it is better to have multiple lines that are comma separated?

nsainaney commented 2 years ago

Not sure comma would work as I believe comma's could be part of the UML code.

What about a path to a file that contains headers? The path could be ~/.joplin-desktop/my-plant-uml-header.iuml or wherever the user wants. Are you able to read the user's local computer? If not, it could be a note that contains the header.

But we could also wait for the Joplin folks to add textarea.

marc0l92 commented 2 years ago

I released the version 1.4.0 that contains the feature you requested. Let me know if it is what you expect and if it is working fine.

nsainaney commented 2 years ago

Hey Mark, Awesome work! Looks great:

With (my plantumlheader.iuml)

!theme cerulean-outline
skinparam linetype ortho

I get:

image

Some minor feedback. If you use path.resolve, relative paths like ~/.config/joplin-desktop/planumlheader.iuml will work. Also, you can use fs/promises so you don't have to do all that stuff with Buffer etc.

import fs from 'fs/promises'
import path from 'path'

...
async function readFileContent(filename: string): Promise<string> {
    const absolutePath = path.resolve(filename)
    const content = await fs.readFile(absolutePath, 'utf8')
    return content
}

I really appreciate the feature! Please feel free to close the issue.

marc0l92 commented 2 years ago

Thanks for your feedback. I'm using fs-extra because there is a bug in webpack that prevent me to use the basic fs module.

One day I will may be able to fix it. I implemented your changes and you can now use relative paths.