@smartcodelab/ngx-prettify
v0.0.6
Published
> This is Angular (version 6+) Service providing utility of Code Formating. > This uses the core "pretty" Javascript Module for formatting HTML Code; > Currently this library supports only HTML, Javascript and CSS code; > > Dependencies : npm modules pr
Downloads
139
Readme
@smartcodelab/ngx-prettify
This is Angular (version 6+) Service providing utility of Code Formating. This uses the core "pretty" Javascript Module for formatting HTML Code; Currently this library supports only HTML, Javascript and CSS code;
Dependencies : npm modules pretty and js-beautify
Installation
Install pretty and @smartcodelab/ngx-prettify library. Use Below commands:
$ npm install pretty js-beautify @smartcodelab/ngx-prettify --save
or
$ yarn add pretty js-beautify @smartcodelab/ngx-prettify
Consuming @smartcodelab/ngx-prettify library
The Service is created with providedIn set to 'root' by default; So only installation of NPM Module is only required. So not necessary to add to any Module >imports explicitly in the NgModule.
In .ts file
import { Component } from '@angular/core';
import { NgxPrettifyService } from '@smartcodelab/ngx-prettify';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
code = `
<!DOCTYPE html><title>Title</title><style>body {width: 500px;}</style>
<script type="application/javascript">function $init() {return true;}</script>
<body><p checked class="title" id='title'>Title</p>
<!-- here goes the rest of the page --></body>`;
constructor( public prettifier: NgxPrettifyService) {
// Below Code prettifies html code content in 'code' variable.
this.code = this.prettifier.prettify(this.code);
}
}
License
MIT