本文共 5400 字,大约阅读时间需要 18 分钟。
ppt 代码语法突出显示
For websites like ours, code
blocks and pre
tags are necessities. Making these code blocks look good and function well is a big part of having your tutorial or example understood and easily digestable by your users.
对于像我们这样的网站,必须有code
块和pre
标签。 使这些代码块看起来不错且功能良好,这是使您的教程或示例易于理解并被用户轻松理解的很大一部分。
We've been asked quite a few times what tool we use for syntax highlighting here at Scotch. Here it is!
我们已经多次问过我们在Scotch使用什么工具来突出显示语法。 这里是!
Today we'll be looking at a great tool that some of you may have heard of: . Prism is a simple, lightweight, and easy to use syntax highlighter. It is easily customizable and has support for some plugins to extend its functionality.
今天,我们将看一个其中一些人可能听说过的出色工具: 。 Prism是一种简单,轻巧且易于使用的语法突出显示器。 它易于定制,并支持某些插件以扩展其功能。
Here's a quick example:
这是一个简单的例子:
For websites like ours,
code
blocks andpre
tags are necessities. Making these code blocks look good and function well is a big part of having your tutorial or example understood and easily digestable by your users.We've been asked quite a few times what tool we use for syntax highlighting here at Scotch. Here it is!
Today we'll be looking at a great tool that some of you may have heard of: PrismJS. Prism is a simple, lightweight, and easy to use syntax highlighter. It is easily customizable and has support for some plugins to extend its functionality.
code
tag. Some other highlighters just tell you to use pre
. Prism makes you use both for good code. It also uses the HTML5 recommended way of defining a language using class="language-xxxx"
. 良好实践为了在编写代码时在语义上正确,您应该使用实际的code
标记。 其他一些荧光笔只是告诉您使用pre
。 Prism使您同时使用这两种代码。 它还使用HTML5建议的使用class="language-xxxx"
定义语言的方式。 And don't forget yours truly! We use Prism right here on Scotch.
并不要真正忘记您的! 我们在苏格兰这里就使用Prism。
Implementing Prism into your site is an extremely easy process. Just link to the css
and the js
files and start highlighting!
在您的站点中实施Prism是一个非常简单的过程。 只需链接到css
和js
文件并开始突出显示即可!
Go get your download from the Prism website.
从Prism网站获取下载。
Once you have the files you have configured Prism to your needs, download and include the files into your project.
获得文件后,可以根据需要配置Prism,然后下载文件并将其包含在项目中。
Now we will include these files into our project.
现在,我们将这些文件包含到我们的项目中。
Look At Me Prism-ing
That's it. Now we are ready to use Prism.
而已。 现在我们准备使用棱镜。
After you have included the necessary files, using Prism is very easy. All you have to do is add a pre
and code
tag to your site. Then add a class to your code
tag and you have beautiful syntax highlighting.
包含必要的文件后,使用Prism非常容易。 您所要做的就是在网站上添加pre
和code
标签。 然后将一个类添加到您的code
标签中,您将获得漂亮的语法突出显示。
look at my html stuff here
Just like that you have beautiful syntax highlighting. Notice how we use language-markup
to highlight HTML files. Here are the different classes to use for the different languages.
就像您拥有漂亮的语法突出显示一样。 注意我们如何使用language-markup
突出显示HTML文件。 这是用于不同语言的不同类。
Language | Class |
HTML | language-markup |
CSS | language-css |
JavaScript | language-javascript |
CoffeeScript | language-coffeescript |
PHP | language-php |
Ruby | language-ruby |
Go | language-go |
语言 | 类 |
HTML | 语言标记 |
CSS | 语言css |
JavaScript | 语言JavaScript |
CoffeeScript | 语言咖啡 |
PHP | 语言PHP |
Ruby | 语言Ruby |
走 | 语言去 |
Prism lets you configure your download with a few different themes.
Prism使您可以配置一些不同主题的下载。
Prism lets you extend the features using plugins and it has some great ones ready to go.
Prism允许您使用插件扩展功能,并且有许多不错的功能可供使用。
a specific line in your code. Use the data-line
attribute on your pre
tag.
代码中的特定行。 在pre
标签上使用data-line
属性。
body { background:#F2F2F2; }h1, h2, h3, h4, h5, h6 { font-family:'Raleway'; }.container { width:90%; }
Add to your code blocks. Do this by adding a class to your pre
tag.
将添加到您的代码块。 为此,可以在您的pre
标签中添加一个类。
pre class="line-numbers"
pre class="line-numbers"
Using Prism is a quick and easy way to get beautiful syntax highlighting for your code. There are other alternatives out there, but we feel that Prism does the job well and is incredibly easy to use.
使用Prism是一种快速简便的方法,可为代码获得漂亮的语法突出显示。 还有其他选择,但是我们认为Prism做得很好,并且非常易于使用。
If you have any favorite tools for showing off code or anything similar, sound off in the comments.
如果您有喜欢的工具来展示代码或类似的东西,请在注释中取消提示。
翻译自:
ppt 代码语法突出显示
转载地址:http://rjywd.baihongyu.com/