Sublime Forum

How do I pass minihtml to a plugin function?

#1

I am following along with this guide on developing a plugin with input handlers. The section on rendering a preview mentions that you can use text or minihtml. I’ve looked at the minihtml reference page, but it is still not clear to me how you pass the html to be processed in the preview function. For example, how would you change the following preview function to instead use minihtml? For the sake of brevity, let’s assume my minihtml is already a string in a variable called template. Thanks!

class MyTextInputHandler(sublime_plugin.TextInputHandler):
    def name(self):
        return "text"

    def placeholder(self):
        return "Text to insert"

    def preview(self, text):
        return "Characters: {}".format(len(text))
0 Likes

#2

https://www.sublimetext.com/docs/api_reference.html

It’s a shame that I can’t directly get a link to a specific method on the docs page.

So you should put your minihtml into a sublime.Html object.

return sublime.Html("Characters: {}".format(len(text)))

You didn’t actually use any minihtml feature in your example though.

1 Like

#3

Thank you. That works. The example I gave was from the guide I linked and for inputting just text. I was asking how to change that to accept minihtml. So with my minihtml wrapped in a variable called template, the following is working for me.

class MyTextInputHandler(sublime_plugin.TextInputHandler):
    def name(self):
        return "text"

    def placeholder(self):
        return "Text to insert"

    def preview(self, text):
        return sublime.Html(template)
0 Likes