<code-highlighter>
Performs code highlighting on the body of the element. Useful when Source Code (e.g. Java Code) needs to be rendered as part of View.
Demo of how this works is available here
Pre-requisite
First, make sure you have the npm (packaged with Node.js) installed.
Install the WebComponent
Run sudo npm install --save polymer-code-highlighter
to install the Code-Highlighter webcomponent.
How to use in a HTML file
In the HTML file, please do following:
- Add the script tag to get the code-highlighter.js.
- Add the tag to highlight the sample code.
<!-- #1. Get the code-highlighter.js -->Basic code-highlighter demo<!-- #2. Add the tag --><!-- java code to be highlighted -->class Person {private firstName = "Vikram";private lastName = "Rawat";public String getFirstName(){return firstName;}public String getLastName(){return lastName;}}
How to use in a Custom Polymer 3 Element
In the custom element js file, please do following:
- Import the code-highlighter.js
- Add the tag to highlight the sample code.
;;<!-- #1 Get the code-highlighterjs -->static {return html`<!-- #2. Add the tag -->private void getValue(){String name = "Vikram";}`;}windowcustomElements;
Limitations
- Currently supports highlighting for Java Code snippets only.