mimic
mimic

Reputation: 5224

Medium-editor: how to apply multiple tags wrappers?

I'm trying to use the great "medium editor clone" https://github.com/yabwe/medium-editor and I'm stuck with the problem:

How to wrap a selected piece of text (that is actually code) with 2 tags: <pre> and <code>

(I want it to use highlight.js code formatter).

So, the result after applying should be:

<pre><code>some my code</code></pre>

I have no idea how to implement it.

Upvotes: 0

Views: 270

Answers (1)

mimic
mimic

Reputation: 5224

For those who may be interested in this problem, I found the solution.

I had to use extend button with the following code:

var SampleButton = MediumEditor.extensions.button.extend({
            ...
            handleClick: function (event) {
                var selection = rangy.getSelection().toHtml();
                sel = '<pre><code>' + selection + '</code></pre>';
                this.base.pasteHTML(selection);
            }
        });

That is I just extract the text and wrap it with tags.

Let me know if you found more elegant and natural way to gain it.

Upvotes: 1

Related Questions