├── .editorconfig ├── .gitignore ├── README.md ├── angular.json ├── license.md ├── package-lock.json ├── package.json ├── projects ├── angular-highlight-js │ ├── README.md │ ├── karma.conf.js │ ├── ng-package.json │ ├── package.json │ ├── src │ │ ├── lib │ │ │ ├── angular-highlight-js.module.ts │ │ │ └── content │ │ │ │ ├── content.directive.spec.ts │ │ │ │ └── content.directive.ts │ │ ├── public-api.ts │ │ └── test.ts │ ├── tsconfig.lib.json │ ├── tsconfig.lib.prod.json │ ├── tsconfig.spec.json │ └── tslint.json └── demo │ ├── browserslist │ ├── e2e │ ├── protractor.conf.js │ ├── src │ │ ├── app.e2e-spec.ts │ │ └── app.po.ts │ └── tsconfig.json │ ├── karma.conf.js │ ├── src │ ├── app │ │ ├── app.component.html │ │ ├── app.component.scss │ │ ├── app.component.spec.ts │ │ ├── app.component.ts │ │ └── app.module.ts │ ├── assets │ │ └── .gitkeep │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── favicon.ico │ ├── index.html │ ├── main.ts │ ├── polyfills.ts │ ├── styles.scss │ └── test.ts │ ├── tsconfig.app.json │ ├── tsconfig.spec.json │ └── tslint.json ├── tsconfig.json └── tslint.json /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | quote_type = single 11 | 12 | [*.md] 13 | max_line_length = off 14 | trim_trailing_whitespace = false 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /tmp 5 | /out-tsc 6 | # Only exists if Bazel was run 7 | /bazel-out 8 | /dist 9 | # dependencies 10 | /node_modules 11 | 12 | # profiling files 13 | chrome-profiler-events.json 14 | speed-measure-plugin.json 15 | 16 | # IDEs and editors 17 | /.idea 18 | .project 19 | .classpath 20 | .c9/ 21 | *.launch 22 | .settings/ 23 | *.sublime-workspace 24 | 25 | # IDE - VSCode 26 | .vscode/* 27 | !.vscode/settings.json 28 | !.vscode/tasks.json 29 | !.vscode/launch.json 30 | !.vscode/extensions.json 31 | .history/* 32 | 33 | # misc 34 | /.sass-cache 35 | /connect.lock 36 | /coverage 37 | /libpeerconnection.log 38 | npm-debug.log 39 | yarn-error.log 40 | testem.log 41 | /typings 42 | 43 | # System Files 44 | .DS_Store 45 | Thumbs.db 46 | dist/angular-highlight-js/package.json 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### angular2-highlight-js 2 | 3 | [highlight.js](https://highlightjs.org) integration with Angular. 4 | 5 | #### Quick links 6 | 7 | ### Installation 8 | 9 | ```bash 10 | npm install --save angular2-highlight-js@latest highlight.js 11 | ``` 12 | 13 | ### Usage 14 | 15 | Add the highlight.js css for the style you want to use to your app's styles in **angular.json**. 16 | 17 | ```json 18 | "styles": [ 19 | "./node_modules/highlight.js/styles/monokai-sublime.css", 20 | ... 21 | ], 22 | ``` 23 | 24 | In **app.module.ts** import the highlight.js library and any languages you will be highlighting. 25 | 26 | ```typescript 27 | import { registerLanguage } from 'highlight.js'; 28 | import javascript from 'highlight.js/lib/languages/javascript'; 29 | import typescript from 'highlight.js/lib/languages/typescript'; 30 | 31 | registerLanguage('typescript', typescript); 32 | registerLanguage('javascript', javascript); 33 | ``` 34 | 35 | Import the **AngularHighlightJsModule**. 36 | 37 | ```typescript 38 | import { AngularHighlightJsModule } from 'angular2-highlight-js'; 39 | ``` 40 | 41 | ```typescript 42 | @NgModule({ 43 | declarations: [AppComponent], 44 | imports: [...AngularHighlightJsModule], 45 | providers: [], 46 | bootstrap: [AppComponent], 47 | }) 48 | export class AppModule {} 49 | ``` 50 | 51 | This library contains the **HighlightJsContentDirective** 52 | Below are usage notes for each. A demo app is also available as in the [repo](). 53 | 54 | #### For hljsContent directive 55 | 56 | Use this to highlight the contents of and element which will be set dynamically (by setting innerHTML for example). 57 | 58 | Import the directive and declare it. 59 | 60 | ```typescript 61 | 62 | @Component({ 63 | selector: 'demo', 64 | templateUrl: 'demo.component.html', 65 | styleUrls: ['demo.component.css'] 66 | }) 67 | ``` 68 | 69 | Add the attribute **hljsContent** to the element which will have content that requires highlighting. 70 | When the content is changed the directive will look for all child elements which match the selector provided and highlight them. If no selector is given it will default to finding all code elements. 71 | 72 | ```html 73 |
74 | ``` 75 | 76 | You can configure **highlight.js** by using the **[options]** property on the directive 77 | 78 | ```html 79 |
84 | ``` 85 | -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "demo": { 7 | "projectType": "application", 8 | "schematics": { 9 | "@schematics/angular:component": { 10 | "style": "scss" 11 | } 12 | }, 13 | "root": "projects/demo", 14 | "sourceRoot": "projects/demo/src", 15 | "prefix": "hljs", 16 | "architect": { 17 | "build": { 18 | "builder": "@angular-devkit/build-angular:browser", 19 | "options": { 20 | "outputPath": "dist/demo", 21 | "index": "projects/demo/src/index.html", 22 | "main": "projects/demo/src/main.ts", 23 | "polyfills": "projects/demo/src/polyfills.ts", 24 | "tsConfig": "projects/demo/tsconfig.app.json", 25 | "aot": true, 26 | "assets": [ 27 | "projects/demo/src/favicon.ico", 28 | "projects/demo/src/assets" 29 | ], 30 | "styles": [ 31 | "./node_modules/@angular/material/prebuilt-themes/indigo-pink.css", 32 | "./node_modules/highlight.js/styles/monokai-sublime.css", 33 | "projects/demo/src/styles.scss" 34 | ], 35 | "scripts": [] 36 | }, 37 | "configurations": { 38 | "production": { 39 | "fileReplacements": [ 40 | { 41 | "replace": "projects/demo/src/environments/environment.ts", 42 | "with": "projects/demo/src/environments/environment.prod.ts" 43 | } 44 | ], 45 | "optimization": true, 46 | "outputHashing": "all", 47 | "sourceMap": false, 48 | "extractCss": true, 49 | "namedChunks": false, 50 | "extractLicenses": true, 51 | "vendorChunk": false, 52 | "buildOptimizer": true, 53 | "budgets": [ 54 | { 55 | "type": "initial", 56 | "maximumWarning": "2mb", 57 | "maximumError": "5mb" 58 | }, 59 | { 60 | "type": "anyComponentStyle", 61 | "maximumWarning": "6kb" 62 | } 63 | ] 64 | } 65 | } 66 | }, 67 | "serve": { 68 | "builder": "@angular-devkit/build-angular:dev-server", 69 | "options": { 70 | "browserTarget": "demo:build" 71 | }, 72 | "configurations": { 73 | "production": { 74 | "browserTarget": "demo:build:production" 75 | } 76 | } 77 | }, 78 | "extract-i18n": { 79 | "builder": "@angular-devkit/build-angular:extract-i18n", 80 | "options": { 81 | "browserTarget": "demo:build" 82 | } 83 | }, 84 | "test": { 85 | "builder": "@angular-devkit/build-angular:karma", 86 | "options": { 87 | "main": "projects/demo/src/test.ts", 88 | "polyfills": "projects/demo/src/polyfills.ts", 89 | "tsConfig": "projects/demo/tsconfig.spec.json", 90 | "karmaConfig": "projects/demo/karma.conf.js", 91 | "assets": [ 92 | "projects/demo/src/favicon.ico", 93 | "projects/demo/src/assets" 94 | ], 95 | "styles": [ 96 | "./node_modules/@angular/material/prebuilt-themes/indigo-pink.css", 97 | "projects/demo/src/styles.scss" 98 | ], 99 | "scripts": [] 100 | } 101 | }, 102 | "lint": { 103 | "builder": "@angular-devkit/build-angular:tslint", 104 | "options": { 105 | "tsConfig": [ 106 | "projects/demo/tsconfig.app.json", 107 | "projects/demo/tsconfig.spec.json", 108 | "projects/demo/e2e/tsconfig.json" 109 | ], 110 | "exclude": ["**/node_modules/**"] 111 | } 112 | }, 113 | "e2e": { 114 | "builder": "@angular-devkit/build-angular:protractor", 115 | "options": { 116 | "protractorConfig": "projects/demo/e2e/protractor.conf.js", 117 | "devServerTarget": "demo:serve" 118 | }, 119 | "configurations": { 120 | "production": { 121 | "devServerTarget": "demo:serve:production" 122 | } 123 | } 124 | } 125 | } 126 | }, 127 | "angular-highlight-js": { 128 | "projectType": "library", 129 | "root": "projects/angular-highlight-js", 130 | "sourceRoot": "projects/angular-highlight-js/src", 131 | "prefix": "hljs", 132 | "architect": { 133 | "build": { 134 | "builder": "@angular-devkit/build-angular:ng-packagr", 135 | "options": { 136 | "tsConfig": "projects/angular-highlight-js/tsconfig.lib.json", 137 | "project": "projects/angular-highlight-js/ng-package.json" 138 | }, 139 | "configurations": { 140 | "production": { 141 | "tsConfig": "projects/angular-highlight-js/tsconfig.lib.prod.json" 142 | } 143 | } 144 | }, 145 | "test": { 146 | "builder": "@angular-devkit/build-angular:karma", 147 | "options": { 148 | "main": "projects/angular-highlight-js/src/test.ts", 149 | "tsConfig": "projects/angular-highlight-js/tsconfig.spec.json", 150 | "karmaConfig": "projects/angular-highlight-js/karma.conf.js" 151 | } 152 | }, 153 | "lint": { 154 | "builder": "@angular-devkit/build-angular:tslint", 155 | "options": { 156 | "tsConfig": [ 157 | "projects/angular-highlight-js/tsconfig.lib.json", 158 | "projects/angular-highlight-js/tsconfig.spec.json" 159 | ], 160 | "exclude": ["**/node_modules/**"] 161 | } 162 | } 163 | } 164 | } 165 | }, 166 | "defaultProject": "demo", 167 | "cli": { 168 | "analytics": "4794b35f-6b24-4381-8cd3-17bcb2a3ec9b" 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /license.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2019 Useful Software Solutions Ltd 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular2-highlight-js", 3 | "version": "9.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build angular-highlight-js && ng build demo", 8 | "copy-files": "copy README.md dist\\angular-highlight-js && copy license.md dist\\angular-highlight-js", 9 | "pack": "cd dist/angular-highlight-js && npm pack", 10 | "prep-lib": "npm run build && npm run copy-files && npm run pack", 11 | "test": "ng test", 12 | "lint": "ng lint", 13 | "e2e": "ng e2e" 14 | }, 15 | "keywords": [ 16 | "Angular", 17 | "highlight.js", 18 | "code snippet", 19 | "code formatting" 20 | ], 21 | "author": { 22 | "name": "Jay Chase", 23 | "email": "JonathanChase@outlook.com", 24 | "url": "https://www.usefuldev.com/home" 25 | }, 26 | "bugs": { 27 | "url": "https://github.com/jaychase/angular2-highlight-js/issues" 28 | }, 29 | "repository": { 30 | "type": "git", 31 | "url": "https://github.com/jaychase/angular2-highlight-js.git" 32 | }, 33 | "license": "MIT", 34 | "dependencies": { 35 | "@angular/animations": "~11.0.2", 36 | "@angular/cdk": "~11.0.1", 37 | "@angular/common": "~11.0.2", 38 | "@angular/compiler": "~11.0.2", 39 | "@angular/core": "~11.0.2", 40 | "@angular/forms": "~11.0.2", 41 | "@angular/material": "^11.0.1", 42 | "@angular/platform-browser": "~11.0.2", 43 | "@angular/platform-browser-dynamic": "~11.0.2", 44 | "@angular/router": "~11.0.2", 45 | "highlight.js": "^10.4.0", 46 | "rxjs": "~6.6.3", 47 | "tslib": "^2.0.0", 48 | "zone.js": "~0.10.2" 49 | }, 50 | "devDependencies": { 51 | "@angular-devkit/build-angular": "^0.1100.2", 52 | "@angular/cli": "~11.0.2", 53 | "@angular/compiler-cli": "~11.0.2", 54 | "@angular/language-service": "~11.0.2", 55 | "@types/jasmine": "~3.3.8", 56 | "@types/jasminewd2": "~2.0.3", 57 | "@types/node": "^12.11.1", 58 | "codelyzer": "^5.1.2", 59 | "jasmine-core": "~3.4.0", 60 | "jasmine-spec-reporter": "~4.2.1", 61 | "karma": "~5.1.1", 62 | "karma-chrome-launcher": "~2.2.0", 63 | "karma-coverage-istanbul-reporter": "~2.0.1", 64 | "karma-jasmine": "~2.0.1", 65 | "karma-jasmine-html-reporter": "^1.4.0", 66 | "ng-packagr": "^11.0.2", 67 | "protractor": "~7.0.0", 68 | "ts-node": "~7.0.0", 69 | "tslint": "~6.1.3", 70 | "typescript": "~4.0.5" 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /projects/angular-highlight-js/README.md: -------------------------------------------------------------------------------- 1 | ### angular2-highlight-js 2 | 3 | [highlight.js](https://highlightjs.org) integration with Angular. 4 | 5 | #### Quick links 6 | 7 | ### Installation 8 | 9 | ```bash 10 | npm install --save angular2-highlight-js@latest highlight.js 11 | ``` 12 | 13 | ### Usage 14 | 15 | Add the highlight.js css for the style you want to use to your app's styles in **angular.json**. 16 | 17 | ```json 18 | "styles": [ 19 | "./node_modules/highlight.js/styles/monokai-sublime.css", 20 | ... 21 | ], 22 | ``` 23 | 24 | In **app.module.ts** import the highlight.js library and any languages you will be highlighting. 25 | 26 | ```typescript 27 | import hljs from 'highlight.js/lib/highlight'; 28 | import javascript from 'highlight.js/lib/languages/javascript'; 29 | import typescript from 'highlight.js/lib/languages/typescript'; 30 | 31 | hljs.registerLanguage('typescript', typescript); 32 | hljs.registerLanguage('javascript', javascript); 33 | ``` 34 | 35 | Import the **AngularHighlightJsModule**. 36 | 37 | ```typescript 38 | import { AngularHighlightJsModule } from 'angular2-highlight-js'; 39 | ``` 40 | 41 | ```typescript 42 | @NgModule({ 43 | declarations: [AppComponent], 44 | imports: [...AngularHighlightJsModule], 45 | providers: [], 46 | bootstrap: [AppComponent] 47 | }) 48 | export class AppModule {} 49 | ``` 50 | 51 | This library contains the **HighlightJsContentDirective** 52 | Below are usage notes for each. A demo app is also available as in the [repo](). 53 | 54 | #### For hljsContent directive 55 | 56 | Use this to highlight the contents of and element which will be set dynamically (by setting innerHTML for example). 57 | 58 | Import the directive and declare it. 59 | 60 | ```typescript 61 | 62 | @Component({ 63 | selector: 'demo', 64 | templateUrl: 'demo.component.html', 65 | styleUrls: ['demo.component.css'] 66 | }) 67 | ``` 68 | 69 | Add the attribute **hljsContent** to the element which will have content that requires highlighting. 70 | When the content is changed the directive will look for all child elements which match the selector provided and highlight them. If no selector is given it will default to finding all code elements. 71 | 72 | ```html 73 |
74 | ``` 75 | 76 | You can configure **highlight.js** by using the **[options]** property on the directive 77 | 78 | ```html 79 |
84 | ``` 85 | -------------------------------------------------------------------------------- /projects/angular-highlight-js/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, '../../coverage/angular-highlight-js'), 20 | reports: ['html', 'lcovonly'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false, 30 | restartOnFileChange: true 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /projects/angular-highlight-js/ng-package.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "../../node_modules/ng-packagr/ng-package.schema.json", 3 | "dest": "../../dist/angular-highlight-js", 4 | "lib": { 5 | "entryFile": "src/public-api.ts", 6 | "umdModuleIds": { 7 | "highlight.js": "highlight.js" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /projects/angular-highlight-js/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular2-highlight-js", 3 | "version": "9.0.0", 4 | "keywords": [ 5 | "Angular", 6 | "highlight.js", 7 | "code snippet", 8 | "code formatting" 9 | ], 10 | "license": "MIT", 11 | "author": { 12 | "name": "Jay Chase", 13 | "email": "JonathanChase@outlook.com", 14 | "url": "https://www.usefuldev.com/home" 15 | }, 16 | "bugs": { 17 | "url": "https://github.com/jaychase/angular2-highlight-js/issues" 18 | }, 19 | "repository": { 20 | "type": "git", 21 | "url": "https://github.com/jaychase/angular2-highlight-js.git" 22 | }, 23 | "peerDependencies": { 24 | "@angular/common": ">=10.0.0", 25 | "@angular/core": ">=10.0.0", 26 | "highlight.js": ">=10.4.0" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /projects/angular-highlight-js/src/lib/angular-highlight-js.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { ContentDirective } from './content/content.directive'; 3 | 4 | @NgModule({ 5 | declarations: [ContentDirective], 6 | imports: [], 7 | exports: [ContentDirective] 8 | }) 9 | export class AngularHighlightJsModule {} 10 | -------------------------------------------------------------------------------- /projects/angular-highlight-js/src/lib/content/content.directive.spec.ts: -------------------------------------------------------------------------------- 1 | import { ContentDirective } from './content.directive'; 2 | 3 | describe('ContentDirective', () => { 4 | it('should create an instance', () => { 5 | const directive = new ContentDirective(); 6 | expect(directive).toBeTruthy(); 7 | }); 8 | }); 9 | -------------------------------------------------------------------------------- /projects/angular-highlight-js/src/lib/content/content.directive.ts: -------------------------------------------------------------------------------- 1 | import { 2 | AfterViewChecked, 3 | Directive, 4 | ElementRef, 5 | Input, 6 | NgZone, 7 | OnChanges, 8 | SimpleChanges, 9 | } from '@angular/core'; 10 | import { configure, highlightBlock } from 'highlight.js'; 11 | // import hljs from 'highlight.js/lib/highlight'; 12 | 13 | @Directive({ 14 | selector: '[hljsContent]', 15 | }) 16 | export class ContentDirective implements OnChanges, AfterViewChecked { 17 | @Input() options: HLJSOptions; 18 | @Input('hljsContent') highlightSelector: string; 19 | private done = false; 20 | 21 | constructor(private elementRef: ElementRef, private zone: NgZone) {} 22 | 23 | ngOnChanges(simpleChanges: SimpleChanges) { 24 | // tslint:disable-next-line: no-string-literal 25 | if (simpleChanges['options'] && this.options) { 26 | configure(this.options); 27 | } 28 | } 29 | 30 | ngAfterViewChecked() { 31 | if (!this.done) { 32 | const selector = this.highlightSelector || 'code'; 33 | 34 | if ( 35 | this.elementRef.nativeElement.innerHTML && 36 | this.elementRef.nativeElement.querySelector 37 | ) { 38 | const snippets = this.elementRef.nativeElement.querySelectorAll( 39 | selector 40 | ); 41 | this.zone.runOutsideAngular(() => { 42 | for (const snippet of snippets) { 43 | highlightBlock(snippet); 44 | } 45 | }); 46 | 47 | this.done = true; 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /projects/angular-highlight-js/src/public-api.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Public API Surface of angular-highlight-js 3 | */ 4 | 5 | export * from './lib/angular-highlight-js.module'; 6 | export * from './lib/content/content.directive'; 7 | -------------------------------------------------------------------------------- /projects/angular-highlight-js/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone'; 4 | import 'zone.js/dist/zone-testing'; 5 | import { getTestBed } from '@angular/core/testing'; 6 | import { 7 | BrowserDynamicTestingModule, 8 | platformBrowserDynamicTesting 9 | } from '@angular/platform-browser-dynamic/testing'; 10 | 11 | declare const require: any; 12 | 13 | // First, initialize the Angular testing environment. 14 | getTestBed().initTestEnvironment( 15 | BrowserDynamicTestingModule, 16 | platformBrowserDynamicTesting() 17 | ); 18 | // Then we find all the tests. 19 | const context = require.context('./', true, /\.spec\.ts$/); 20 | // And load the modules. 21 | context.keys().map(context); 22 | -------------------------------------------------------------------------------- /projects/angular-highlight-js/tsconfig.lib.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../../out-tsc/lib", 5 | "target": "es2015", 6 | "declaration": true, 7 | "inlineSources": true, 8 | "types": ["highlight.js"], 9 | "lib": ["dom", "es2018"] 10 | }, 11 | "angularCompilerOptions": { 12 | "skipTemplateCodegen": true, 13 | "strictMetadataEmit": true, 14 | "fullTemplateTypeCheck": true, 15 | "strictInjectionParameters": true, 16 | "enableResourceInlining": true 17 | }, 18 | "exclude": ["src/test.ts", "**/*.spec.ts"] 19 | } 20 | -------------------------------------------------------------------------------- /projects/angular-highlight-js/tsconfig.lib.prod.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.lib.json", 3 | "angularCompilerOptions": { 4 | "enableIvy": false 5 | } 6 | } -------------------------------------------------------------------------------- /projects/angular-highlight-js/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../../out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts" 12 | ], 13 | "include": [ 14 | "**/*.spec.ts", 15 | "**/*.d.ts" 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /projects/angular-highlight-js/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tslint.json", 3 | "rules": { 4 | "directive-selector": [true, "attribute", "hljs", "camelCase"], 5 | "component-selector": [true, "element", "hljs", "kebab-case"] 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /projects/demo/browserslist: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # You can see what browsers were selected by your queries by running: 6 | # npx browserslist 7 | 8 | > 0.5% 9 | last 2 versions 10 | Firefox ESR 11 | not dead 12 | not IE 9-11 # For IE 9-11 support, remove 'not'. -------------------------------------------------------------------------------- /projects/demo/e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | // Protractor configuration file, see link for more information 3 | // https://github.com/angular/protractor/blob/master/lib/config.ts 4 | 5 | const { SpecReporter } = require('jasmine-spec-reporter'); 6 | 7 | /** 8 | * @type { import("protractor").Config } 9 | */ 10 | exports.config = { 11 | allScriptsTimeout: 11000, 12 | specs: [ 13 | './src/**/*.e2e-spec.ts' 14 | ], 15 | capabilities: { 16 | 'browserName': 'chrome' 17 | }, 18 | directConnect: true, 19 | baseUrl: 'http://localhost:4200/', 20 | framework: 'jasmine', 21 | jasmineNodeOpts: { 22 | showColors: true, 23 | defaultTimeoutInterval: 30000, 24 | print: function() {} 25 | }, 26 | onPrepare() { 27 | require('ts-node').register({ 28 | project: require('path').join(__dirname, './tsconfig.json') 29 | }); 30 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 31 | } 32 | }; -------------------------------------------------------------------------------- /projects/demo/e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | import { browser, logging } from 'protractor'; 3 | 4 | describe('workspace-project App', () => { 5 | let page: AppPage; 6 | 7 | beforeEach(() => { 8 | page = new AppPage(); 9 | }); 10 | 11 | it('should display welcome message', () => { 12 | page.navigateTo(); 13 | expect(page.getTitleText()).toEqual('Welcome to demo!'); 14 | }); 15 | 16 | afterEach(async () => { 17 | // Assert that there are no errors emitted from the browser 18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER); 19 | expect(logs).not.toContain(jasmine.objectContaining({ 20 | level: logging.Level.SEVERE, 21 | } as logging.Entry)); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /projects/demo/e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get(browser.baseUrl) as Promise; 6 | } 7 | 8 | getTitleText() { 9 | return element(by.css('app-root h1')).getText() as Promise; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /projects/demo/e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../../../out-tsc/e2e", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /projects/demo/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, '../../coverage/demo'), 20 | reports: ['html', 'lcovonly', 'text-summary'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false, 30 | restartOnFileChange: true 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /projects/demo/src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | Overview 3 | 4 | For full instructions on click 5 | here. To find out more about highlight.js can be found 10 | here 11 | 12 | 13 | 14 | Using the HighlightJsContent directive 15 | 16 |

17 | Use this directive to handle dynamic content which contains snippets. Both 18 | the sections below have innerHTML bound to the the sampleContent property. 19 |

20 |

Raw pre code without highlighting

21 |
22 |

Add dynamic content and highlight it

23 |
28 |
29 | 30 | 39 | 40 |
41 | -------------------------------------------------------------------------------- /projects/demo/src/app/app.component.scss: -------------------------------------------------------------------------------- 1 | mat-card { 2 | margin: 12px; 3 | } 4 | -------------------------------------------------------------------------------- /projects/demo/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from '@angular/core/testing'; 2 | import { AppComponent } from './app.component'; 3 | 4 | describe('AppComponent', () => { 5 | beforeEach(async(() => { 6 | TestBed.configureTestingModule({ 7 | declarations: [ 8 | AppComponent 9 | ], 10 | }).compileComponents(); 11 | })); 12 | 13 | it('should create the app', () => { 14 | const fixture = TestBed.createComponent(AppComponent); 15 | const app = fixture.debugElement.componentInstance; 16 | expect(app).toBeTruthy(); 17 | }); 18 | 19 | it(`should have as title 'demo'`, () => { 20 | const fixture = TestBed.createComponent(AppComponent); 21 | const app = fixture.debugElement.componentInstance; 22 | expect(app.title).toEqual('demo'); 23 | }); 24 | 25 | it('should render title in a h1 tag', () => { 26 | const fixture = TestBed.createComponent(AppComponent); 27 | fixture.detectChanges(); 28 | const compiled = fixture.debugElement.nativeElement; 29 | expect(compiled.querySelector('h1').textContent).toContain('Welcome to demo!'); 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /projects/demo/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-root', 5 | templateUrl: './app.component.html', 6 | styleUrls: ['./app.component.scss'] 7 | }) 8 | export class AppComponent { 9 | sampleContent = ` 10 |
11 |      
12 |          class Greeter {
13 |              constructor(public greeting: string) { }
14 |              greet() {
15 |                  return "hello world";
16 |              }
17 |          };
18 |      
19 |  
20 |
21 |      
22 |          alert('Hello, World!');
23 |      
24 |  
25 | `; 26 | 27 | dynamicContent: string; 28 | 29 | addContent() { 30 | this.dynamicContent = this.sampleContent; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /projects/demo/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { MatButtonModule } from '@angular/material/button'; 3 | import { MatCardModule } from '@angular/material/card'; 4 | import { BrowserModule } from '@angular/platform-browser'; 5 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 6 | import { AngularHighlightJsModule } from 'angular-highlight-js'; 7 | import { registerLanguage } from 'highlight.js'; 8 | import javascript from 'highlight.js/lib/languages/javascript'; 9 | import typescript from 'highlight.js/lib/languages/typescript'; 10 | import { AppComponent } from './app.component'; 11 | 12 | registerLanguage('typescript', typescript); 13 | registerLanguage('javascript', javascript); 14 | 15 | @NgModule({ 16 | declarations: [AppComponent], 17 | imports: [ 18 | BrowserModule, 19 | BrowserAnimationsModule, 20 | MatCardModule, 21 | MatButtonModule, 22 | AngularHighlightJsModule, 23 | ], 24 | providers: [], 25 | bootstrap: [AppComponent], 26 | }) 27 | export class AppModule {} 28 | -------------------------------------------------------------------------------- /projects/demo/src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JayChase/angular2-highlight-js/308564f10bdf097cef7e3974174c188d7d82f5c4/projects/demo/src/assets/.gitkeep -------------------------------------------------------------------------------- /projects/demo/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /projects/demo/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /projects/demo/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JayChase/angular2-highlight-js/308564f10bdf097cef7e3974174c188d7d82f5c4/projects/demo/src/favicon.ico -------------------------------------------------------------------------------- /projects/demo/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Demo 6 | 7 | 8 | 9 | 10 | 14 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /projects/demo/src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.error(err)); 13 | -------------------------------------------------------------------------------- /projects/demo/src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 22 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 23 | 24 | /** 25 | * Web Animations `@angular/platform-browser/animations` 26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 28 | */ 29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 30 | 31 | /** 32 | * By default, zone.js will patch all possible macroTask and DomEvents 33 | * user can disable parts of macroTask/DomEvents patch by setting following flags 34 | * because those flags need to be set before `zone.js` being loaded, and webpack 35 | * will put import in the top of bundle, so user need to create a separate file 36 | * in this directory (for example: zone-flags.ts), and put the following flags 37 | * into that file, and then add the following code before importing zone.js. 38 | * import './zone-flags.ts'; 39 | * 40 | * The flags allowed in zone-flags.ts are listed here. 41 | * 42 | * The following flags will work for all browsers. 43 | * 44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 47 | * 48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 50 | * 51 | * (window as any).__Zone_enable_cross_context_check = true; 52 | * 53 | */ 54 | 55 | /*************************************************************************************************** 56 | * Zone JS is required by default for Angular itself. 57 | */ 58 | import 'zone.js/dist/zone'; // Included with Angular CLI. 59 | 60 | 61 | /*************************************************************************************************** 62 | * APPLICATION IMPORTS 63 | */ 64 | -------------------------------------------------------------------------------- /projects/demo/src/styles.scss: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | 3 | html, body { height: 100%; } 4 | body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; } 5 | -------------------------------------------------------------------------------- /projects/demo/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: any; 11 | 12 | // First, initialize the Angular testing environment. 13 | getTestBed().initTestEnvironment( 14 | BrowserDynamicTestingModule, 15 | platformBrowserDynamicTesting() 16 | ); 17 | // Then we find all the tests. 18 | const context = require.context('./', true, /\.spec\.ts$/); 19 | // And load the modules. 20 | context.keys().map(context); 21 | -------------------------------------------------------------------------------- /projects/demo/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../../out-tsc/app", 5 | "types": [] 6 | }, 7 | "include": [ 8 | "src/**/*.d.ts" 9 | ], 10 | "files": [ 11 | "src/main.ts", 12 | "src/polyfills.ts" 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /projects/demo/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../../out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts", 12 | "src/polyfills.ts" 13 | ], 14 | "include": [ 15 | "src/**/*.spec.ts", 16 | "src/**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /projects/demo/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tslint.json", 3 | "rules": { 4 | "directive-selector": [true, "attribute", "app", "camelCase"], 5 | "component-selector": [true, "element", "app", "kebab-case"] 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "downlevelIteration": true, 9 | "emitDecoratorMetadata": true, 10 | "experimentalDecorators": true, 11 | "module": "esnext", 12 | "moduleResolution": "node", 13 | "importHelpers": true, 14 | "target": "es2015", 15 | "typeRoots": ["node_modules/@types"], 16 | "lib": ["es2018", "dom"], 17 | "paths": { 18 | "angular-highlight-js": [ 19 | "projects/angular-highlight-js/src/public-api.ts" 20 | ], 21 | "angular-highlight-js/*": ["dist/angular-highlight-js/*"] 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rulesDirectory": ["codelyzer"], 4 | "rules": { 5 | "align": { 6 | "options": ["parameters", "statements"] 7 | }, 8 | "array-type": false, 9 | "arrow-parens": false, 10 | "arrow-return-shorthand": true, 11 | "curly": true, 12 | "deprecation": { 13 | "severity": "warning" 14 | }, 15 | "eofline": true, 16 | "import-blacklist": [true, "rxjs/Rx"], 17 | "import-spacing": true, 18 | "indent": { 19 | "options": ["spaces"] 20 | }, 21 | "interface-name": false, 22 | "max-classes-per-file": false, 23 | "max-line-length": [true, 140], 24 | "member-access": false, 25 | "member-ordering": [ 26 | true, 27 | { 28 | "order": [ 29 | "static-field", 30 | "instance-field", 31 | "static-method", 32 | "instance-method" 33 | ] 34 | } 35 | ], 36 | "no-consecutive-blank-lines": false, 37 | "no-console": [true, "debug", "info", "time", "timeEnd", "trace"], 38 | "no-empty": false, 39 | "no-inferrable-types": [true, "ignore-params"], 40 | "no-non-null-assertion": true, 41 | "no-redundant-jsdoc": true, 42 | "no-switch-case-fall-through": true, 43 | "no-var-requires": false, 44 | "object-literal-key-quotes": [true, "as-needed"], 45 | "object-literal-sort-keys": false, 46 | "ordered-imports": false, 47 | "quotemark": [true, "single"], 48 | "semicolon": { 49 | "options": ["always"] 50 | }, 51 | "space-before-function-paren": { 52 | "options": { 53 | "anonymous": "never", 54 | "asyncArrow": "always", 55 | "constructor": "never", 56 | "method": "never", 57 | "named": "never" 58 | } 59 | }, 60 | "trailing-comma": false, 61 | "component-class-suffix": true, 62 | "contextual-lifecycle": true, 63 | "directive-class-suffix": true, 64 | "no-conflicting-lifecycle": true, 65 | "no-host-metadata-property": true, 66 | "no-input-rename": true, 67 | "no-inputs-metadata-property": true, 68 | "no-output-native": true, 69 | "no-output-on-prefix": true, 70 | "no-output-rename": true, 71 | "no-outputs-metadata-property": true, 72 | "template-banana-in-box": true, 73 | "template-no-negated-async": true, 74 | "typedef-whitespace": { 75 | "options": [ 76 | { 77 | "call-signature": "nospace", 78 | "index-signature": "nospace", 79 | "parameter": "nospace", 80 | "property-declaration": "nospace", 81 | "variable-declaration": "nospace" 82 | }, 83 | { 84 | "call-signature": "onespace", 85 | "index-signature": "onespace", 86 | "parameter": "onespace", 87 | "property-declaration": "onespace", 88 | "variable-declaration": "onespace" 89 | } 90 | ] 91 | }, 92 | "use-lifecycle-interface": true, 93 | "use-pipe-transform-interface": true, 94 | "variable-name": { 95 | "options": ["ban-keywords", "check-format", "allow-pascal-case"] 96 | }, 97 | "whitespace": { 98 | "options": [ 99 | "check-branch", 100 | "check-decl", 101 | "check-operator", 102 | "check-separator", 103 | "check-type", 104 | "check-typecast" 105 | ] 106 | } 107 | } 108 | } 109 | --------------------------------------------------------------------------------