npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

as-prism

v4.0.2

Published

Angular Code Highlighter

Downloads

323

Readme

Install

npm install as-prism --save

prismjs package is a required dependency

npm install prismjs --save

Setup

#1. Add AsPrismModule to app NgModule

import { CommonModule } from "@angular/common";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";

import { AsPrismModule } from "as-prism";

@NgModule({
  imports: [
    CommonModule,
    BrowserAnimationsModule,
    AsPrismModule, // AsPrismModule added
  ],
  bootstrap: [App],
  declarations: [App],
})
class MainModule {}

#2. Add prism theme css in styles.css or styles.scss or styles.less file

/* Prismjs theme */
@import "prismjs/themes/prism.css";

INFO: Prism available theme

/* Available themes */
@import "prismjs/themes/prism-coy.css";
@import "prismjs/themes/prism-dark.css";
@import "prismjs/themes/prism-funky.css";
@import "prismjs/themes/prism-okaidia.css";
@import "prismjs/themes/prism-solarizedlight.css";
@import "prismjs/themes/prism-tomorrow.css";
@import "prismjs/themes/prism-twilight.css";

#3. Optional: import language.

If you have highlighter use case all over the application. than it's better to import languages in the root component like app.component.ts file

// language import
import 'prismjs/components/prism-yaml';
import 'prismjs/components/prism-json';
import 'prismjs/components/prism-scss';
import 'prismjs/components/prism-typescript';


@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  ...
}

Use

#1. Data

Note*: if your import language in app.component.ts then you don't need to import language in particular file.

import { Component } from '@angular/core';

// Input languages that you are using. Note: HTML language code default imported
import 'prismjs/components/prism-yaml';
import 'prismjs/components/prism-json';
// import 'prismjs/components/prism-scss';
// import 'prismjs/components/prism-typescript';

@Component({...})
export class YourComponent {
  html_language: string = "html"
  html_code: string = `
  <h2>THis is simple html code</h2>
  <p><strong>Lorem Ipsum</strong> is simply dummy text of the printing and typesetting industry</p>
  <h3>This is simple heading text</h3>
  <p>Dummy text ever since the <strong>1500s</strong>, when an unknown printer took a galley of type and scrambled</p>`

  yaml_code: string = `
  - required_engine_version: 8

  - list: "allowed_dev_files"
    items:
    - "/dev/null"
    append: true

  - list: "allowed_image"
    items:
    - "techincent-ci"
    append: true

  - rule: "Accept VPC Peering Connection"
    tags:
    - "cloud"
    source: "aws_cloudtrail"`

  json_code: string = `{
    "kind": "Deployment",
    "apiVersion": "apps/v1",
    "metadata": {
      "name": "ti-dashboard",
      "namespace": "techincent",
    },
    "spec": {
      "replicas": 1,
      "selector": {
        "matchLabels": {
          "app": "techincent-dashboard",
          "role": "techincent"
        }
      }
    }
  }`
}

#2. Render as-prism element in html

<h2>HTML Code Example</h2>
<as-prism [code]="html_code" [language]="html_language"></as-prism>

<h2>YAML Code Example</h2>
<as-prism [code]="yaml_code" language="yaml"></as-prism>

<h2>JSON Code Example</h2>
<as-prism [code]="json_code" language="json"></as-prism>

Experimental Render with directive

Note: Directive is available for Experimental

<pre asPrism="json">
  <code>
    {{directive_json_code}}
  </code>
</pre>

<pre asPrism="html">
  <code>
    {{html_code}}
  </code>
</pre>

INFO: Checkout available languages support [https://prismjs.com/#supported-languages]


License

MIT

Change Log

  • 4.0.2 -> (asPrism="language") directive base render on Expermental api available, as-prism component switch to none encapsulation
  • 2.2.0 -> (asPrism="language") directive base highlighter, Note: developmentApi (it's testing)

Major Change Log

  • 0.x.x -> Support Angular 14.x.x
  • 1.x.x -> Support Angular Version 15.x.x
  • 2.x.x -> Support Angular Version 16.x.x
  • 2.3.x -> Support Angular Version >= 16.x.x
  • 3.x.x -> Support Angular Version >= 17.x.x
  • 4.x.x -> Support Angular Version >= 18.x.x