posit-dev / py-htmltools

Tools for HTML generation and output
MIT License
19 stars 4 forks source link

`HTMLDependency` does not work with external script sources #45

Open schloerke opened 2 years ago

schloerke commented 2 years ago

https://github.com/rstudio/py-htmltools/blob/ae298449b10de5a193031d7c72d7216f7611cf5a/htmltools/_core.py#L1094-L1098

I'd expect to be able to write:

HTMLDependency(
    "mediapipe-hand",
    "0.0.1",
    source={"href":"https://cdn.jsdelivr.net/npm/@mediapipe/camera_utils"},
    script=[{"src":"camera_utils.js"}]
).as_html_tags()
#> <script src="https://cdn.jsdelivr.net/npm/@mediapipe/camera_utils/camera_utils.js"></script>

Currently, it produces:

<script src="/camera_utils.js"></script>

Can I have a HTMLDependency that points to external scripts?

cpsievert commented 2 years ago

Yea, that seems like an oversight

wch commented 2 years ago

IIRC, we had considered this but hadn’t defined the type for when the source is a remote url. There may be some prior discussion about this.

wch commented 2 years ago

Just to follow up: I think the idea was to create a new type similar to HTMLDependencySource, but with fields that are appropriate for remote sources

https://github.com/rstudio/py-htmltools/blob/ae298449b10de5a193031d7c72d7216f7611cf5a/htmltools/_core.py#L889-L891