feat: Markdown 渲染器支持 Apache 配置文件语法高亮
continuous-integration/drone/push Build is passing

This commit is contained in:
seahi committed 2026-09-27 21:28:00 +08:00
1 parent a83acc1427
commit 94e76bbcd2
2 files changed
+24

No files matched your search

+4
View File
@@ -27,6 +27,7 @@ import java from 'highlight.js/lib/languages/java';
import php from 'highlight.js/lib/languages/php'; import php from 'highlight.js/lib/languages/php';
import dockerfile from 'highlight.js/lib/languages/dockerfile'; import dockerfile from 'highlight.js/lib/languages/dockerfile';
import nginx from 'highlight.js/lib/languages/nginx'; import nginx from 'highlight.js/lib/languages/nginx';
import apache from 'highlight.js/lib/languages/apache';
import ini from 'highlight.js/lib/languages/ini'; import ini from 'highlight.js/lib/languages/ini';
import http from 'highlight.js/lib/languages/http'; import http from 'highlight.js/lib/languages/http';
import diff from 'highlight.js/lib/languages/diff'; import diff from 'highlight.js/lib/languages/diff';
@@ -57,6 +58,9 @@ hljs.registerLanguage('java', java);
hljs.registerLanguage('php', php); hljs.registerLanguage('php', php);
hljs.registerLanguage('dockerfile', dockerfile); hljs.registerLanguage('dockerfile', dockerfile);
hljs.registerLanguage('nginx', nginx); hljs.registerLanguage('nginx', nginx);
hljs.registerLanguage('apache', apache);
hljs.registerLanguage('apacheconf', apache);
hljs.registerLanguage('httpd', apache);
hljs.registerLanguage('ini', ini); hljs.registerLanguage('ini', ini);
hljs.registerLanguage('toml', ini); hljs.registerLanguage('toml', ini);
hljs.registerLanguage('http', http); hljs.registerLanguage('http', http);
+20
View File
@@ -7,6 +7,7 @@ import {
resolveAdmonitionTitle, resolveAdmonitionTitle,
sanitizeMarkdownHtml sanitizeMarkdownHtml
} from './rendering'; } from './rendering';
import { renderMarkdown } from './renderer';
describe('replaceGithubAdmonitions', () => { describe('replaceGithubAdmonitions', () => {
it('passes the type, title and quote body to the renderer', () => { it('passes the type, title and quote body to the renderer', () => {
@@ -122,3 +123,22 @@ describe('sanitizeMarkdownHtml', () => {
expect(sanitized).toContain('rel="noopener noreferrer"'); expect(sanitized).toContain('rel="noopener noreferrer"');
}); });
}); });
describe('renderMarkdown code highlighting', () => {
it('highlights apache, apacheconf, and httpd configuration blocks', () => {
const mdApache = '```apache\nRewriteEngine On\nRewriteRule ^index\\.html$ / [R=301,L]\n```';
const htmlApache = renderMarkdown(mdApache);
expect(htmlApache).toContain('language-apache');
expect(htmlApache).toContain('RewriteEngine');
const mdConf = '```apacheconf\n<VirtualHost *:80>\nServerName example.com\n</VirtualHost>\n```';
const htmlConf = renderMarkdown(mdConf);
expect(htmlConf).toContain('language-apacheconf');
expect(htmlConf).toContain('hljs-section');
const mdHttpd = '```httpd\n<VirtualHost *:80>\nServerName example.com\n</VirtualHost>\n```';
const htmlHttpd = renderMarkdown(mdHttpd);
expect(htmlHttpd).toContain('language-httpd');
expect(htmlHttpd).toContain('hljs-section');
});
});