Skip to content

denis-migdal/hljs_editable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hljs_editable

Make highlight.js codes editables

Usage :

const code = document.querySelector(...);
new HLJSEditable(code);

Other features : -> history -> support for enter/tabulation keys.

Get lang :

// instance
hljs.lang

// standalone
HLJSEditable.lang(elem);

Manage cursor :

// instance
hljs.getCursorPos();
hljs.setCursorPos(cursor); // an integer giving the caret position.

// standalone
HLJSEditable.getCursorPos(elem);
HLJSEditable.setCursorPos(elem, cursor);

Change language

// instance
hljs.changeLang(lang);

// standalone :
HLJSEditatable.changeLang(html, code); // remove unnecessary line break and indentation.

Trim (not yet implemented)

// option :
new HLJSEditable(code, {trim: true});

// standalone :
HLJSEditatable.trim(code); // remove unnecessary line break and indentation.

! requires :

<style>
code[contenteditable]::after {
    content: "\200b"
}
</style>

TODO: history (ctrl+Z/etc) TODO: change event... (when focus out) TODO: script for HTML code ?

About

Make highlight.js codes editables

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published