plantuml-previewer.vim icon indicating copy to clipboard operation
plantuml-previewer.vim copied to clipboard

Use with .rst files

Open ubmarco opened this issue 5 years ago • 3 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?

ubmarco avatar May 12 '20 13:05 ubmarco

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')

weirongxu avatar May 12 '20 19:05 weirongxu

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.

ubmarco avatar May 12 '20 19:05 ubmarco

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

weirongxu avatar May 12 '20 20:05 weirongxu