Skip to content

Commit

Permalink
z_html: also call sanitizer callback for comment blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
mworrell committed Oct 16, 2012
1 parent 993c642 commit 23f6321
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/z_html.erl
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,17 @@ sanitize1(Html, ExtraElts, ExtraAttrs, Options) ->

sanitize(B, _Stack, _ExtraElts, _ExtraAttrs, _Options) when is_binary(B) ->
escape(B);
sanitize({comment, Text}, _Stack, _ExtraElts, _ExtraAttrs, _Options) ->
{comment, Text};
sanitize({comment, _Text} = Comment, _Stack, _ExtraElts, _ExtraAttrs, Options) ->
case Options of
T when is_tuple(T), element(1, T) =:= context ->
z_notifier:foldl(sanitize_element, Comment, Options);
_ ->
case proplists:get_value(element, Options) of
undefined -> Comment;
F when is_function(F) -> F(Comment);
{M,F,A} -> erlang:apply(M, F, [Comment|A])
end
end;
sanitize({pi, _Raw}, _Stack, _ExtraElts, _ExtraAttrs, _Options) ->
<<>>;
sanitize({pi, _Tag, _Attrs}, _Stack, _ExtraElts, _ExtraAttrs, _Options) ->
Expand Down

9 comments on commit 23f6321

@mmzeeman
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we also going to move the z_notifier to stdlib?

@arjan
Copy link
Member

@arjan arjan commented on 23f6321 Oct 17, 2012 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kaos
Copy link
Member

@kaos kaos commented on 23f6321 Oct 17, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nice to avoid zotonic specifics altogether, if possible.

@mmzeeman
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also change zotonic code that instead explicitly passing the context we pass a function which has the context in a closure:

sanitize(DomTree, fun(Elt) -> z_notifier:foldl(sanitize_element, Elt, Context) end)

@arjan
Copy link
Member

@arjan arjan commented on 23f6321 Oct 17, 2012 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mworrell
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My idea was to clean this up later, changing the Zotonic code accordingly.

I think we will need some stubs or macros in Zotonic to handle this, always passing extra funs is error prone.

@mworrell
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW I already added support for {M,F,A} and fun() callbacks.

@kaos
Copy link
Member

@kaos kaos commented on 23f6321 Oct 17, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice :)

@mmzeeman
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it. :-)

Please sign in to comment.