wordpress.highlight.js代码高亮显示
wordpress.highlight.js代码高亮显示
1、启用highlight.js代码高亮显示插件Enlighter – Customizable Syntax Highlighter

2、选择Enlighter – Customizable Syntax Highlighter 高亮显示代码插件,插入代码

3、粘贴代码确认,页面预览,显示效果

c展示高亮代码如下
// Test SOCKS5 proxy connectivity using libcurl
// Build: make (with CURL_LIB and CURL_INC vars if needed)
// Run: ./testproxy_libcurl
#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>
// Write callback to capture response
static size_t write_callback(void *contents, size_t size, size_t nmemb, void *userp) {
size_t realsize = size * nmemb;
FILE *fp = (FILE *)userp;
fwrite(contents, 1, realsize, fp);
return realsize;
}
int main(void) {
CURL *curl;
CURLcode res;
FILE *output_file;
const char *proxy_url = "socks5h://127.0.0.1:10808";
const char *target_url = "https://www.google.com";
const char *output_filename = "google_libcurl.txt";
// Initialize libcurl
curl_global_init(CURL_GLOBAL_DEFAULT);
// Open output file
output_file = fopen(output_filename, "wb");
if (!output_file) {
perror("Failed to open output file");
curl_global_cleanup();
return EXIT_FAILURE;
}
// Initialize curl easy handle
curl = curl_easy_init();
if (!curl) {
fprintf(stderr, "Failed to initialize curl\n");
fclose(output_file);
curl_global_cleanup();
return EXIT_FAILURE;
}
// Set proxy
curl_easy_setopt(curl, CURLOPT_PROXY, proxy_url);
// Set target URL
curl_easy_setopt(curl, CURLOPT_URL, target_url);
// Set write callback to capture response body
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, output_file);
// Optional: follow redirects
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
// Perform request
printf("Fetching %s through proxy %s...\n", target_url, proxy_url);
res = curl_easy_perform(curl);
// Check for errors
if (res != CURLE_OK) {
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
fclose(output_file);
curl_easy_cleanup(curl);
curl_global_cleanup();
return EXIT_FAILURE;
}
// Get response code
long response_code;
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
printf("HTTP response code: %ld\n", response_code);
// Clean up
fclose(output_file);
curl_easy_cleanup(curl);
curl_global_cleanup();
printf("Content saved to %s\n", output_filename);
return EXIT_SUCCESS;
}
/*
//Makefile Makefile_libcurl
//rm -rf testproxy_libcurl
// make -f Makefile_libcurl
//
# Makefile for testproxy_libcurl
# Builds an HTTP client using libcurl with SOCKS5 proxy support
# Requires: libcurl development files
CC = gcc
CFLAGS = -I/usr/include -Wall -Wextra $(shell pkg-config --cflags libcurl)
LDFLAGS = $(shell pkg-config --libs libcurl) -lrt
TARGET = testproxy_libcurl
SRC = $(TARGET).c
.PHONY: all clean
all: $(TARGET)
$(TARGET): $(SRC)
$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
clean:
rm -f $(TARGET) google_libcurl.txt
run: $(TARGET)
./$(TARGET)
*/
1. 在 Scripts in Header 框中粘贴以下代码(完整复制)
<!-- Highlight.js 核心 CDN -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/atom-one-dark.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<!-- 行号插件 -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlightjs-line-numbers.js/2.8.0/highlightjs-line-numbers.min.js"></script>
<!-- 代码块全局样式 -->
<style>
.code-box {
position: relative;
margin: 20px 0;
border-radius: 8px;
overflow: hidden;
font-family: Consolas, Monaco, monospace !important;
}
.code-light {
background: #ffffff;
border: 1px solid #e1e4e8;
}
.code-dark {
background: #282c34;
border: 1px solid #3e4451;
}
.code-copy {
position: absolute;
top: 8px;
right: 12px;
padding: 4px 10px;
font-size: 12px;
border-radius: 4px;
border: none;
cursor: pointer;
z-index: 99;
background: #fff;
color: #333;
opacity: 0.9;
}
.code-dark .code-copy {
background: #3e4451;
color: #fff;
}
.code-copy:hover { opacity: 1; }
.hljs { padding: 1.5rem !important; }
.hljs-ln-numbers {
opacity: 0.5 !important;
padding-right: 1rem !important;
user-select: none;
}
</style>
<script>
// 初始化高亮和行号
document.addEventListener('DOMContentLoaded', function() {
hljs.highlightAll();
hljs.initLineNumbersOnLoad();
});
// 一键复制功能
function copyCode(btn) {
const codeText = btn.nextElementSibling.textContent.trim();
navigator.clipboard.writeText(codeText).then(function() {
var oldText = btn.innerText;
btn.innerText = "已复制";
setTimeout(function() { btn.innerText = oldText; }, 1500);
});
}
</script>
3. 点击页面底部 Save 按钮保存
✅ 全局配置完成! 现在你的整个网站所有文章 / 页面都支持代码高亮了!
四、第三步:在经典编辑器中使用(超简单)
以后写代码,只需要在「文本模式」粘贴代码结构,全自动高亮 + 行号 + 复制!
通用模板(直接用)
<div class="code-box code-light"> <button class="code-copy" onclick="copyCode(this)">复制</button> <pre><code class="language-你的语言"> 粘贴代码 </code></pre> </div>
五、你的测试代码(直接粘贴到文章里)
自适应IP