Skip to content

Commit

Permalink
add代码高亮
Browse files Browse the repository at this point in the history
  • Loading branch information
jkjoy committed Jul 2, 2024
1 parent b647b0c commit 8449fd3
Show file tree
Hide file tree
Showing 8 changed files with 17,698 additions and 6 deletions.
2 changes: 0 additions & 2 deletions comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@
);
?>
<?php else: ?>

<center><h3><?php _e('暂无评论'); ?></h3></center>

<?php endif; ?>
<div id="<?php $this->respondId(); ?>" class="comment-respond">
<div class="cancel-comment-reply cancel-comment-reply-link"><?php $comments->cancelReply(); ?></div>
Expand Down
5 changes: 3 additions & 2 deletions footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
</div>
<?php $this->options->tongji(); ?>
</footer>
<script>
<?php if ($this->options->showprism): ?>
<script>
document.addEventListener('DOMContentLoaded', function () {
var defaultLanguage = 'javascript'; // 设置默认语言
document.querySelectorAll('pre code').forEach(function (block) {
Expand All @@ -17,7 +18,7 @@
Prism.highlightAll();
});
</script>

<?php endif; ?>
</div>
</body>
</html>
4 changes: 4 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ function themeConfig($form) {
array('0'=> _t(''), '1'=> _t('')),
'0', _t('是否显示文章目录'), _t('选择“是”将在文章页面显示文章目录(仅在宽度大于1400px的设备中显示)。'));
$form->addInput($showtoc);
$showprism = new Typecho_Widget_Helper_Form_Element_Radio('showprism',
array('0'=> _t(''), '1'=> _t('')),
'0', _t('是否代码高亮'), _t('选择“是”将引用prism.js代码高亮显示'));
$form->addInput($showprism);
}
function get_post_view($archive) {
$cid = $archive->cid;
Expand Down
2 changes: 0 additions & 2 deletions header.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
<script src="<?php $this->options->themeUrl('script.js'); ?>"></script>
<?php $this->header("generator=&template=&pingback=&wlw=&xmlrpc=&rss1=&atom=&rss2=/feed"); ?>
<?php $this->options->addhead(); ?>
<script src="//cdnjs.sgcd.net/code-highlight/js/prism.js"></script>
<link rel="stylesheet" href="//cdnjs.sgcd.net/code-highlight/css/prism.css" />
<?php $this->header(); ?>
</head>
<body>
Expand Down
4 changes: 4 additions & 0 deletions page.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php $this->need('header.php'); ?>
<?php if ($this->options->showprism): ?>
<script src="<?php $this->options->themeUrl('prism.js'); ?>"></script>
<link rel="stylesheet" href="<?php $this->options->themeUrl('prism.css'); ?>" />
<?php endif; ?>
<div class="main">
<div class="container">
<article class="post-wrap page">
Expand Down
4 changes: 4 additions & 0 deletions post.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php $this->need('header.php'); ?>
<?php if ($this->options->showprism): ?>
<script src="<?php $this->options->themeUrl('prism.js'); ?>"></script>
<link rel="stylesheet" href="<?php $this->options->themeUrl('prism.css'); ?>" />
<?php endif; ?>
<div class="main">
<div class="container">
<?php if ($this->options->showtoc): ?>
Expand Down
Loading

0 comments on commit 8449fd3

Please sign in to comment.