mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-01-04 06:01:59 +08:00
2ff327e742
* Implement cells bin * Temporarily keep cells source * Send complete bin entries from session to clients when a cell gets removed * Polish styles * Hydrate bin entries on section deletion as well
39 lines
777 B
JavaScript
39 lines
777 B
JavaScript
import { getAttributeOrThrow } from "../lib/attribute";
|
|
import { highlight } from "../cell/live_editor/monaco";
|
|
|
|
/**
|
|
* A hook used to highlight source code in the root element.
|
|
*
|
|
* Configuration:
|
|
*
|
|
* * `data-language` - language of the source code
|
|
*/
|
|
const Highlight = {
|
|
mounted() {
|
|
this.props = getProps(this);
|
|
|
|
highlightIn(this.el, this.props.language);
|
|
},
|
|
|
|
updated() {
|
|
this.props = getProps(this);
|
|
|
|
highlightIn(this.el, this.props.language);
|
|
},
|
|
};
|
|
|
|
function getProps(hook) {
|
|
return {
|
|
language: getAttributeOrThrow(hook.el, "data-language"),
|
|
};
|
|
}
|
|
|
|
function highlightIn(element, language) {
|
|
const code = element.innerText;
|
|
|
|
highlight(code, language).then((html) => {
|
|
element.innerHTML = html;
|
|
});
|
|
}
|
|
|
|
export default Highlight;
|