I want to be able to add arbitrary text as link hrefs using wysihtml5. For example: I want to generate this <a href="[~55~]">link</a>
I have worked out how to do this -- here's a simplified example of what I'm doing:
editor = new wysihtml5.Editor("text_area_content", {toolbar: "wysihtml5-toolbar"})
editor.composer.commands.exec("createLink", { href: "[~"+55+"~]" })
The problem I now have is that, after creating a link, when this link is selected in the editor, the dialog box shows the link as "http://current_url/[~55~]". I want it to show just "[~55~]".
I have tried to bind a new event to links within the editor, but I couldn't work out how to do that (since they are in an iframe).
How can I get the wysihtml5 link dialog to show the link address without displaying the current url?
In wysihtml5/src/toolbar/dialog.js
a method _interpolate
is called on the link which takes the link's attributes and displays them in the dialog. So whatever is in the href="..."
is displayed in the input element of the dialog.
Example from the inline documentation:
https://github.com/xing/wysihtml5/blob/master/src/toolbar/dialog.js
<!-- original link -->
<a href="http://www.google.com" target="_blank">foo</a>
<!-- dialog: -->
<input type="text" data-wysihtml5-dialog-field="href" value="">
<input type="text" data-wysihtml5-dialog-field="target" value="">
<!-- after calling _interpolate() the dialog will look like this -->
<input type="text" data-wysihtml5-dialog-field="href" value="http://www.google.com">
<input type="text" data-wysihtml5-dialog-field="target" value="_blank">
So if you can extend the method _interpolate in your application you could check when the attribute name is href
and then just display the relative part (without the server name).