diff options
author | Noah Campbell <noahcampbell@gmail.com> | 2013-09-17 14:16:06 -0700 |
---|---|---|
committer | Noah Campbell <noahcampbell@gmail.com> | 2013-09-17 14:16:06 -0700 |
commit | 6b0752e8c0334dfb2275a2edb975ec13a2724134 (patch) | |
tree | d489894fbf0585c4dfb8ccb8c70a7e78d11d633e /transform | |
parent | c6fe87b14e06a46bbf3b94cfdf67e9127d51e2fe (diff) |
Move AbUrlify to post content transformation
Currently the a@href and script@src elements will have BaseUrl applied
to their elements prior to being written to disk.
Diffstat (limited to 'transform')
-rw-r--r-- | transform/post.go | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/transform/post.go b/transform/post.go index f54688cb2..f63f1683b 100644 --- a/transform/post.go +++ b/transform/post.go @@ -17,14 +17,18 @@ func (t *Transformer) Apply(r io.Reader, w io.Writer) (err error) { return } - if err = t.absUrlify(tr); err != nil { + if err = t.absUrlify(tr, elattr{"a", "href"}, elattr{"script", "src"}); err != nil { return } return tr.Render(w) } -func (t *Transformer) absUrlify(tr *htmltran.Transformer) (err error) { +type elattr struct { + tag, attr string +} + +func (t *Transformer) absUrlify(tr *htmltran.Transformer, selectors ...elattr) (err error) { var baseURL, inURL *url.URL if baseURL, err = url.Parse(t.BaseURL); err != nil { @@ -38,9 +42,11 @@ func (t *Transformer) absUrlify(tr *htmltran.Transformer) (err error) { return baseURL.ResolveReference(inURL).String() } - if err = tr.Apply(htmltran.TransformAttrib("src", replace), "script"); err != nil { - return + for _, el := range selectors { + if err = tr.Apply(htmltran.TransformAttrib(el.attr, replace), el.tag); err != nil { + return + } } - return tr.Apply(htmltran.TransformAttrib("href", replace), "a") + return } |