xt-plugin-editor 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +17 -0
- package/.postcssrc.json +1 -0
- package/.prettierrc +12 -0
- package/.rush/temp/chunked-rush-logs/xt-plugin-editor.build.chunks.jsonl +23 -0
- package/.rush/temp/chunked-rush-logs/xt-plugin-editor.test.chunks.jsonl +50 -0
- package/.rush/temp/shrinkwrap-deps.json +1200 -0
- package/CHANGELOG.md +2 -0
- package/README.md +12 -2
- package/angular.json +148 -0
- package/package.json +80 -4
- package/projects/editor/README.md +13 -0
- package/projects/editor/ng-package.json +7 -0
- package/projects/editor/package.json +43 -0
- package/projects/editor/src/lib/editor/editor.component.css +15 -0
- package/projects/editor/src/lib/editor/editor.component.html +29 -0
- package/projects/editor/src/lib/editor/editor.component.spec.ts +53 -0
- package/projects/editor/src/lib/editor/editor.component.ts +202 -0
- package/projects/editor/src/lib/markdown/inline-markdown-pipe.spec.ts +25 -0
- package/projects/editor/src/lib/markdown/inline-markdown-pipe.ts +30 -0
- package/projects/editor/src/lib/markdown/markdown-pipe.spec.ts +29 -0
- package/projects/editor/src/lib/markdown/markdown-pipe.ts +21 -0
- package/projects/editor/src/lib/prose-mirror/basic-setup.ts +655 -0
- package/projects/editor/src/lib/register.ts +33 -0
- package/projects/editor/src/public-api.ts +7 -0
- package/projects/editor/tsconfig.lib.json +13 -0
- package/projects/editor/tsconfig.lib.prod.json +11 -0
- package/projects/editor/tsconfig.spec.json +10 -0
- package/projects/editor-plugin/federation.config.js +33 -0
- package/projects/editor-plugin/public/favicon.ico +0 -0
- package/projects/editor-plugin/src/app/app.component.css +0 -0
- package/projects/editor-plugin/src/app/app.component.html +3 -0
- package/projects/editor-plugin/src/app/app.component.spec.ts +34 -0
- package/projects/editor-plugin/src/app/app.component.ts +23 -0
- package/projects/editor-plugin/src/app/app.config.ts +22 -0
- package/projects/editor-plugin/src/app/app.routes.ts +6 -0
- package/projects/editor-plugin/src/app/editor-test-component/editor-test.component.css +4 -0
- package/projects/editor-plugin/src/app/editor-test-component/editor-test.component.html +19 -0
- package/projects/editor-plugin/src/app/editor-test-component/editor-test.component.spec.ts +33 -0
- package/projects/editor-plugin/src/app/editor-test-component/editor-test.component.ts +67 -0
- package/projects/editor-plugin/src/bootstrap.ts +6 -0
- package/projects/editor-plugin/src/index.html +13 -0
- package/projects/editor-plugin/src/main.ts +6 -0
- package/projects/editor-plugin/src/styles.css +14 -0
- package/projects/editor-plugin/tsconfig.app.json +11 -0
- package/projects/editor-plugin/tsconfig.federation.json +13 -0
- package/projects/editor-plugin/tsconfig.spec.json +10 -0
- package/rush-logs/xt-plugin-editor.build.error.log +8 -0
- package/rush-logs/xt-plugin-editor.build.log +23 -0
- package/rush-logs/xt-plugin-editor.test.error.log +1 -0
- package/rush-logs/xt-plugin-editor.test.log +50 -0
- package/tsconfig.json +33 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Pipe, PipeTransform } from '@angular/core';
|
|
2
|
+
|
|
3
|
+
@Pipe({
|
|
4
|
+
name: 'inlineMarkdown',
|
|
5
|
+
})
|
|
6
|
+
export class InlineMarkdownPipe implements PipeTransform {
|
|
7
|
+
transform(value: unknown, ...args: unknown[]): unknown {
|
|
8
|
+
if( typeof value === 'string' ) {
|
|
9
|
+
let text = value as string;
|
|
10
|
+
if (text.length>100)
|
|
11
|
+
text=text.substring(0,100); // For inline text, we don't want all the text, just the start
|
|
12
|
+
text = text.replace(/!\[[^\]]*\]\([^)]*\)/g, ''); // images
|
|
13
|
+
text = text.replace(/\[([^\]]*)\]\([^)]*\)/g, '$1');// links -> visible text
|
|
14
|
+
text = text.replace(/^#{1,6}\s*/gm, ''); // headers
|
|
15
|
+
text = text.replace(/^\s*[-*+]\s+/gm, ''); // bullet lists
|
|
16
|
+
text = text.replace(/^\s*\d+[.)]\s+/gm, ''); // numbered lists
|
|
17
|
+
text = text.replace(/^\s*[-*]\s+/gm, ''); // bullets that were bold markers
|
|
18
|
+
text = text.replace(/\*\*([^*]*)\*\*/g, '$1'); // bold
|
|
19
|
+
text = text.replace(/\*([^*]*)\*/g, '$1'); // italic *
|
|
20
|
+
text = text.replace(/(?<!\w)_([^_\n]+)_(?!\w)/g, '$1'); // italic _text_
|
|
21
|
+
text = text.replace(/\s*\n\s*/g, ' '); // newlines -> spaces
|
|
22
|
+
text = text.replace(/\s{2,}/g, ' ').trim(); // collapse
|
|
23
|
+
if (text.length>57) {
|
|
24
|
+
return text.substring(0,57)+'...';
|
|
25
|
+
}
|
|
26
|
+
return text;
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from 'vitest';
|
|
2
|
+
import { MarkdownPipe } from './markdown-pipe';
|
|
3
|
+
import { TestBed } from '@angular/core/testing';
|
|
4
|
+
import { provideNoopAnimations } from '@angular/platform-browser/animations';
|
|
5
|
+
import { provideZonelessChangeDetection } from '@angular/core';
|
|
6
|
+
|
|
7
|
+
describe('MarkdownPipe', () => {
|
|
8
|
+
beforeEach(async () => {
|
|
9
|
+
await TestBed.configureTestingModule({
|
|
10
|
+
providers: [MarkdownPipe, provideNoopAnimations(), provideZonelessChangeDetection()]
|
|
11
|
+
|
|
12
|
+
})
|
|
13
|
+
.compileComponents();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('create an instance', () => {
|
|
17
|
+
const pipe = TestBed.inject(MarkdownPipe);
|
|
18
|
+
expect(pipe).toBeTruthy();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('Render correctly HTML', () => {
|
|
22
|
+
const pipe = TestBed.inject(MarkdownPipe);
|
|
23
|
+
const response = pipe.transform("# Header\n\nTest **Text**") as string;
|
|
24
|
+
expect(response.indexOf('<h1>')).not.toBe(-1);
|
|
25
|
+
expect(response.indexOf('Test')).not.toBe(-1);
|
|
26
|
+
expect(response.indexOf('<strong>')).not.toBe(-1);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Pipe, PipeTransform, SecurityContext } from '@angular/core';
|
|
2
|
+
import { marked } from 'marked';
|
|
3
|
+
import { DomSanitizer } from '@angular/platform-browser';
|
|
4
|
+
|
|
5
|
+
@Pipe({
|
|
6
|
+
name: 'markdown',
|
|
7
|
+
})
|
|
8
|
+
export class MarkdownPipe implements PipeTransform {
|
|
9
|
+
constructor(protected sanitizer: DomSanitizer) {
|
|
10
|
+
}
|
|
11
|
+
transform(value: unknown, ...args: unknown[]): unknown {
|
|
12
|
+
if( typeof value === 'string' ) {
|
|
13
|
+
const html= marked.parse(value.replace(/^[\u200B\u200C\u200D\u200E\u200F\uFEFF]/,""),
|
|
14
|
+
{
|
|
15
|
+
async:false
|
|
16
|
+
});
|
|
17
|
+
return this.sanitizer.sanitize(SecurityContext.HTML, html);
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|