Skip to content

Commit a726c3c

Browse files
author
Zhicheng WANG
committed
separate from main project
0 parents  commit a726c3c

13 files changed

+247
-0
lines changed

karma.conf.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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'),
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+
});
31+
};

ng-package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
3+
"dest": "../../../dist/ui-model/angular-markdown",
4+
"lib": {
5+
"entryFile": "src/public_api.ts"
6+
}
7+
}

package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "@ui-model/angular-markdown",
3+
"version": "0.2.1",
4+
"main": "src/public_api.ts",
5+
"devDependencies": {
6+
"@types/highlight.js": "^9.1.9",
7+
"@types/markdown-it": "0.0.2"
8+
},
9+
"peerDependencies": {
10+
"@angular/common": "^6.0.0 || ^7.0.0 || ^8.0.0",
11+
"@angular/core": "^6.0.0 || ^7.0.0 || ^8.0.0",
12+
"@ui-model/angular": "0.2.1",
13+
"highlight.js": "^9.10.0",
14+
"markdown-it": "^8.3.1",
15+
"markdown-it-abbr": "^1.0.4",
16+
"markdown-it-deflist": "^2.0.1",
17+
"markdown-it-emoji": "^1.3.0",
18+
"markdown-it-footnote": "^3.0.1",
19+
"markdown-it-ins": "^2.0.0",
20+
"markdown-it-mark": "^2.0.0",
21+
"markdown-it-sub": "^1.0.0",
22+
"markdown-it-sup": "^1.0.0",
23+
"markdown-it-table-of-contents": "^0.3.2"
24+
}
25+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { HighlightPipe } from './highlight.pipe';
2+
3+
describe('HighlightPipe', () => {
4+
it('create an instance', () => {
5+
const pipe = new HighlightPipe();
6+
expect(pipe).toBeTruthy();
7+
});
8+
});

src/lib/pipes/highlight.pipe.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Pipe, PipeTransform } from '@angular/core';
2+
import { highlightAuto } from 'highlight.js';
3+
4+
const defaultLanguages = ['ts', 'js', 'html', 'scss', 'css'];
5+
6+
@Pipe({
7+
name: 'highlight',
8+
})
9+
export class HighlightPipe implements PipeTransform {
10+
transform(value: string, language: string = 'ts'): string {
11+
if (!value) {
12+
return;
13+
}
14+
return highlightAuto(value, [language].concat(defaultLanguages)).value;
15+
}
16+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { MarkdownPipe } from './markdown.pipe';
2+
3+
describe('MarkdownPipe', () => {
4+
it('create an instance', () => {
5+
const pipe = new MarkdownPipe();
6+
expect(pipe).toBeTruthy();
7+
});
8+
});

src/lib/pipes/markdown.pipe.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { Pipe, PipeTransform } from '@angular/core';
2+
import * as hljs from 'highlight.js';
3+
import * as MarkdownIt from 'markdown-it';
4+
5+
declare function require(id: string): any;
6+
7+
const markdown = new MarkdownIt();
8+
markdown.use(require('markdown-it-abbr'));
9+
markdown.use(require('markdown-it-deflist'));
10+
markdown.use(require('markdown-it-emoji'));
11+
markdown.use(require('markdown-it-footnote'));
12+
markdown.use(require('markdown-it-ins'));
13+
markdown.use(require('markdown-it-mark'));
14+
markdown.use(require('markdown-it-sub'));
15+
markdown.use(require('markdown-it-sup'));
16+
markdown.use(require('markdown-it-table-of-contents'));
17+
markdown.use(highlighter);
18+
19+
@Pipe({
20+
name: 'markdown',
21+
})
22+
export class MarkdownPipe implements PipeTransform {
23+
transform(value: string): string {
24+
if (!value) {
25+
return '';
26+
}
27+
return markdown.render(value);
28+
}
29+
}
30+
31+
function highlighter(md: MarkdownIt): void {
32+
md.set({
33+
highlight: (code, lang) => {
34+
return hljs.highlightAuto(code, lang ? [lang] : ['ts', 'js', 'html', 'scss', 'css']).value;
35+
},
36+
});
37+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { CommonModule } from '@angular/common';
2+
import { NgModule } from '@angular/core';
3+
import { HighlightPipe } from './pipes/highlight.pipe';
4+
import { MarkdownPipe } from './pipes/markdown.pipe';
5+
6+
@NgModule({
7+
imports: [
8+
CommonModule,
9+
],
10+
declarations: [
11+
HighlightPipe,
12+
MarkdownPipe,
13+
],
14+
exports: [
15+
HighlightPipe,
16+
MarkdownPipe,
17+
],
18+
})
19+
export class UiModelMarkdownModule {
20+
}
21+
22+
export * from './pipes/highlight.pipe';
23+
export * from './pipes/markdown.pipe';

src/public_api.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/*
2+
* Public API Surface of angular-markdown
3+
*/
4+
5+
export * from './lib/ui-model-markdown.module';

src/test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
2+
3+
import { getTestBed } from '@angular/core/testing';
4+
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
5+
import 'core-js/es7/reflect';
6+
import 'zone.js/dist/zone';
7+
import 'zone.js/dist/zone-testing';
8+
9+
declare const require: any;
10+
11+
// First, initialize the Angular testing environment.
12+
getTestBed().initTestEnvironment(
13+
BrowserDynamicTestingModule,
14+
platformBrowserDynamicTesting(),
15+
);
16+
// Then we find all the tests.
17+
const context = require.context('./', true, /\.spec\.ts$/);
18+
// And load the modules.
19+
context.keys().map(context);

0 commit comments

Comments
 (0)