Insert custom HTML using a new button in the Medium Editor toolbar
Check out the demo page hosted on GitHub pages.
Creates a new instance of CustomHtml extension.
- Object options An object containing the extension configuration. The following fields should be provided:
- buttonText: the text of the button (default:
</>
) - htmlToInsert: the HTML code that should be inserted
The click event handler that calls insertHtmlAtCaret
method.
This function is called by the Medium Editor and returns the button that is added in the toolbar
- HTMLButtonElement The button that is attached in the Medium Editor toolbar
Load in the page the following scripts in this order:
- Medium Editor JS
- Custom HTML Medium Editor Extension
- Your custom script (that creates the editor and contains the custom handlers)
window.onload = function () {
var myEditor = new MediumEditor(".container", {
buttons: [
"bold"
, "italic"
, "underline"
, "anchor"
, "header1"
, "header2"
, "quote"
, "customHtml"
]
, extensions: {
"customHtml": new CustomHtml({
buttonText: "<hr>"
, htmlToInsert: "<hr class='someclass'>"
})
}
});
};
Run the following commands to download and install the extension:
$ git clone [email protected]:jillix/medium-editor-custom-html.git medium-editor-custom-html
$ cd medium-editor-custom-html
$ npm install
- File an issue in the repository, using the bug tracker, describing the contribution you'd like to make. This will help us to get you started on the right foot.
- Fork the project in your account and create a new branch:
your-great-feature
. - Commit your changes in that branch.
- Open a pull request, and reference the initial issue in the pull request message.
See the LICENSE file.