From 24eef595e9fa2a6c9b6dd295f1a7146f2ef93d80 Mon Sep 17 00:00:00 2001 From: Ruben Bimberg <ruben.bimberg@mni.thm.de> Date: Mon, 4 Oct 2021 13:29:59 +0200 Subject: [PATCH] Remove markdown when using deepl --- .../_dialogs/deep-ldialog/deep-ldialog.component.ts | 3 ++- src/app/utils/create-comment-keywords.ts | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) 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 3f18d73fd..ac5e45af6 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 7a0919484..592296cfa 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; -- GitLab