Is restructured text preview on the roadmap?


#1

If not I would like to request that feature as an addon - similar to the markdown preview.

Thanks.


#2

Hi!

The dev team records feature requests and bug reports at https://github.com/Komodo/KomodoEdit/issues, they’d love to hear more there.


#3

The new preview mechanic is entirely modular, making it easy to add your own previewers. As an example check out the markdown previewer:

https://github.com/Komodo/KomodoIDE/blob/master/src/modules/preview/content/sdk/handlers/markdown.js

This gets registered with the previewer via:

require("preview").register("Name", "module/namespace");

You could create an addon using this mechanic by creating a project using the “Komodo Addon Boilerplate” template.


#4

You gave them the KomodoIDE repo link…


#5

Any other link to markdown preview code? KomodoIDE page is 404 - presumably private.

Thanks


#6

Bah, of course. It’s not in Edit. Here’s the code for you to reference:

/*
Copyright 2017 ActiveState Software Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
(function()
{

    const styleUtils = require("sdk/stylesheet/utils");
    const $ = require("ko/dom");
    const marked = require("contrib/marked");
    const w = require("ko/windows").getMain();
    const legacy = w.ko;
    const koFile = require("ko/file");
    const preview = require("preview/preview");
    const timers = require("sdk/timers");

    // We need a temp path so we can run our previewer on a `file://` path
    // otherwise we run into security issues (eg. relative images not loading)
    const tempPath = koFile.createTemp("temp.html");

    this.isEnabled = (view) =>
    {
        return view.language == "Markdown";
    };

    this.Previewer = function(view, browser)
    {
        var prepared = false;
        var firstLoad = true;

        if ( ! koFile.isFile(tempPath))
        {
            // recreate temp file if it got deleted
            koFile.create(tempPath);
        }

        this.getHtml = (callback) =>
        {
            if ( ! prepared)
            {
                browser.attr("src", "file://" + tempPath);
                browser.once("DOMContentLoaded", () =>
                {
                    prepared = true;
                    this.getHtml(callback);
                });

                var statusbar = $("<statusbar>").attr("align", "center");
                browser.before(statusbar);

                addressbar = $("<textbox>").attr({ value: "Markdown Preview", flex: 1, readonly: true });
                statusbar.append(addressbar);

                var closeButton = $("<button>").attr("class", "close-icon unstyled");
                closeButton.on("command", () => preview.close(view));
                statusbar.append(closeButton);
                
                return;
            }
            callback(marked(view.scimoz.text));

            styleUtils.loadSheet(browser.element().contentWindow, "less://preview/skin/markdown.less");

            var doc = browser.element().contentDocument;

            var baseURI = view.url ? view.url.replace(/\/[\w.-]+\.[\w-]+$/, '/') : "about:blank";
            var base = doc.createElement("base");
            base.setAttribute("href", baseURI);
            base.setAttribute("target", "_blank");
            doc.head.appendChild(base);

            if (firstLoad)
            {
                firstLoad = false;
                timers.setTimeout(() =>
                {
                    preview.reload(view);
                }, 0);
            }
        };
    };

}).apply(module.exports);

#7

thanks nathanr