Published
Edited
Mar 9, 2020
Fork of SVG Viewer
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
imported_svg = {
const replacedText = await local_file.text()
.then(svgText => svgText
// Replace eb_*_001_42_ with eb_*_001
.replace(/"(eb_(text|color)_[0-9]{3})[^"]+"/g, '"$1"')
// Remove any path id for eb_color_NNN
.replace(/(<g id="eb_color_[0-9]{3}"[^>]*>\s*<path[^>]*) id="[^"]*"([^>]*>(?:.*?)<\/\s*path>\s*<\/g>)/g, '$1$2')
// Remove any text id for eb_text_NNN
.replace(/(<g id="eb_text_[0-9]{3}"[^>]*>\s*<text[^>]*) id="[^"]*"([^>]*>(?:.*?)<\/\s*text>\s*<\/g>)/g, '$1$2')
// Replace group (path)
.replace(/<g id="(eb_color_[0-9]{3})"[^>]*>\s*<path([^>]*[^>]*(?:>(?:.*?)<\/\s*path>|\/>))\s*<\/g>/g, '<path id="$1"$2')
// Replace group (text)
.replace(/<g id="(eb_text_[0-9]{3})"[^>]*>\s*<text([^>]*>(?:.*?)<\/\s*text>)\s*<\/g>/g, '<text id="$1"$2'));
const ids = replacedText.match(/eb_(?:text|color)_[0-9]{3}/g);
const duplicated_ids = _(ids).groupBy().pickBy(x => x.length > 1).keys().value();
const replacedTextBlob = new Blob([replacedText], {type: 'image/svg+xml'});
return {
blob_url: URL.createObjectURL(replacedTextBlob),
duplicated_ids: duplicated_ids
}
}
Insert cell
Insert cell
Insert cell
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