torchlight-laravel icon indicating copy to clipboard operation
torchlight-laravel copied to clipboard

Allow Blade component to read content from anywhere (URLs, base64...)

Open felixdorn opened this issue 1 year ago • 0 comments

Hi,

Currently,

<x-torchlight-code contents="https://gist.githubusercontent.com/..." />

does not work because of the is_file condition which reduces what we can accept to the file:// wrapper instead of all the stream wrappers.

The above is only one example, here's another, when using Stripe's markdoc.dev, which is not ported to PHP (yet), one can simply convert the fence node (codeblock) to the blade equivalent without messing with the torchlight-cli:

const fence = {
  render 'pre',
  // ...
  transform(node, config) {
      const attributes = node.transformAttributes(config);

      return new Tag('pre', {}, [
          new Tag('x-torchlight-code', {
              language: node.attributes.language,
              "contents": "data://text/plain;base64," + btoa(node.attributes.content)
          }, [])
      ])
    }
}

The <x-torchlight-code contents="data://text/plain;base64,..."> produced then works without any changes, assuming the middleware is registered.

felixdorn avatar Mar 09 '24 22:03 felixdorn