source说:
/*
* While HTML supports far more named entities, the lowest common denominator
* has become HTML5's XML Serialisation which is restricted to the those named
* entities that XML supports. Using HTML entities would result in this error:
* XML Parsing Error: undefined entity
*/
实际上,html策略只会更改HTML中具有特殊含义的字符,而html_attr策略会替换几乎所有非字母数字字符,包括空格.看例子:
看到这个文字好吗?
raw: See this text, OK?
html: See this <b>text</b>, OK?
html_attr: See this <b>text</b>, OK?
在我的理解中,对于HTML,你可以使用html策略,对于XML文档,你最好使用html_attr策略,但我没有在实践中尝试过这个.