weirongxu / plantuml-previewer.vim

Vim / Neovim plugin for preview PlantUML

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use with .rst files

ubmarco opened this issue · comments

Thanks a lot for this extension, it has proven very useful to me.

I use Plantuml in Sphinx with the sphinxcontrib.plantuml extension. In below RST file, plantuml-previewer.vim basically works, but will only render the first diagram.

Chapter1
--------

.. uml::

  @startuml
  class test1
  @enduml


Chapter2
--------

.. uml::

  @startuml
  class test2
  @enduml

I guess it looks for the first @startuml. I would appreciate a feature where plantuml-previewer.vim is aware of the cursor location and will look for surrounding @startuml and @enduml appearances. If none are found, it can default to the current implementation. The automatic update mechanism would have to somehow remember the Plantuml instance and update accordingly if it gets changed. This would also bind the browser page to a certain diagram.

Do you think that's feasible? Do you see a workaround in the current implementation?

Perhaps we can provide a lower-level API, then can let users use text to preview the plantuml.

Example:

let start = searchpairpos('@startuml', '', '@enduml', 'nb')
let end = searchpairpos('@startuml', '', '@enduml', 'n')
call plantuml_preview#refresh_by_content(getline(start, end), 'foo.puml')

Thanks for the fast response, this sounds like a great idea.
I commonly have RST files with many PUML diagrams. Can the refresh_by_content function find out if the relevant files have changed so rendering is not triggered if all lines are identical? That would reduce load/render times a lot.
One note on above code, the function searchpairpos returns a list [line-numer, column], so I guess getline(start[0], end[0]) is needed.

Can the refresh_by_content function find out if the relevant files have changed so rendering is not triggered if all lines are identical?

I agree with you

I guess getline(start[0], end[0]) is needed.

Indeed