简体   繁体   English

用语义ui代码突出显示

[英]Code highlighting with semantic-ui

I'm using semantic-ui for a website and I want to know if code highlighting is an actual feature it supports. 我正在为网站使用semantic-ui,我想知道代码突出显示是否是它支持的实际功能。

There are code blocks shown throughout the library's docs pages with highlighted code but I can't find any details about how to use it in my project. 整个库的文档页面中都显示了代码块,其中包含突出显示的代码,但我找不到有关如何在项目中使用它的任何详细信息。

After looking at their page's source code I tried creating the following divs which did not highlight the code: 在查看了他们页面的源代码后,我尝试创建以下没有突出显示代码的div:

<div class="ui segment">
  <div class="ui ignored code" data-type="bash" data-title="commands">
    #!/bin/bash

    # test
    echo 'hello there'
  </div>
</div>

Also tried including this script: http://semantic-ui.com/javascript/library/highlight.min.js 还试过包括这个脚本: http//semantic-ui.com/javascript/library/highlight.min.js

Am I coding it wrong or is code highlighting not even part of the library? 我编码错了还是代码突出显示甚至不是库的一部分?

As jlukic said in this post they use highlight.js library to insert code.Then you need to initialize initHighlightingOnLoad() function to use their code syntax: 正如jlukic在这篇文章中所说,他们使用highlight.js库来插入代码。然后你需要初始化initHighlightingOnLoad()函数来使用他们的代码语法:

 hljs.initHighlightingOnLoad(); 
 <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css"> <script src="https://semantic-ui.com/javascript/library/highlight.min.js"></script> <div class="ui segment"> <pre><code class="bash"> #!/bin/bash # test echo 'hello there' </code></pre> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM