Make it easier to extend ToHtmlSerializer #26

Closed
pillingworthz opened this Issue Jul 6, 2011 · 2 comments

Comments

Projects
None yet
2 participants
@pillingworthz

Similar to #21 - toHtmlSerialzer is difficult to subclass and tweak behaviour.

I would like to modify the link URLs before they are written (in my case I want to resolve relative image URLs)

I can do this by overriding toHtmlSerializer but I have to override all of the link methods, some are complicated and I end up having to repeat the base class code (public void visit(final RefLinkNode node) in particular).

Maybe some of the code in this class could be broken down with more overridable template method hooks so subclasses can change the functionality more easily?

public void visit(ExpLinkNode node) {
    if (node.getImage()) {
        printer.print("<img src=\"").printEncoded(modifyUrl(node.getUrl()), this).print("\"  alt=\"").startEncoding(this);
        ...

String modifyUrl(String url) {
    // override to modify the url
    return url;
}

Also some variables like printer as private which make overriding and tweaking the behaviour difficult.

@sirthias

This comment has been minimized.

Show comment Hide comment
@sirthias

sirthias Jul 6, 2011

Owner

Yes, good point!
Will take care of this with the next release...
Thanks for taking the time to report this!
Cheers,
Mathias

Owner

sirthias commented Jul 6, 2011

Yes, good point!
Will take care of this with the next release...
Thanks for taking the time to report this!
Cheers,
Mathias

@pillingworthz

This comment has been minimized.

Show comment Hide comment
@pillingworthz

pillingworthz Jul 6, 2011

Excellent - will look forward to it.

Excellent - will look forward to it.

@sirthias sirthias closed this in 869b108 Oct 4, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment