Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Refactor sanitize_token for better subclassing#26

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
mfa wants to merge3 commits intohtml5lib:masterfrommfa:master

Conversation

mfa
Copy link
Contributor

@mfamfa commentedApr 24, 2013

For my application I need to clean all unallowed tokens.
At the moment the only way is to copy the whole sanitize_token method, remove a few lines and add one.
Splitting up the sanitize_token method would simplify this a lot and reduces code duplication (in my code).

Example usage:

importhtml5libfromhtml5libimporttreebuilders,treewalkers,serializer,sanitizerclassMySanitizer(sanitizer.HTMLSanitizer):# reduce tokens to only a fewacceptable_elements= ['b','br','center','em','h3','h4','h5','h6','i','li','ol','p','span','strike','strong','tt','ul']allowed_elements=acceptable_elementsdefunallowed_token(self,token):# remove all unallowed tokensreturn""defsanitize(input):p=html5lib.HTMLParser(tokenizer=MySanitizer,tree=treebuilders.getTreeBuilder("dom"))dom_tree=p.parseFragment(input)walker=treewalkers.getTreeWalker("dom")stream=walker(dom_tree)s=serializer.htmlserializer.HTMLSerializer(omit_optional_tags=False,quote_attr_values=True)returnu"".join(s.serialize(stream))

@gsnedders
Copy link
Member

Well, Travis CI shows you having made all the sanitizer tests fail. That ought to be fixed. Otherwise, you should use the standard English "disallow" and not "unallow". That said, in principle looks good.

@gsnedders
Copy link
Member

Merged in52f9ca6

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@mfa@gsnedders

[8]ページ先頭

©2009-2025 Movatter.jp