Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ryanburnette/htmlassetref
https://github.com/ryanburnette/htmlassetref
Last synced: 22 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/ryanburnette/htmlassetref
- Owner: ryanburnette
- License: mpl-2.0
- Created: 2023-05-31T13:09:23.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-05-31T22:20:41.000Z (over 1 year ago)
- Last Synced: 2024-11-19T19:52:21.025Z (3 months ago)
- Language: Go
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# htmlassetref
`htmlassetref` is a Go package that enables the modification of URL references within HTML content. It offers a straightforward and convenient approach to identify HTML tags with attributes like src, href, or srcset that reference URLs, allowing for easy customization based on a callback function. With `htmlassetref`, developers can efficiently update and manipulate URL references in HTML, facilitating tasks such as rewriting asset URLs, handling path adjustments, or implementing custom transformations.
## Usage
```go
package mainimport (
"fmt"
"github.com/ryanburnette/htmlassetref"
)func main() {
// Sample HTML content
html := `
`
// Call UpdateAssetRefs with a callback function to update the references
updatedHTML := htmlassetref.UpdateAssetRefs(html, func(ref string) string {
// Modify the reference as needed (e.g., add a version suffix)
return ref + "?v=1.0"
})// Print the updated HTML
fmt.Println(updatedHTML)
}```
## Test
The reliability of this package is maintained through the test. The
`_content.html` markup in this project should contain all possible examples of
HTML tags that reference a downloadable asset. The tests ensure that all
applicable tags are being found and their correct references returned and then
modified by the callback.```shell
go test
```