lukeorth / poison

Professional Hugo theme for dev bloggers. Based on Mdo's classic Hyde theme.
https://poison.lukeorth.com
GNU General Public License v3.0
205 stars 97 forks source link

Add support for plantuml rendering #46

Closed traveltissues closed 1 year ago

traveltissues commented 1 year ago

This was something I ended up adding to my fork for some posts I was thinking of. I think some people might find it useful.

lukeorth commented 1 year ago

Thank you, @traveltissues! I hadn't heard about PlantUML diagrams before, but they look useful. Definitely a nice thing to include.

I tweaked the PR just a bit. I'm trying not to rely on CDNs and host all dependencies locally in this project. As a result, I removed the CDN references and downloaded the raw plantuml-encoder.min.js script to static/js. I also moved what was in your <script> tags into its own JavaScript file to keep things a bit more separated. Nothing against the work you did at all, just organizational preferences on my part. :)

Since you put in the bulk of the work on this, I wanted to give you a chance to review my changes and provide any feedback before I merge. Thanks again for the great work! :100:

traveltissues commented 1 year ago

Thanks for taking a look at this. I've tested this with the following but the html is malformed because of the innerText of the <span>. It was working with my previous version but I can't immediately see the reason, I could spend a couple minutes soon and try to debug.

---
title: test
---
{{<plantuml id="1">}}
package "foo" {
    [A] <<a description for A>>
    [B] <<a description for B>>
}
[Inputs] <<something \n otherthing>>
Inputs --> A
Inputs --> B
A --> foo
B --> foo
{{</plantuml>}}

edit: it seems that the problem is the value being passed to the encoder is being mangled, and in this case it's to do with cases like the above.

    [A] <<a description for A>>

can be handled provided a space between the delim and the value is added

    [A] << a description for A >>
lukeorth commented 1 year ago

Thanks for taking a look at this. I've tested this with the following but the html is malformed because of the innerText of the <span>. It was working with my previous version but I can't immediately see the reason, I could spend a couple minutes soon and try to debug.

---
title: test
---
{{<plantuml id="1">}}
package "foo" {
  [A] <<a description for A>>
  [B] <<a description for B>>
}
[Inputs] <<something \n otherthing>>
Inputs --> A
Inputs --> B
A --> foo
B --> foo
{{</plantuml>}}

edit: it seems that the problem is the value being passed to the encoder is being mangled, and in this case it's to do with cases like the above.

  [A] <<a description for A>>

can be handled provided a space between the delim and the value is added

  [A] << a description for A >>

Agreed - I think it's an HTML encoding issue. I've managed to get it working by first encoding it with safeHTML and then piping it into htmlUnescape to decode. This way seems to work regardless of the spacing.

lukeorth commented 1 year ago

Okay, I've incorporated your suggestions and tweaked things just a bit (see my last comment). Let me know if it's working on your end or if you have any other suggestions. I appreciate you helping with all of this!

traveltissues commented 1 year ago

Agreed - I think it's an HTML encoding issue. I've managed to get it working by first encoding it with safeHTML and then piping it into htmlUnescape to decode. This way seems to work regardless of the spacing.

Yes I think it's due to <``> being the HTML element delims. TIL htmlUnescape is a thing, thanks I thought I would need to do that manually, it's a bit strange that it worked on the previous iteration and my guess is that's because I was essentially dropping the value of {{ .Inner }} in the element. Thanks for helping with this.