-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possibility to overnight writer methods #14
Comments
For good example you can check blackfriday v2 renderer interface/HTML writer implementation that is easy to customize for specific needs |
I'd love to do that and actually tried to do it with the current interface (i was mistaken about how embedding works and thought it to be like inheritance), see here (note the comment below the diff). At a glance I don't see how blackfriday v2 makes this possible, could you elaborate? In any case I'll look into this next week and hope blackfriday presents an elegant solution that we can imitate. |
Check this PR in Gitea how we are overriding it for blackfriday: |
Thx! I missed WithRenderer while skimming the code yesterday. Looks simple and clean enough. Will add it end of next week :) |
The blackfriday approach requires extensive code changes (no nested Implemented in 14900e9. type ExtendedHTMLWriter struct { *HTMLWriter }
func (w *ExtendedHTMLWriter) WriteText(t Text) {}
func NexExtendedHTMLWriter() *ExtendedHTMLWriter {
htmlWriter := NewHTMLWriter()
extendedWriter := &ExtendedHTMLWriter{htmlWriter, 0}
htmlWriter.ExtendingWriter = extendedWriter
return extendedWriter
} |
feel free to re-open this if you have anything - I just like to keep my inbox empty so I'm closing this for now. |
Yes, it does work, thanks. It is still tricky with needing own |
Could you point me to the part where you run into this problem? I thought about getting rid of cloning but in the end thought it wasn't needed. In any case the code is still there and maybe this solves your problems? f0ebfce We could also expose NodesAsString on the writer interface if that helps - i didn't see a reason to until now but whatever you run into, feel free to suggest improvements |
I need them because I'm overriding WriteRegularLink function and it needs NodesAsString function to get rendered nodes for link, see: https://github.com/go-gitea/gitea/pull/8560/files#diff-ec1158a92d009b3ac2d4241bac8c8e63R92 |
Thx! Don't have time to look into this tonight but sounds like this would be solved by exporting |
It does not work correct with that commit, it renders text that should be between
|
I had to make clone function this way to get it working for me: func (r *ExtendedHTMLWriter) emptyClone() *ExtendedHTMLWriter {
wcopy := *(r.HTMLWriter)
wcopy.Builder = strings.Builder{}
rcopy := *r
rcopy.HTMLWriter = &wcopy
wcopy.ExtendingWriter = &rcopy
return &rcopy
}
func (r *ExtendedHTMLWriter) nodesAsString(nodes ...org.Node) string {
tmp := r.emptyClone()
org.WriteNodes(tmp, nodes...)
return tmp.String()
} |
Can you try again? #15 |
Thx for testing, merged in #15 (v0.1.8). Again - feel free to re-open / open another ticket if there's anything else :) |
Thanks |
Currently it is impossible to override HTML writer methods to fine-tune them. For Gitea project we need custom link/image URLs but only way to implement this is to copy all HTML writer and change single method. Mostly it is because of nodeAsString method that clones writer and also WriteNode usage that passes HTML writer all over the place
The text was updated successfully, but these errors were encountered: