Skip to content
Snippets Groups Projects
Commit 24eef595 authored by Ruben Bimberg's avatar Ruben Bimberg :computer:
Browse files

Remove markdown when using deepl

parent ff575017
No related merge requests found
......@@ -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;
......
......@@ -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;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment