我需要匹配所有这些开始标记:
<p>
<a href="foo">
Run Code Online (Sandbox Code Playgroud)
但不是这些:
<br />
<hr class="foo" />
Run Code Online (Sandbox Code Playgroud)
我想出了这个,并希望确保我做对了.我只抓住了a-z.
<([a-z]+) *[^/]*?>
Run Code Online (Sandbox Code Playgroud)
我相信它说:
/,然后我有这个权利吗?更重要的是,你怎么看?
有什么办法可以将HTML转换为正确的纯文本吗?我尝试了从raw到sanitize的所有东西,甚至还有使用text_part方法的Mail gem,它本应该做到这一点,但对我来说不起作用.
到目前为止,我最好的射门是,strip_tags(strip_links(resource.body))但等等没有正确转换.<p><ul>
这或多或少是我在HTML中的含义:
Hello
This is some text. Blah blah blah.
Address:
John Doe
10 ABC Street
Whatever City
New Features
- Feature A
- Feature B
- Feature C
Check this out: http://www.google.com
Best,
Admin
Run Code Online (Sandbox Code Playgroud)
转换成类似的东西
Hello
This is some text. Blah blah blah.
Address: John Doe 10 ABC Street Whatever City
New Features Feature A Feature B Feature C
Check this out: http://www.google.com
Best, Admin
Run Code Online (Sandbox Code Playgroud)
任何的想法?