时光沉淀

使用prism.js代码高亮

· Views · By 浪子

实现代码块高亮显示效果
head加入

<script src="https://cdnjs.sgcd.net/code-highlight/js/prism.js"></script>
<link rel="stylesheet" href="https://cdnjs.sgcd.net/code-highlight/css/prism.css"  />

footer加入

<script>Prism.highlightAll()  </script>

美化 mac 风格

在js中加入

var container = document.getElementsByTagName('main')[0];
var codeBlocks = container.getElementsByTagName('pre');
Array.from(codeBlocks).forEach(function(item) {
  item.style.whiteSpace = 'pre-wrap';
  // Add pre-mac element for Mac Style UI
  var preMac = document.createElement('div');
  preMac.classList.add('pre-mac');
  preMac.innerHTML = '<span></span><span></span><span></span>';
  item.parentNode.insertBefore(preMac, item);
  item.classList.add('line-numbers');
});

css

.pre-mac {
  position: relative;
  margin-top: -7px;
  top: 21px;
  left: 10px;
  width: 100px;
  z-index: 99;
}
.pre-mac > span {
  float: left;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 5px;
}
.pre-mac > span:nth-child(1) {
  background: red;
}
.pre-mac > span:nth-child(2) {
  background: sandybrown;
}
.pre-mac > span:nth-child(3) {
  background: limegreen;
} 

评论

0 条评论

暂无评论

Using $this when not in object context

Error: Using $this when not in object context in /app/data/plugins/FediverseSync/template/comment.php:3 Stack trace: #0 /app/data/plugins/FediverseSync/Plugin.php(989): require_once() #1 [internal function]: FediverseSync_Plugin::renderComments(Object(Widget\Archive), NULL) #2 /app/var/Typecho/Plugin.php(446): call_user_func_array(Array, Array) #3 /app/var/Widget/Archive.php(1274): Typecho\Plugin->__call('Widget_Archive:...', Array) #4 /app/data/themes/paper-main/footer.php(23): Widget\Archive->footer() #5 /app/var/Widget/Archive.php(1336): require('/app/data/theme...') #6 /app/data/themes/paper-main/post.php(51): Widget\Archive->need('footer.php') #7 /app/var/Widget/Archive.php(1418): require_once('/app/data/theme...') #8 /app/var/Typecho/Router.php(99): Widget\Archive->render() #9 /app/index.php(23): Typecho\Router::dispatch() #10 {main}