我正在使用 reactjs 来渲染帖子。在我的帖子中,我有一些标签<code></code>
。所以我想展示code
给大家容易看到。
我用 reactjs 渲染我的帖子。
<div className="post-body" dangerouslySetInnerHTML={{
__html: this.state.post.content.rendered
}} />
我从这里安装了代码美化。
https://www.npmjs.com/package/code-prettify
那么我该如何使用pretty-code
呢?
这是我的内容渲染 json:
"content": {
"rendered": "<p>In blogger\/blogspot you can you the conditional tags to make custom for posts, pages, archive page, label and search page, even a specific post.<\/p>\n<h2>I.List of conditional tags you can use in your Blogger theme.<\/h2>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li>For Index page (Homepage, label pages and archive pages)\n<div class=\"toolbar\"><code class=\"prettyprint\"><b:if cond='data:blog.pageType == \"index\"'><br \/>\n<\/b:if><\/code><\/div>\n<\/li>\n<li>\n<div class=\"toolbar\">For posts<\/div>\n<div class=\"toolbar\"><code class=\"prettyprint\"><b:if cond='data:blog.pageType == \"index\"'><br \/>\n<\/b:if><\/code><\/div>\n<\/li>\n<li>\n<div class=\"toolbar\">For pages<\/div>\n<div class=\"toolbar\"><code class=\"prettyprint\"><b:if cond='data:blog.pageType == \"static_page\"'><br \/>\n<\/b:if><\/code><\/div>\n<\/li>\n<li>\n<div class=\"toolbar\">For archive pages<\/div>\n<div class=\"toolbar\"><code class=\"prettyprint\"><b:if cond='data:blog.pageType == \"archive\"'><br \/>\n<\/b:if><\/code><\/div>\n<\/li>\n<li>\n<div class=\"toolbar\">For homepage<\/div>\n<div class=\"toolbar\"><code class=\"prettyprint\"><b:if cond='data:blog.url == data:blog.homepageUrl'><br \/>\n<\/b:if><\/code><\/div>\n<\/li>\n<li>\n<div class=\"toolbar\">For specific url<\/div>\n<div class=\"toolbar\"><code class=\"prettyprint\"><b:if cond='data:blog.url == \"PUT_URL_HERE\"'><br \/>\n<\/b:if><\/code><\/div>\n<\/li>\n<li>\n<div class=\"toolbar\">For search page<\/div>\n<div class=\"toolbar\"><code class=\"prettyprint\"><b:if cond='data:blog.searchLabel'><br \/>\n<\/b:if><\/code><\/div>\n<\/li>\n<li>\n<div class=\"toolbar\">For error page<\/div>\n<div class=\"toolbar\"><code class=\"prettyprint\"><b:if cond='data:blog.pageType == \"error_page\"'><br \/>\n<\/b:if><\/code><\/div>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<h2>II. How to use?<\/h2>\n<p>You can use like this:<br \/>\nExample: In home page, I want to make a different style with other pages\/posts. I will use css inside conditional tags.<br \/>\n<code class=\"prettyprint\"><br \/>\n<b:if cond='data:blog.url == data:blog.homepageUrl'><br \/>\n<style><br \/>\nbody {font-size:20px; background:#f1f1f1}<br \/>\n<\/style><br \/>\n<script><br \/>\n\/\/<![CDATA[<br \/>\n$('body').addClass('homepage')<br \/>\n\/\/]]><br \/>\n<\/script><br \/>\n<\/b:if><br \/>\n<\/code><\/p>\n<p>You also can use else if not homepage.<\/p>\n<p><code class=\"prettyprint\"><br \/>\n<b:if cond='data:blog.url == data:blog.homepageUrl'><br \/>\n<style><br \/>\nbody {font-size:20px; background:#f1f1f1}<br \/>\n<\/style><br \/>\n<script><br \/>\n\/\/<![CDATA[<br \/>\n$('body').addClass('homepage')<br \/>\n\/\/]]><br \/>\n<\/script><\/code><\/p>\n<p><b:else\/><br \/>\n<!– Code for other pages here –><br \/>\n<\/b:if><\/p>\n",
"protected": false
},