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

ion-prism

v2.0.7

Published

Ionic directive to display code blocks in Ionic 3 apps

Downloads

6

Readme

ION PRISM DIRECTIVE GitHub top language

An Ionic directive to display blocks of code on your Ionic HTML pages, using Prism.js.

| NPM GitHub package version npm Npm downloads | Maintenance GitHub last commit Open issues | Build Status Sonar quality gate Code Climate | Greenkeeper badge Dependencies Status DevDependencies Status | | --- | :--- | :---- | :----


Installation

npm install --save ion-prism

Import Prism CSS in your Ionic Project

Ionic allows to extend or override ionic app-scripts in order. So add a task to the ionic_copy config as follows.

First, at the root of your project folder, add a folder config (if it doesn't exist) then create a copy.config.js in it with this content (or just add the task it if the file already exists):

module.exports = {
    copyPrism: {
        src: ['{{ROOT}}/node_modules/prismjs/themes/**/*'],
        dest: '{{WWW}}/assets/prismjs/themes'
    }
}

Then in your package.json, add this:

  "config": {
    "ionic_copy": "./config/copy.config.js"
  }

CSS from the Prism.js library will be copy to your output folder.

Finally, you just need to add css file in the index.html of the Ionic app:

<link href="assets/prismjs/themes/prism.css" rel="stylesheet">

Note that you may want import one of the other css files of Prismjs to change the theme as you want. (prism-coy.css, prism-dark.css, prism-funky.css, prism-okaidia.css, prism-solarizedlight.css, prism-tomorrow.css, prism-twilight.css)

Declare directive in your app

In app.module.ts, import IonPrismDirective and add it to the declarations of @NgModule as follows:

import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';

import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { IonPrismDirective } from 'ion-prism';

@NgModule({
  declarations: [
    MyApp,
    HomePage,
    IonPrismDirective
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage
  ],
  providers: [
    StatusBar,
    SplashScreen,
    {provide: ErrorHandler, useClass: IonicErrorHandler}
  ]
})
export class AppModule {}

Usage

Ion Prism directive works only on textarea element and needs a value for the language:

<textarea ion-prism="<language_type_here>">
    <your_code_to_display_here_>
</textarea>

Example

A full app as example is available here.

  <h1>Example with javascript</h1>
  <textarea ion-prism="javascript">
    var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
      var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
      if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
      else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
      return c > 3 && r && Object.defineProperty(target, key, r), r;
  };
  </textarea>

  <h1>Example with html</h1>
  <textarea ion-prism="html">
    <svg width="200" height="200" style="border:1px solid black;">
        <circle cx="20" cy="20" r="20" fill="green" />
        <circle cx="70" cy="70" r="20" fill="purple" />
        <rect x="110" y="110" height="30" width="30" fill="blue" />
        <rect x="160" y="160" height="30" width="30" fill="red" />
    </svg>
  </textarea>

Result:

Contribute

(I use commitizen, so if you wanna contribute to the project and create a pull request, please use it by running git cz instead of git commit.)

Support

If you are having issues, please let me know: [email protected]

License

The project is licensed under the GNU Affero General Public License v3.0 license