如何在Blogger嵌入程式碼-Google Code Prettify
加入程式碼區塊教學可參考此篇文章
https://eric0806.blogspot.tw/2014/04/blogger-google-code-prettify.html
首先在</head>標籤前加入以下程式碼:
接著在</body>標籤前加入以下程式碼:
使用時方式如下:
成果如下:
https://eric0806.blogspot.tw/2014/04/blogger-google-code-prettify.html
首先在</head>標籤前加入以下程式碼:
- <style type='text/css'>
- /*程式碼高亮設定*/
- /*main box*/
- .pre-highborder{
- border: 1px solid #ff0000;
- padding: 3px 3px 3px 0;
- }
- pre.prettyprint, code.prettyprint {
- border-radius: 8px;
- -moz-border-radius: 8px;
- -webkit-border-radius: 8px;
- padding: 5px;
- background-color: #eee !important;
- box-shadow: 0 0 5px #999;
- -moz-box-shadow: 0 0 5px #999;
- -webkit-box-shadow: 0 0 5px #999;
- }
- /*font*/
- pre span, code span {
- font-family: 'monospace', 'Courier New', 'Microsoft JhengHei', sans-serif !important;
- font-size: 12px !important;
- }
- /*each line*/
- li.L0, li.L1, li.L2, li.L3, li.L4, li.L5, li.L6, li.L7, li.L8, li.L9 {
- margin: 0 !important;
- padding: 2px 0 2px 4px !important;
- list-style-type:decimal !important;
- border-left: 1px solid #999;
- }
- /*even line*/
- li.L1, li.L3, li.L5, li.L7, li.L9 {
- background-color: #f6f6f6 !important;
- }
- /*odd line*/
- li.L0, li.L2, li.L4, li.L6, li.L8 {
- background-color: #FFF !important;
- }
- /*line-number background color*/
- ol.linenums {
- background-color: #eee;
- margin-left: 10px;
- }
- </style>
接著在</body>標籤前加入以下程式碼:
- <script src='https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js?autoload=true&lang=basic&lang=css&lang=sql' />
- <script src='//ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js' />
- <script type='text/javascript'>
- $("pre").each(function(){
- $(this).addClass('prettyprint').addClass('linenums');
- });
- </script>
使用時方式如下:
- <pre>
- <!--這裡就可以放你的程式碼了-->
- </pre>
成果如下:
- #include <iostream>
- using namespace std;
- int main()
- {
- cout << "Hello, World!";
- return 0;
- }
留言
張貼留言