Progress on ViewRendered2

77 views
Skip to first unread message

Thomas Passin

unread,
Dec 27, 2019, 6:35:04 PM12/27/19
to leo-editor
I have made a lot of progress on re-implementing Viewrendered2 in the QT5 era, and I wanted to share where I am with it.

To quickly summarize what VR2 added to viewrendered for @rst (Restructured Text) trees:
   - It can render an entire @rst tree, rather than a singe node.
   - It can export the rendering to an external browser.
   - It can display syntax-colorized code blocks that are marked with a "@language python" directive.  This can be easier than using the ''.. code:: python" RsT syntax.
   - It can display only the code blocks, without any non-code text.
   - It can execute the code in a node or the entire tree, and display any output below the code block.

Unfortunately, VR2 only worked with Qt4.  I've been working on getting it to use Qt5.  I'm calling my version viewrendered3.  I decided to start from viewrendered, since EKR has gotten it integrated into the new QT5/docks GUI framework, and I thought it would be too hard to modify VR2 to make all that work.  So here's what I've gotten working so far. This is all for a single node, since I'm not walking the tree yet.

   1. Renders code blocks marked with the @language python directive.
   2. Renders MathJax math in the rendering pane (this was non-obvious to get going).
   3. Has the toolbar and menu of the original VR2.  The only part of that which is hooked up so far is the "Export" button.
   4. Renders images with local file locations (this turned out to be kind of tricky).
 
For non-@rst nodes, it works the same as viewrendered, since it uses the same code.  In fact, wherever possible I'm delegating to the VR code, to minimize the chances of getting out of sync with it.  I'm using delegation rather than inheritance because it seemed I had fewer problems when I wanted to override certain code.

To get item 2, MathJax, working, I had to change from the default QTextBrowser to a QWebEngineView, because it has to execute MathJax script, and the QTextBrowser doesn't seem to, even though it does display an HTML string.  So I have to swap in the web browser widget (QWebEngineView) for @rst nodes.   In the code it's called a QtWebKitWidgets.QWebView, but by EKR's import magic, it's really a QWebEngineView.

To get item 4 working, I had to discover that the setHtml() method actually passes in the html as a data: url.  You can't have relative locations (like for an image) because a  data: url doesn't really have a location per se.  So I took the route of saving the HTML string to a temporary file, which I had to do anyway for sending the rendering to an external browser.  The QWebEngineView can load the local file without trouble.

So it's been painful, but progress is good.

Edward K. Ream

unread,
Dec 28, 2019, 11:14:29 AM12/28/19
to leo-editor
On Fri, Dec 27, 2019 at 6:35 PM Thomas Passin <tbp1...@gmail.com> wrote:
I have made a lot of progress on re-implementing Viewrendered2 in the QT5 era, and I wanted to share where I am with it.

Many thanks for this work!  Others have expressed interest.
 
So it's been painful, but progress is good.

Excellent.

Edward

Thomas Passin

unread,
Jan 3, 2020, 1:46:41 PM1/3/20
to leo-editor
On Friday, December 27, 2019 at 6:35:04 PM UTC-5, Thomas Passin wrote:
I have made a lot of progress on re-implementing Viewrendered2 in the QT5 era, and I wanted to share where I am with it.

Here's the new work as of today:

- I completely re-implemented the code that reads a node's rst and converts it  to HTML.  Now each section that's delineated by an @language directive is collected in its own chunk, so a Python code chunk can be displayed (or executed, when I get that going) with proper syntax colorizing.  A node can contain any number of @language changes, not just a single change to Python like the old VR2.  In principle, one could have different languages appropriately colorized in different code blocks, but for now I'm only doing it for Python.

   Using chunks seems to be a fairly standard approach in literate programing, and I have a Chunks class for accumulating text chunks that knows how to turn its text into the right rst form for the code language (only Python so far).

- for @md nodes, I have math rendering by MathJax, and code block colorizing, working. Code fencing is working.  To make this work, you need a css style sheet, and the plan here is for the plugin to check for its existence and to create a default stylesheet if needed.  Or you will be able to designate a custom stylesheet instead.

- The Reload toolbar button is now hooked up and working.

Edward K. Ream

unread,
Jan 7, 2020, 4:27:14 AM1/7/20
to leo-editor
On Fri, Jan 3, 2020 at 1:46 PM Thomas Passin <tbp1...@gmail.com> wrote:
On Friday, December 27, 2019 at 6:35:04 PM UTC-5, Thomas Passin wrote:
I have made a lot of progress on re-implementing Viewrendered2 in the QT5 era, and I wanted to share where I am with it.

Thanks for this report, and all the work you have done.

Edward

Thomas Passin

unread,
Jan 13, 2020, 10:59:36 AM1/13/20
to leo-editor
I'm happy to say that the new viewrendered3 plugin now has everything working that I wanted for the first phase.  An entire tree can be displayed (instead of just  a single node). The viewing pane can display only the code blocks if desired.  Code in a node or tree can be executed and the output inserted into the viewing pane.  These last three only work for RsT, and only Python code can be executed for now (although many languages can be colorized).

MathJax math rendering works for both RsT and MD nodes.  Relative URLs work, so that, for example, images can be displayed in the rendering pane using a URL relative to the file you are working on.

It should not be hard to get the tree walking, code-only viewing, and code execution working for Markdown, but I plan to leave them until after the current version gets some more testing.

I changed the user interface a bit from viewrendered2:

  1. The default rendering type (RsT, MD, Text) can be changed at any time by a menu item.  No more need to edit an @setting and reload.
  2. Code execution is done using a pushbutton instead of a menu item. Execution is a one-time event, so that the plugin does not try to execute code every time you type a few characters.  You have to press the button each time you want an execution.
Before I make the plugin available for testing, I need to do a few things:
  • Make sure everything works right on linux.
  • Update the docstring.
  • Write up some configuration information, like how to get MathJax working (you can download the MathJax package to your own computer, and point to it using a file:/// URL).
So a few more days, I hope.
Reply all
Reply to author
Forward
0 new messages