Security News
npm Updates Search Experience with New Objective Sorting Options
npm has a revamped search experience with new, more transparent sorting options—Relevance, Downloads, Dependents, and Publish Date.
ngx-highlightjs
Advanced tools
Instant code highlighting, auto-detect language, super easy to use
$ npm install --save ngx-highlightjs
Head to highlight.js download page and get your custom package bundle including only the languages you need.
Create new folder in src/assets/lib/hljs
and extract the downloaded zip file there.
Import HighlightModule
library from any module:
import { HighlightModule } from 'ngx-highlightjs';
@NgModule({
imports: [
// ...
HighlightModule.forRoot()
]
})
export class AppModule { }
The function forRoot accepts 1 optional parameters, forRoot(options?: HighlightOptions)
With options
parameter you can set:
'github'
'assets/lib/hljs'
true
Choose highlighting theme:
HighlightModule.forRoot({ theme: 'agate'});
List of all available themes from highlight.js
Import highlight.js library from a custom path
const options: HighlightOptions = {
theme: 'agate',
path: 'assets/js/highlight-js'
};
HighlightModule.forRoot(options);
Now you can use the directive highlight
, you can:
<!-- Highlight target element -->
<pre><code highlight [code]="someCode"></code></pre>
<!-- Or -->
<pre><code highlight [textContent]="someCode"></code></pre>
<!-- Highlight child elements of type <pre><code> -->
<div highlight="all">
<pre><code [textContent]="htmlCode"></code></pre>
<pre><code [textContent]="tsCode"></code></pre>
<pre><code [textContent]="cssCode"></code></pre>
</div>
<!-- Highlight custom child elements -->
<div highlight="section code">
<section><code [textContent]="pythonCode"></code></section>
<section><code [textContent]="swiftCode"></code></section>
</div>
[highlight]: string, default ''
highlight
on the element to highlight it.highlight="all"
to highlight all child code elements.highlight="{selector}"
to highlight custom child elements.[code]: string, default null
(highlighted): Stream that emits highlight result
This project uses ng-packagr for development.
Use the following command to build
$ npm run packagr
If you identify any errors in the library, or have an idea for an improvement, please open an issue.
FAQs
Instant code highlighting, auto-detect language, super easy to use.
We found that ngx-highlightjs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm has a revamped search experience with new, more transparent sorting options—Relevance, Downloads, Dependents, and Publish Date.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.