diff --git a/src/index.js b/src/index.js
index 1212d23..eeb36ee 100644
--- a/src/index.js
+++ b/src/index.js
@@ -8,18 +8,22 @@ function materialize_references_to_ipfs_content(node, element) {
// load that content and set it into the attribute as a blob.
//
// Return a promise for doing all of that.
- // TODO: Support
rewriting.
- for (let attribute_name of ['content', 'href', 'src']) {
+ for (let attribute_name of ['content', 'href', 'src', 'style']) {
let attribute_value = element.getAttribute(attribute_name)
- if (attribute_value && attribute_value.startsWith('./')) {
+
+ if (attribute_value && attribute_value.includes('./')) {
let base_hash = window.location.pathname.match(/(^\/ipfs\/\w+)/)[1]
- let uri = base_hash + attribute_value.slice(1)
let anchor = document.createElement('a')
- anchor.href = uri
+ let relative_url = attribute_value.match(/(.\/[^)]+)/)[1]
+ anchor.href = base_hash + relative_url.slice(1)
console.log('loading IPFS sub-content for ' + anchor.pathname)
return node.files.cat(anchor.pathname).then(function (contents_buffer) {
- element.setAttribute(attribute_name, URL.createObjectURL(new Blob([contents_buffer])))
+ let materialized_value = attribute_value.replace(
+ relative_url,
+ URL.createObjectURL(new Blob([contents_buffer]))
+ )
+ element.setAttribute(attribute_name, materialized_value)
})
}
}
@@ -54,7 +58,7 @@ function App() {
// TODO: Should only do this if it's actually an HTML document. Need to gracefully skip this for other content types.
let contents_document = new DOMParser().parseFromString(contents_buffer.toString(), 'text/html')
- let elements = contents_document.querySelectorAll('link,meta,script')
+ let elements = contents_document.querySelectorAll('link,meta,script,div')
let promises = []
for (let element of elements) {