diff --git a/src/app/components/shared/_dialogs/deep-ldialog/deep-ldialog.component.ts b/src/app/components/shared/_dialogs/deep-ldialog/deep-ldialog.component.ts index 3f18d73fd46f226e8395da1ab794fe147a131d04..ac5e45af659453e526a4b06f53e2b64d0eb34c14 100644 --- a/src/app/components/shared/_dialogs/deep-ldialog/deep-ldialog.component.ts +++ b/src/app/components/shared/_dialogs/deep-ldialog/deep-ldialog.component.ts @@ -8,6 +8,7 @@ import { ExplanationDialogComponent } from '../explanation-dialog/explanation-di import { DeepLService, FormalityType, TargetLang } from '../../../../services/http/deep-l.service'; import { Observable } from 'rxjs'; import { map } from 'rxjs/operators'; +import { CreateCommentKeywords } from '../../../../utils/create-comment-keywords'; interface ResultValue { body: string; @@ -48,7 +49,7 @@ export class DeepLDialogComponent implements OnInit, AfterViewInit { const delta = ViewCommentDataComponent.getDeltaFromData(body); const xml = delta.ops.reduce((acc, e, i) => { if (typeof e['insert'] === 'string' && e['insert'].trim().length) { - acc += '<x i="' + i + '">' + this.encodeHTML(e['insert']) + '</x>'; + acc += '<x i="' + i + '">' + this.encodeHTML(CreateCommentKeywords.removeMarkdown(e['insert'])) + '</x>'; e['insert'] = ''; } return acc; diff --git a/src/app/utils/create-comment-keywords.ts b/src/app/utils/create-comment-keywords.ts index 7a09194840c7b87424380b0c71983252b1a6f326..592296cfad4933bcf0456b43a7f58e16524961cd 100644 --- a/src/app/utils/create-comment-keywords.ts +++ b/src/app/utils/create-comment-keywords.ts @@ -3,11 +3,17 @@ import { map } from 'rxjs/operators'; export class CreateCommentKeywords { - static isKeywordAcceptable(keyword: string) { + static isKeywordAcceptable(keyword: string): boolean { const regex = /(^[ -@\[-`{-~]+$)/g; return keyword.match(regex) === null && keyword.length > 2; } + static removeMarkdown(text: string): string { + return text.replace(/([*_~]+(?=[^*_~\s]))|(^[ \t]*#+ )|(^[ \t]*>[> ]*)|(`+)/gm, '') + .replace(/([^*_~\s])[*_~]+/gm, '$1') + .replace(/\[([^\n\[\]]*)\]\(([^()\n]*)\)/gm, '$1 $2'); + } + static isSpellingAcceptable(languagetoolService: LanguagetoolService, text: string, language: Language = 'auto') { return languagetoolService.checkSpellings(text, language).pipe( map(result => { @@ -23,7 +29,7 @@ export class CreateCommentKeywords { ); } - private static escapeForSpacy(text: string) { + private static escapeForSpacy(text: string): string { const upperText = text.toUpperCase(); const regex = /\s+|$/gmi; let m: RegExpExecArray;