livebook/assets/js/lib/attribute.js
Jonatan Kłosko 936d0af5fb
Set up markdown rendering (#16)
* Set up markdown rendering, update theme.

* Improve focus and handle expanding for markdown cells

* Add keybindings for expanding/navigating cells

* Improve editor autofocus when navigating with shortcuts

* Add tests

* Render markdown on the client

* Don't render cell initial data and make a request instead
2021-01-30 00:33:04 +01:00

35 lines
744 B
JavaScript

export function getAttributeOrThrow(element, attr, transform = null) {
if (!element.hasAttribute(attr)) {
throw new Error(
`Missing attribute '${attr}' on element <${element.tagName}:${element.id}>`
);
}
const value = element.getAttribute(attr);
return transform ? transform(value) : value;
}
export function parseBoolean(value) {
if (value === "true") {
return true;
}
if (value === "false") {
return false;
}
throw new Error(
`Invalid boolean attribute ${value}, should be either "true" or "false"`
);
}
export function parseInteger(value) {
const number = parseInt(value, 10);
if (Number.isNaN(number)) {
throw new Error(`Invalid integer value ${value}`);
}
return number;
}