简体   繁体   中英

How to remove HTML entities from JSON?

I'm creating a simple RSS feed app using AngularJS based on this JSON data .

I managed to get the post title and the post content .

But, I got problem when dealing with the content data. I want to strip out all the HTML entities inside it and make it looks something like Pocket app like this:

在此处输入图片说明

I just want:

  1. Plain text content (in same paragraph structure from the feed source)
  2. Center aligned image(s)
  3. Hyperlinks
  4. Unordered and ordered list items
  5. Videos (as result of embed tags - if any)

I read about ngSanitize but I couldn't really understand how to use it to achieve what I want.

How to do it?

if you want to completely remove html tags from Json content ... then check this .... data taken from your sample Json..

Input:

var json = {
    "content": "<p>One of the many new features in <a title=\"WordPress 3.5\" href=\"http://codex.wordpress.org/Version_3.5\">WordPress 3.5</a> is the Iris color picker. <a title=\"Replace Farbtastic color picker\" href=\"http://core.trac.wordpress.org/ticket/21206\"> Iris replaces the, now deprecated, Farbtastic</a> color picker script.  The new Iris color picker is shown off in the Theme Customizer for the Twenty-Twelve theme.</p>\n<p><img class=\"aligncenter size-full wp-image-1634\" src=\"http://rachelbaker.me/wp-content/uploads/2012/11/WordPress-theme-customizer-color-picker2.png\" alt=\"\" /></p>\n<p>As soon as I saw Iris, I fell in love. She is user-friendly, colorful and fun. I found that implementing the new color picker is <a title=\"Adding Farbtastic to WordPress Widgets\" href=\"http://pippinsplugins.com/adding-the-farbtastic-color-picker-to-your-wordpress-widgets/\">very similar to Farbtastic</a>.</p>\n<h3>Iris Color Picker Demo Plugin</h3>\n<p>To use the Iris color picker in a plugin requires:</p>\n<ol>\n<li>Running a version of WordPress that is 3.5 Beta or higher.</li>\n<li>Loading the &#8216;wp-color-picker&#8217; script and style into your plugin options page.</li>\n<li>Adding a text input for your color value to your plugin options page.</li>\n<li>Writing a custom jQuery script to call Iris&#8217;s wpColorPicker method on your color text input field(s).</li>\n</ol>\n<p><strong>How does the code look for implementing steps 2-4?</strong><br />\nI created a demonstration plugin to help answer that. The plugin doesn&#8217;t do anything itself, it is only intended as a guide for developers interested in using the new Iris color picker in a WordPress plugin.</p>\n<p><a class=\"button\" href=\"https://github.com/rachelbaker/iris-color-picker-demo\">View on Github</a></p>\n<p><img class=\"aligncenter size-full wp-image-1635\" src=\"http://rachelbaker.me/wp-content/uploads/2012/11/screenshot-iris-color-picker-demo.jpeg\" alt=\"Iris Color Picker Demo Plugin\" /></p>\n"
};
var someString = 
json.content.replace(/<\/?([a-z][a-z0-9]*)\b[^>]*>/gi, '').
replace(/&#[0-9]+;t/gi,"").replace(/\[/g,"").replace(/\]/g,""); 


console.log(someString);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM