-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
194 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"printWidth": 80, | ||
"printWidth": 140, | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,7 @@ | |
Angular for syntax highlighting with highlight.js | ||
|
||
[![NPM version](https://img.shields.io/npm/v/ngx-highlight-js.svg)](https://www.npmjs.com/package/ngx-highlight-js) | ||
[![Build Status](https://travis-ci.org/cipchk/ngx-highlight-js.svg?branch=master)](https://travis-ci.org/cipchk/ngx-highlight-js) | ||
|
||
[![Ci](https://github.com/cipchk/ngx-highlight-js/workflows/Ci/badge.svg)](https://github.com/cipchk/ngx-highlight-js/actions) | ||
|
||
## Demo | ||
|
||
|
@@ -35,34 +34,81 @@ export class AppModule { | |
Load the highlight.js and theme css in page. | ||
|
||
```html | ||
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/highlight.min.js"></script> | ||
<script src="//cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/highlight.min.js"></script> | ||
``` | ||
|
||
```html | ||
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/styles/atom-one-dark.min.css"> | ||
<link rel="stylesheet" href="//cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/styles/atom-one-dark.min.css" /> | ||
``` | ||
|
||
## Only `<textarea>` Tag | ||
## Usage | ||
### Simple mode | ||
|
||
```html | ||
<textarea highlight-js [options]="{}" [lang]="'typescript'"> | ||
/* tslint:disable */ | ||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'demo', | ||
templateUrl: './demo.component.html', | ||
styleUrls: ['./demo.component.scss'] | ||
selector: 'demo', | ||
templateUrl: './demo.component.html', | ||
styleUrls: ['./demo.component.scss'] | ||
}) | ||
export class DemoComponent { | ||
switchStatus: boolean = true; | ||
switchStatus: boolean = true; | ||
} | ||
</textarea> | ||
``` | ||
|
||
**[options]** equar [configure(options)](http://highlightjs.readthedocs.io/en/latest/api.html#configure-options). (optional) | ||
### Default mode | ||
|
||
Will render each `<pre><code>`: | ||
|
||
```html | ||
<textarea highlight-js mode="default"> | ||
<p> | ||
The bare minimum for using highlight.js on a web page is linking to the library along with one of the styles and calling | ||
<a href="http://highlightjs.readthedocs.io/en/latest/api.html#inithighlightingonload"><code>initHighlightingOnLoad</code></a | ||
>: | ||
</p> | ||
<pre><code class="language-html"><link rel="stylesheet" href="/path/to/styles/default.css"> | ||
<script src="/path/to/highlight.min.js"></script> | ||
<script>hljs.initHighlightingOnLoad();</script> | ||
</code></pre> | ||
<p> | ||
This will find and highlight code inside of <code><pre><code></code> tags; it tries to detect the language automatically. If | ||
automatic detection doesn’t work for you, you can specify the language in the <code>class</code> attribute: | ||
</p> | ||
<pre><code class="language-html"><pre><code class="html">...</code></pre> | ||
</code></pre> | ||
</textarea> | ||
``` | ||
|
||
### Parameter | ||
|
||
**[lang]** uses language detection by default but you can specify the language. (optional) | ||
| Property | Description | Type | Default | Global Config | | ||
|----------|-------------|------|---------|---------------| | ||
| `[mode]` | - `default` Will render each `<pre><code>`<br>- `simple` Render all content according to `lang` language | `default, simple` | `simple` | ✅ | | ||
| `[options]` | Equar [configure(options)](http://highlightjs.readthedocs.io/en/latest/api.html#configure-options) | `any` | - | ✅ | | ||
| `[lang]` | Uses language detection by default but you can specify the language | `string` | `html` | ✅ | | ||
| `[code]` | Specify content | `string` | `html` | - | | ||
|
||
**Global Config** | ||
|
||
```ts | ||
@NgModule({ | ||
providers: [ | ||
{ | ||
provide: HIGHLIGHTJS_CONFIG, | ||
useValue: { | ||
lang: 'html' | ||
} as HighlightJsConfig | ||
} | ||
], | ||
imports: [ HighlightJsModule ], | ||
}) | ||
export class AppDemoModule {} | ||
``` | ||
|
||
## Troubleshooting | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { HighlightJsDirective } from './src/highlight-js.directive'; | ||
export * from './src/highlight-js.module'; | ||
export * from './src/highlight-js.config'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { InjectionToken } from '@angular/core'; | ||
|
||
export interface HighlightJsConfig { | ||
/** | ||
* Specify rendering mode | ||
* - `default` Will render each `<pre><code>` | ||
* - `simple` Render all content according to `lang` language | ||
*/ | ||
mode?: 'default' | 'simple'; | ||
/** | ||
* Uses language detection by default but you can specify the language | ||
*/ | ||
lang?: string; | ||
/** | ||
* Equar [configure(options)](http://highlightjs.readthedocs.io/en/latest/api.html#configure-options) | ||
*/ | ||
options?: any; | ||
} | ||
|
||
export const HIGHLIGHTJS_CONFIG = new InjectionToken<HighlightJsConfig>('HighlightJs-Config'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.