I'm using blogger.com to host some texts on programming, and I'd like to use prettify (same as *) to nicely colour the code samples.
我正在使用blogger.com来主持一些关于编程的文本,我想使用美化(与*相同)来很好地为代码示例着色。
How do I install the prettify scripts into the blog domain?
Would it be better (if indeed its possible) to link to a shared copy somewhere?
I have webspace on a different domain. Would that help?
如何将美化脚本安装到博客域中?在某处链接到共享副本会更好(如果确实可能)吗?我在不同的域上有网站空间。那会有帮助吗?
Many thanks.
非常感谢。
10 个解决方案
#1
60
When you make a new entry in blogger, you get the option to use HTML in your entry and to edit your blog entries.
当您在博客中创建新条目时,您可以选择在条目中使用HTML并编辑博客条目。
so type http://blogger.com , then login, then Posting>Edit Posts>Edit then in there put this at the top:
所以键入http://blogger.com,然后登录,然后发布>编辑帖子>编辑然后将其放在顶部:
<script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/lang-css.min.js"></script>
<script type="text/javascript">
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
addLoadEvent(function() {
prettyPrint();
});
</script>
<style type="text/css">
/* Pretty printing styles. Used with prettify.js. */
.str { color: #080; }
.kwd { color: #008; }
.com { color: #800; }
.typ { color: #606; }
.lit { color: #066; }
.pun { color: #660; }
.pln { color: #000; }
.tag { color: #008; }
.atn { color: #606; }
.atv { color: #080; }
.dec { color: #606; }
pre.prettyprint { padding: 2px; border: 1px solid #888; }
@media print {
.str { color: #060; }
.kwd { color: #006; font-weight: bold; }
.com { color: #600; font-style: italic; }
.typ { color: #404; font-weight: bold; }
.lit { color: #044; }
.pun { color: #440; }
.pln { color: #000; }
.tag { color: #006; font-weight: bold; }
.atn { color: #404; }
.atv { color: #060; }
}
</style>
Note that you shouldn't use prettyPrint
directly as an event handler, it confuses it (see the readme for details). Which is why we're passing addLoadEvent
a function that then turns around and calls prettyPrint
.
请注意,您不应该直接使用prettyPrint作为事件处理程序,它会使它混淆(有关详细信息,请参阅自述文件)。这就是为什么我们传递addLoadEvent一个函数,然后转向并调用prettyPrint。
In this case because blogger does not allow us to link to the stylesheet, we just embed the prettify.css contents.
在这种情况下,因为博客不允许我们链接到样式表,我们只是嵌入了prettify.css内容。
then add a <code></code>
tag or a <pre></pre>
tag with the class name of "prettyprint"
, you can even specify the language like this "prettyprint lang-html"
然后添加一个
标签或一个类名为“prettyprint”的
标签,你甚至可以指定这样的语言“prettyprint lang-html”
so it can look like this
所以它看起来像这样
<pre class="prettyprint lang-html">
<!-- your code here-->
</pre>
or like this
或者像这样
<code class="prettyprint lang-html">
<!-- your code here-->
</code>
the code that you put in needs to have its HTML cleaned from < and > to do this just paste your code in here: http://www.simplebits.com/cgi-bin/simplecode.pl
您放入的代码需要从 <和> 清除其HTML才能执行此操作,只需将代码粘贴到此处:http://www.simplebits.com/cgi-bin/simplecode.pl
you can put the top code in your HTML layout so that its included for all pages by default if you like.
您可以将顶部代码放在HTML布局中,以便默认情况下将其包含在所有页面中(如果您愿意)。
update Now you can link CSS files in blogger, so adding this to the <head>
should be enough
更新现在您可以在博客中链接CSS文件,因此将此添加到就足够了
<link href="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.min.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/lang-css.min.js"></script>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded',function() {
prettyPrint();
});
</script>
I chose not to replace the body onload event on purpose, instead I'm using the new DOMContentLoaded event that the old browsers don't support, if you need old browser support, you can use any other load event to initiate prettyPrint, for example jQuery:
我选择不故意替换body onload事件,而是使用旧浏览器不支持的新DOMContentLoaded事件,如果你需要旧的浏览器支持,你可以使用任何其他load事件来启动prettyPrint,例如jQuery的:
jQuery(function($){
prettyPrint();
});
or the supposedly smallest domready ever
或者所谓的最小的domready
and your done :)
和你完成:)
Edit:
编辑:
as Lim H pointed out in the comments, in case where you use the blogger dynamic views (ajax templates) then you need to use the method described here to bind custom javascript: prettyPrint() doesn't get called on page load
正如Lim H在评论中指出的,如果您使用博客动态视图(ajax模板),那么您需要使用此处描述的方法来绑定自定义javascript:在页面加载时不会调用prettyPrint()
Update 2017-06-04
Use the guide here https://github.com/google/code-prettify
请使用https://github.com/google/code-prettify上的指南
Basically just use this :)
基本上只是用这个:)
<script src="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/run_prettify.min.js"></script>
<pre class="prettyprint"><code class="language-css">...</code></pre>
#2
41
The following worked for me immediately.
以下为我立即工作。
- Go to Blogger > Layout > Edit HTML
- 转到Blogger>布局>编辑HTML
- Copy the following snippet and paste it immediately after
<head>
in the "Edit template" field: - 复制以下代码段并立即将其粘贴到“编辑模板”字段中的之后:
snippet:
片段:
<link href='http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.css' rel='stylesheet' type='text/css'/>
<script src='http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js' type='text/javascript'></script>
- After
</head>
replace<body>
with<body onload='prettyPrint()'>
- 在 之后用替换
- Click "SAVE TEMPLATE"
- 点击“保存模板”
- Go to Blogger > Posting > New Post
- 转到Blogger>发布>新帖子
- Make sure you're editing the HTML by clicking on "Edit HTML." In the empty field try:
- 确保通过单击“编辑HTML”来编辑HTML。在空场中尝试:
<pre class="prettyprint">int foo=0; NSLog(@"%i", foo); </pre>
int foo = 0; NSLog(@“%i”,foo);
- Notice if you click "Preview" now you'll see this code in black only. Don't worry (yet).
- 请注意,如果您现在单击“预览”,您将看到此代码仅为黑色。别担心(还)。
- Click "PUBLISH POST" and then "VIEW BLOG". Your code should be prettified.
- 单击“发布POST”,然后单击“查看博客”。你的代码应该被美化。
#3
15
Nowadays, Google-Code-Prettify has an Auto-Loader script. You can load the JavaScript and CSS for prettify via one URL.
如今,Google-Code-Prettify有一个Auto-Loader脚本。您可以通过一个URL加载JavaScript和CSS以进行美化。
Add the script to the <head>
section of your Blogger template and it will work on all your posts:
将脚本添加到Blogger模板的部分,它将适用于您的所有帖子:
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
More detail here: http://code.google.com/p/google-code-prettify/wiki/GettingStarted
有关详细信息,请访问:http://code.google.com/p/google-code-prettify/wiki/GettingStarted
#4
6
It's very simple to add google code prettifier in your blogger.
在博客中添加谷歌代码美化非常简单。
just include the below javascript library in your blogger just before tag.
只需在标记之前在博客中包含以下javascript库。
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
just like in the below picture...
就像下面的图片一样......
Now you successfully added google code prettifier in your blogger.
现在,您已在博客中成功添加了Google代码美化。
Now if you want to insert code in your blogger post then add code (html, css, php and etc.), then insert that code between .... tags.
现在,如果你想在你的博客帖子中插入代码,然后添加代码(html,css,php等),然后在....标签之间插入该代码。
<pre class="prettyprint">...</pre>
or
要么
<code class="prettyprint">...</code>
Demo of the google Prettify on Blogger
博客上的Google Prettify演示
Also please refer this documentation for adding this Google prettifier to blogger in the following link.
另请参阅此文档,以便通过以下链接将此Google美化用品添加到博主。
how to add Syntax Highlighter For Blogger Using Google Prettify
如何使用Google Prettify为Blogger添加语法荧光笔
#5
3
Have a look at SyntaxHightlighter at http://alexgorbatchev.com/wiki/SyntaxHighlighter On that site you can also find instructions on how to use it at blogger.com and the site offers a hosted version of the required scripts so you don't need to host files somewhere yourself.
在http://alexgorbatchev.com/wiki/SyntaxHighlighter上查看SyntaxHightlighter在该站点上,您还可以在blogger.com上找到有关如何使用它的说明,该站点提供了所需脚本的托管版本,因此您不需要需要自己托管文件。
#6
2
Another solution is to use the syntaxhighlighter 2.0 java script library. I've used it on my blog and it seems to work quite well.
另一种解决方案是使用syntaxhighlighter 2.0 java脚本库。我在我的博客上使用它,它看起来效果很好。
Here's a post about it:
这是关于它的帖子:
http://www.craftyfella.com/2010/01/syntax-highlighting-with-blogger-engine.htmllink text
http://www.craftyfella.com/2010/01/syntax-highlighting-with-blogger-engine.htmllink text
Cheers.
干杯。
#7
1
Not a direct answer to your question, but worth consider GitHub. You can get a free account and get syntax colored "gists" which you can share and host on your web page.
不是你问题的直接答案,但值得考虑GitHub。您可以获得一个免费帐户,并获得可以在您的网页上共享和托管的“gists”语法。
The downside is that the copy is hosted on Github's site and if that's down, then it's down for you too.
缺点是副本托管在Github的网站上,如果这个版本失败了,那么它也适合你。
#8
1
cdnjs providing the library "SyntaxHighlighter"
提供库“SyntaxHighlighter”的cdnjs
got to blogger >> template >> edit template add below code just before ending of the body tag and save template.
I have given Example for python.
you can link the other language script files from cdnjs. syntax highlight code
得到博主>>模板>>编辑模板在正文标签结束前添加下面的代码并保存模板。我给了python的例子。您可以从cdnjs链接其他语言脚本文件。语法高亮代码
<pre class="brush: py">
print("hello world")
</pre>
for other languages go and copy script: https://cdnjs.com/libraries/SyntaxHighlighter
对于其他语言去复制脚本:https://cdnjs.com/libraries/SyntaxHighlighter
<!-- syntax highlighter-->
<link href='https://cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/styles/shThemeDefault.css' rel='stylesheet'/>
<script src='https://cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/scripts/shCore.min.js'/>
<script src='https://cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/scripts/shAutoloader.min.js'/>
<!-- for python -->
<script src='https://cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/scripts/shBrushPython.min.js'/>
<!-- include other languages like javascript, php -->
<script language='javascript'>
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all();
</script>
#9
0
Here is the solution that works for me. Put in the <head>...</head>
of dynamic blogger HTML:
这是适合我的解决方案。放入动态博客HTML的 ... :
<script>
$(window.blogger.ui()).on('viewitem', function (event, post, element) {
prettyPrint();
});
</script>
#10
0
Go to blogger theme section and click on edit HTML.. Then add the Google Prettify CDN to the head tag of the HTML.
转到博客主题部分,然后单击编辑HTML ..然后将Google Prettify CDN添加到HTML的head标记。
https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js'/>
https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js'/>
Then include a theme for code snippet below this script..I included Desert theme.
然后在此脚本下面包含一个代码片段主题。我包括沙漠主题。
<!--Desert theme-->
<style type='text/css'>pre .atn,pre .kwd,pre .tag{font-weight:700}pre.prettyprint{display:block;background-color:#333}pre .nocode{background-color:none;color:#000}pre .str{color:#ffa0a0}pre .kwd{color:khaki}pre .com{color:#87ceeb}pre .typ{color:#98fb98}pre .lit{color:#cd5c5c}pre .pln,pre .pun{color:#fff}pre .tag{color:khaki}pre .atn{color:#bdb76b}pre .atv{color:#ffa0a0}pre .dec{color:#98fb98}ol.linenums{margin-top:0;margin-bottom:0;color:#AEAEAE}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}@media print{pre.prettyprint{background-color:none}code .str,pre .str{color:#060}code .kwd,pre .kwd{color:#006;font-weight:700}code .com,pre .com{color:#600;font-style:italic}code .typ,pre .typ{color:#404;font-weight:700}code .lit,pre .lit{color:#044}code .pun,pre .pun{color:#440}code .pln,pre .pln{color:#000}code .tag,pre .tag{color:#006;font-weight:700}code .atn,pre .atn{color:#404}code .atv,pre .atv{color:#060}}</style>
For more themes, visit here.. Prettify themes
欲了解更多主题,请访问此处.. Prettify主题
When you create a post, change the edit mode from visual to HTML and go to the place where you are going to add the code snippet. Then include the code like this.
创建帖子时,将编辑模式从可视化更改为HTML,然后转到要添加代码段的位置。然后包括这样的代码。
<pre class="prettyprint">
<code class="language-html">
<!-- your code snippet -->
</code>
</pre>
You can change the code style by selecting relevant languages html, css, php, javascript... Here I used a html code snippet.
你可以通过选择相关的语言html,css,php,javascript来改变代码风格......这里我使用了一个html代码片段。
#1
60
When you make a new entry in blogger, you get the option to use HTML in your entry and to edit your blog entries.
当您在博客中创建新条目时,您可以选择在条目中使用HTML并编辑博客条目。
so type http://blogger.com , then login, then Posting>Edit Posts>Edit then in there put this at the top:
所以键入http://blogger.com,然后登录,然后发布>编辑帖子>编辑然后将其放在顶部:
<script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/lang-css.min.js"></script>
<script type="text/javascript">
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
addLoadEvent(function() {
prettyPrint();
});
</script>
<style type="text/css">
/* Pretty printing styles. Used with prettify.js. */
.str { color: #080; }
.kwd { color: #008; }
.com { color: #800; }
.typ { color: #606; }
.lit { color: #066; }
.pun { color: #660; }
.pln { color: #000; }
.tag { color: #008; }
.atn { color: #606; }
.atv { color: #080; }
.dec { color: #606; }
pre.prettyprint { padding: 2px; border: 1px solid #888; }
@media print {
.str { color: #060; }
.kwd { color: #006; font-weight: bold; }
.com { color: #600; font-style: italic; }
.typ { color: #404; font-weight: bold; }
.lit { color: #044; }
.pun { color: #440; }
.pln { color: #000; }
.tag { color: #006; font-weight: bold; }
.atn { color: #404; }
.atv { color: #060; }
}
</style>
Note that you shouldn't use prettyPrint
directly as an event handler, it confuses it (see the readme for details). Which is why we're passing addLoadEvent
a function that then turns around and calls prettyPrint
.
请注意,您不应该直接使用prettyPrint作为事件处理程序,它会使它混淆(有关详细信息,请参阅自述文件)。这就是为什么我们传递addLoadEvent一个函数,然后转向并调用prettyPrint。
In this case because blogger does not allow us to link to the stylesheet, we just embed the prettify.css contents.
在这种情况下,因为博客不允许我们链接到样式表,我们只是嵌入了prettify.css内容。
then add a <code></code>
tag or a <pre></pre>
tag with the class name of "prettyprint"
, you can even specify the language like this "prettyprint lang-html"
然后添加一个
标签或一个类名为“prettyprint”的
标签,你甚至可以指定这样的语言“prettyprint lang-html”
so it can look like this
所以它看起来像这样
<pre class="prettyprint lang-html">
<!-- your code here-->
</pre>
or like this
或者像这样
<code class="prettyprint lang-html">
<!-- your code here-->
</code>
the code that you put in needs to have its HTML cleaned from < and > to do this just paste your code in here: http://www.simplebits.com/cgi-bin/simplecode.pl
您放入的代码需要从 <和> 清除其HTML才能执行此操作,只需将代码粘贴到此处:http://www.simplebits.com/cgi-bin/simplecode.pl
you can put the top code in your HTML layout so that its included for all pages by default if you like.
您可以将顶部代码放在HTML布局中,以便默认情况下将其包含在所有页面中(如果您愿意)。
update Now you can link CSS files in blogger, so adding this to the <head>
should be enough
更新现在您可以在博客中链接CSS文件,因此将此添加到就足够了
<link href="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.min.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/lang-css.min.js"></script>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded',function() {
prettyPrint();
});
</script>
I chose not to replace the body onload event on purpose, instead I'm using the new DOMContentLoaded event that the old browsers don't support, if you need old browser support, you can use any other load event to initiate prettyPrint, for example jQuery:
我选择不故意替换body onload事件,而是使用旧浏览器不支持的新DOMContentLoaded事件,如果你需要旧的浏览器支持,你可以使用任何其他load事件来启动prettyPrint,例如jQuery的:
jQuery(function($){
prettyPrint();
});
or the supposedly smallest domready ever
或者所谓的最小的domready
and your done :)
和你完成:)
Edit:
编辑:
as Lim H pointed out in the comments, in case where you use the blogger dynamic views (ajax templates) then you need to use the method described here to bind custom javascript: prettyPrint() doesn't get called on page load
正如Lim H在评论中指出的,如果您使用博客动态视图(ajax模板),那么您需要使用此处描述的方法来绑定自定义javascript:在页面加载时不会调用prettyPrint()
Update 2017-06-04
Use the guide here https://github.com/google/code-prettify
请使用https://github.com/google/code-prettify上的指南
Basically just use this :)
基本上只是用这个:)
<script src="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/run_prettify.min.js"></script>
<pre class="prettyprint"><code class="language-css">...</code></pre>
#2
41
The following worked for me immediately.
以下为我立即工作。
- Go to Blogger > Layout > Edit HTML
- 转到Blogger>布局>编辑HTML
- Copy the following snippet and paste it immediately after
<head>
in the "Edit template" field: - 复制以下代码段并立即将其粘贴到“编辑模板”字段中的之后:
snippet:
片段:
<link href='http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.css' rel='stylesheet' type='text/css'/>
<script src='http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js' type='text/javascript'></script>
- After
</head>
replace<body>
with<body onload='prettyPrint()'>
- 在 之后用替换
- Click "SAVE TEMPLATE"
- 点击“保存模板”
- Go to Blogger > Posting > New Post
- 转到Blogger>发布>新帖子
- Make sure you're editing the HTML by clicking on "Edit HTML." In the empty field try:
- 确保通过单击“编辑HTML”来编辑HTML。在空场中尝试:
<pre class="prettyprint">int foo=0; NSLog(@"%i", foo); </pre>
int foo = 0; NSLog(@“%i”,foo);
- Notice if you click "Preview" now you'll see this code in black only. Don't worry (yet).
- 请注意,如果您现在单击“预览”,您将看到此代码仅为黑色。别担心(还)。
- Click "PUBLISH POST" and then "VIEW BLOG". Your code should be prettified.
- 单击“发布POST”,然后单击“查看博客”。你的代码应该被美化。
#3
15
Nowadays, Google-Code-Prettify has an Auto-Loader script. You can load the JavaScript and CSS for prettify via one URL.
如今,Google-Code-Prettify有一个Auto-Loader脚本。您可以通过一个URL加载JavaScript和CSS以进行美化。
Add the script to the <head>
section of your Blogger template and it will work on all your posts:
将脚本添加到Blogger模板的部分,它将适用于您的所有帖子:
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
More detail here: http://code.google.com/p/google-code-prettify/wiki/GettingStarted
有关详细信息,请访问:http://code.google.com/p/google-code-prettify/wiki/GettingStarted
#4
6
It's very simple to add google code prettifier in your blogger.
在博客中添加谷歌代码美化非常简单。
just include the below javascript library in your blogger just before tag.
只需在标记之前在博客中包含以下javascript库。
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
just like in the below picture...
就像下面的图片一样......
Now you successfully added google code prettifier in your blogger.
现在,您已在博客中成功添加了Google代码美化。
Now if you want to insert code in your blogger post then add code (html, css, php and etc.), then insert that code between .... tags.
现在,如果你想在你的博客帖子中插入代码,然后添加代码(html,css,php等),然后在....标签之间插入该代码。
<pre class="prettyprint">...</pre>
or
要么
<code class="prettyprint">...</code>
Demo of the google Prettify on Blogger
博客上的Google Prettify演示
Also please refer this documentation for adding this Google prettifier to blogger in the following link.
另请参阅此文档,以便通过以下链接将此Google美化用品添加到博主。
how to add Syntax Highlighter For Blogger Using Google Prettify
如何使用Google Prettify为Blogger添加语法荧光笔
#5
3
Have a look at SyntaxHightlighter at http://alexgorbatchev.com/wiki/SyntaxHighlighter On that site you can also find instructions on how to use it at blogger.com and the site offers a hosted version of the required scripts so you don't need to host files somewhere yourself.
在http://alexgorbatchev.com/wiki/SyntaxHighlighter上查看SyntaxHightlighter在该站点上,您还可以在blogger.com上找到有关如何使用它的说明,该站点提供了所需脚本的托管版本,因此您不需要需要自己托管文件。
#6
2
Another solution is to use the syntaxhighlighter 2.0 java script library. I've used it on my blog and it seems to work quite well.
另一种解决方案是使用syntaxhighlighter 2.0 java脚本库。我在我的博客上使用它,它看起来效果很好。
Here's a post about it:
这是关于它的帖子:
http://www.craftyfella.com/2010/01/syntax-highlighting-with-blogger-engine.htmllink text
http://www.craftyfella.com/2010/01/syntax-highlighting-with-blogger-engine.htmllink text
Cheers.
干杯。
#7
1
Not a direct answer to your question, but worth consider GitHub. You can get a free account and get syntax colored "gists" which you can share and host on your web page.
不是你问题的直接答案,但值得考虑GitHub。您可以获得一个免费帐户,并获得可以在您的网页上共享和托管的“gists”语法。
The downside is that the copy is hosted on Github's site and if that's down, then it's down for you too.
缺点是副本托管在Github的网站上,如果这个版本失败了,那么它也适合你。
#8
1
cdnjs providing the library "SyntaxHighlighter"
提供库“SyntaxHighlighter”的cdnjs
got to blogger >> template >> edit template add below code just before ending of the body tag and save template.
I have given Example for python.
you can link the other language script files from cdnjs. syntax highlight code
得到博主>>模板>>编辑模板在正文标签结束前添加下面的代码并保存模板。我给了python的例子。您可以从cdnjs链接其他语言脚本文件。语法高亮代码
<pre class="brush: py">
print("hello world")
</pre>
for other languages go and copy script: https://cdnjs.com/libraries/SyntaxHighlighter
对于其他语言去复制脚本:https://cdnjs.com/libraries/SyntaxHighlighter
<!-- syntax highlighter-->
<link href='https://cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/styles/shThemeDefault.css' rel='stylesheet'/>
<script src='https://cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/scripts/shCore.min.js'/>
<script src='https://cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/scripts/shAutoloader.min.js'/>
<!-- for python -->
<script src='https://cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/scripts/shBrushPython.min.js'/>
<!-- include other languages like javascript, php -->
<script language='javascript'>
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all();
</script>
#9
0
Here is the solution that works for me. Put in the <head>...</head>
of dynamic blogger HTML:
这是适合我的解决方案。放入动态博客HTML的 ... :
<script>
$(window.blogger.ui()).on('viewitem', function (event, post, element) {
prettyPrint();
});
</script>
#10
0
Go to blogger theme section and click on edit HTML.. Then add the Google Prettify CDN to the head tag of the HTML.
转到博客主题部分,然后单击编辑HTML ..然后将Google Prettify CDN添加到HTML的head标记。
https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js'/>
https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js'/>
Then include a theme for code snippet below this script..I included Desert theme.
然后在此脚本下面包含一个代码片段主题。我包括沙漠主题。
<!--Desert theme-->
<style type='text/css'>pre .atn,pre .kwd,pre .tag{font-weight:700}pre.prettyprint{display:block;background-color:#333}pre .nocode{background-color:none;color:#000}pre .str{color:#ffa0a0}pre .kwd{color:khaki}pre .com{color:#87ceeb}pre .typ{color:#98fb98}pre .lit{color:#cd5c5c}pre .pln,pre .pun{color:#fff}pre .tag{color:khaki}pre .atn{color:#bdb76b}pre .atv{color:#ffa0a0}pre .dec{color:#98fb98}ol.linenums{margin-top:0;margin-bottom:0;color:#AEAEAE}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}@media print{pre.prettyprint{background-color:none}code .str,pre .str{color:#060}code .kwd,pre .kwd{color:#006;font-weight:700}code .com,pre .com{color:#600;font-style:italic}code .typ,pre .typ{color:#404;font-weight:700}code .lit,pre .lit{color:#044}code .pun,pre .pun{color:#440}code .pln,pre .pln{color:#000}code .tag,pre .tag{color:#006;font-weight:700}code .atn,pre .atn{color:#404}code .atv,pre .atv{color:#060}}</style>
For more themes, visit here.. Prettify themes
欲了解更多主题,请访问此处.. Prettify主题
When you create a post, change the edit mode from visual to HTML and go to the place where you are going to add the code snippet. Then include the code like this.
创建帖子时,将编辑模式从可视化更改为HTML,然后转到要添加代码段的位置。然后包括这样的代码。
<pre class="prettyprint">
<code class="language-html">
<!-- your code snippet -->
</code>
</pre>
You can change the code style by selecting relevant languages html, css, php, javascript... Here I used a html code snippet.
你可以通过选择相关的语言html,css,php,javascript来改变代码风格......这里我使用了一个html代码片段。