我嘗試添加使用語法高亮highlight.js我的申請工作,但它似乎並沒有與角2highlight.js不角2
工作能否請你讓我知道什麼,我可能是不正確的?
這裏是Plnkr:https://plnkr.co/edit/G3NFFPGXKyc9mV1a6ufJ?p=preview
這是組件
import {Component} from 'angular2/core';
@Component({
selector: "my-app",
template: `
Hello!
<pre>
<code class="html">
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
</code>
</pre>
`
})
export class AppComponent{
}
而這正是我使用CDN將highlight.js:
<!DOCTYPE html>
<html>
<head>
<!-- IE required polyfills, in this exact order -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.35.0/es6-shim.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.25/system-polyfills.js"></script>
<script src="https://npmcdn.com/angular2/es6/dev/src/testing/shims_for_IE.js"></script>
<!-- Angular polyfill required everywhere -->
<script src="https://code.angularjs.org/2.0.0-beta.13/angular2-polyfills.js"></script>
<script src="https://code.angularjs.org/tools/system.js"></script>
<script src="https://code.angularjs.org/tools/typescript.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.13/Rx.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.13/angular2.dev.js"></script>
<link rel="stylesheet" href="style.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.4.0/styles/solarized-light.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.4.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script>
System.config({
transpiler: 'typescript',
typescriptOptions: { emitDecoratorMetadata: true },
packages: {
'api': {defaultExtension: 'ts'},
'app': {defaultExtension: 'ts'}
}
});
System.import('app/main')
.then(null, console.error.bind(console));
</script>
</head>
<body>
<my-app>loading...</my-app>
</body>
</html>
https://highlightjs.org/usage/
感謝蒂埃裏。這樣可行。但是如果在同一頁面上有多個代碼塊呢?我可以將#code應用於所有這些塊嗎?我雖然只能在一個塊上使用#代碼。 – takeradi
不客氣!是的,你是對的;-)我添加了一個基於directivve的方法。看到我更新的答案... –