代码高亮

2023/02/24 10:07:20 heyan hexo

这里简单展示一下我们的主题对代码的高亮效果。

Java

class Solution {
    public int[] twoSum(int[] nums, int target) {
        int n = nums.length;
        for (int i = 0; i < n; ++i) {
            for (int j = i + 1; j < n; ++j) {
                if (nums[i] + nums[j] == target) {
                    return new int[]{i, j};
                }
            }
        }
        return new int[0];
    }
}

C

int* twoSum(int* nums, int numsSize, int target, int* returnSize) {
    for (int i = 0; i < numsSize; ++i) {
        for (int j = i + 1; j < numsSize; ++j) {
            if (nums[i] + nums[j] == target) {
                int* ret = malloc(sizeof(int) * 2);
                ret[0] = i, ret[1] = j;
                *returnSize = 2;
                return ret;
            }
        }
    }
    *returnSize = 0;
    return NULL;
}

C++

class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        int n = nums.size();
        for (int i = 0; i < n; ++i) {
            for (int j = i + 1; j < n; ++j) {
                if (nums[i] + nums[j] == target) {
                    return {i, j};
                }
            }
        }
        return {};
    }
};

Python

class Solution:
    def twoSum(self, nums: List[int], target: int) -> List[int]:
        n = len(nums)
        for i in range(n):
            for j in range(i + 1, n):
                if nums[i] + nums[j] == target:
                    return [i, j]
        
        return []

Golang

func twoSum(nums []int, target int) []int {
    for i, x := range nums {
        for j := i + 1; j < len(nums); j++ {
            if x+nums[j] == target {
                return []int{i, j}
            }
        }
    }
    return nil
}

Scala

object HelloWorld {
    def main(args: Array[String]): Unit = {
        println("Hello, world!")
    }
}

C#

using System;
namespace HelloWorldApplication
{
    /* 类名为 HelloWorld */
    class HelloWorld
    {
        /* main函数 */
        static void Main(string[] args)
        {
            /* 我的第一个 C# 程序 */
            Console.WriteLine("Hello World!");
            Console.ReadKey();
        }
    }
}

html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>heyan主题</title>
</head>
<body>
  <h1>主题效果展示</h1>
  <p>代码高亮</p>
</body>
</html>

css

// 链接
.markdown-section a:not(.title)
  color: #121212;
  font-family: "Serif";
  font-weight: 420;
  padding-inline: 2px;
  text-decoration: none;

// h1, h2
.markdown-section h1,
.markdown-section h2
  padding: 8px 0px;
  border-bottom: 2px solid;
  margin-top: 10px;
  margin-bottom: 5px;
  font-size: 1.7rem;
  border-color: #eeeeee;

.markdown-section h3
  padding: 8px 0px;
  margin-top: 6px;
  margin-bottom: 3px;
  font-size: 1.4rem;

javascript

$(document).ready(function() {
    $('img').each(function() {
      if ($(this).parent().hasClass('fancybox')) return;
      if ($(this).hasClass('nofancybox')) return;
      var alt = this.alt;
      if (alt) $(this).after('<span class="caption">' + alt + '</span>');
      $(this).wrap('<a href="' + ($(this).attr('data-src') == null ? this.src : $(this).attr('data-src')) + '" title="' + alt + '" class="fancybox"></a>');
    })
    $(this).find('.fancybox').each(function(){
      $(this).attr('rel', 'article')
    })
    $("a[href$='.jpg'],a[href$='.png'],a[href$='.gif'],a[href$='.webp']").attr('rel', 'gallery').fancybox({
      helpers : {
      title: { type: 'inside'}
      }
    });
    
    // 如果页面的高度小于屏幕的高度,为了避免底部导航栏 "居中"
    if (document.body.scrollHeight < window.screen.availHeight) {
      $("#flex_bottom").addClass("fixed-bottom");
    } else {
      $("#flex_bottom").removeClass("fixed-bottom");
    }
});

yaml

# 导航栏
menu_left:
  - title: 主页
    path: '' 
    icon_class: 'fa fa-home'
  - title: 归档
    path: 'archives'
    icon_class: 'fa fa-archive'
  - title: 关于
    path: /about
    icon_class: 'fa fa-user'

post_excerpt_paragraph: 1
max_excerpt_words: 500

menu_right:


search: 
  enable: true  # 是否使用搜索功能
  placeholder: 搜索

# 侧边栏展示的内容以及顺序
widgets_left:
  - category
widgets_right:
  - tag
  - recent
  - links


widgets_links:
  - title: csdn
    url: https://blog.csdn.net/smileyan9
  - title: 笑颜网
    url: https://smileyan.cn
  - title: Hexo
    url: https://hexo.io

# 默认情况下展示的分类,标签,最近的
# length 数目,超过部分折叠
# sort_by 排序依据
# rule 递增或递减
widgets_default_show:
  category:
    length: 10
    sort_by: length # length | name
    rule: desc      # desc | asc
  tag: 
    length: 10
    sort_by: name   # length | name
    rule: desc      # desc | asc
  recent:
    length: 5
    sort_by: date   # date | updated
    rule: desc      # desc | asc

# 是否使用 fancy | mathjax
fancybox: true
mathjax: true

# 备案号
beian: 湘ICP备 17012851号

Bash

# resolve links - $0 may be a softlink
PRG="$0"

while [ -h "$PRG" ] ; do
  ls=`ls -ld "$PRG"`
  link=`expr "$ls" : '.*-> \(.*\)$'`
  if expr "$link" : '/.*' > /dev/null; then
    PRG="$link"
  else
    PRG=`dirname "$PRG"`/"$link"
  fi
done

SQL

SELECT * FROM Websites ORDER BY alexa DESC;

SELECT websites.name, access_log.count, access_log.date
FROM websites
RIGHT JOIN access_<pre class="command-line">log
ON access_log.site_id=websites.id
ORDER BY access_log.count DESC;

XML

<?xml version="1.0" encoding="UTF-8"?>
<site>
  <name>RUNOOB</name>
  <url>https://www.runoob.com</url>
  <logo>runoob-logo.png</logo>
  <desc>编程学习网站</desc>
</site>

https://prismjs.com/download.html#themes=prism&languages=markup+css+clike+javascript+bash+c+csharp+cpp+go+java+python+scala+sql+yaml&plugins=line-numbers+show-language+toolbar+copy-to-clipboard