Public
Edited
Apr 27, 2023
Insert cell
Insert cell
Diff = require("diff")
Insert cell
myspan = {
const one = "robin linacre";
const other = "roin liinacre";
const color = "";

let diffy = Diff.diffChars(one, other);

function get_span(p) {
const bgc = p.added ? "#eaf2c2" : p.removed ? "#fadad7" : "white";
const textc = p.added ? "#406619" : p.removed ? "#b30000" : "black";

return `<span style="background: ${bgc}; color: ${textc} ">${p.value}</span>`;
}

return html`${diffy.map((part) => get_span(part))}`;
}
Insert cell
a = html`hello`
Insert cell
html`${a}`
Insert cell
{
let a = ["a", "b", "c"];
return `${a.map((part) => part)}`;
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more