Ich versuche Syntax hinzufügen, um meine Anwendung hervorgehoben highlight.js verwenden, aber es scheint nicht mit kantigem 2.highlight.js funktioniert nicht mit kantigem 2
arbeiten Könnten Sie mir bitte mitteilen, was ich könnte es falsch machen? Hier
ist die Plnkr: https://plnkr.co/edit/G3NFFPGXKyc9mV1a6ufJ?p=preview
Dies ist die Komponente
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{
}
und das ist, wo ich highlight.js bin Zugabe CDN:
<!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/
danke Thierry. das funktioniert. Aber was ist, wenn auf derselben Seite mehrere Codeblöcke vorhanden sind? Kann ich #code auf all diese Blöcke anwenden? Ich kann zwar #code auf nur einem Block verwenden. – takeradi
Gern geschehen! Ja, du hast Recht ;-) Ich habe einen Ansatz hinzugefügt, der auf einer Direktive basiert. Siehe meine aktualisierte Antwort ... –