开发者

How do I expand all class="..." attributes to style="..."?

I'm parsing forum threads with Nokogiri and putting them into a RSS feed. The forum itself doesn't have RSS or any other kind of news feeds.

The problem I've encountered is that elements are styled with CSS classes and via selectors in forums style file included in the page. I can't include it into a news feed, so I want to replace all class="..." attributes with style="<style properties from classes here>".

Any ideas how do I do that? Maybe there 开发者_运维问答are some gems able to parse CSS and update Nokogiri parser?


You need to show a sample of what you are parsing, plus a sample of the code you've written.

In addition, RSS doesn't support styles so rather than replace class="..." with style="" just remove the class info. You can embed HTML in RSS items, but IMO that results in lousy looking feeds and can lead to problems farther down the road if someone else wants to reuse the data. Instead I'd recommend sanitizing the HTML or even stripping all tags.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜