-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: footnotes escape html only once (#2088)
- Loading branch information
1 parent
5bdb9fc
commit cc85f14
Showing
9 changed files
with
2,282 additions
and
5,517 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,41 @@ | ||
import { Component, Input } from '@angular/core'; | ||
import { Component, Input, OnInit } from '@angular/core'; | ||
import { FormControl } from '@angular/forms'; | ||
import * as Editor from 'ckeditor5-custom-build/build/ckeditor'; | ||
import * as Editor from 'ckeditor5-custom-build'; | ||
import { ckEditor } from './ck-editor'; | ||
import { unescapeHtml } from './unescape-html'; | ||
|
||
@Component({ | ||
selector: 'app-ck-editor', | ||
template: ` <ckeditor [formControl]="control" [config]="ckEditor.config" [editor]="editor" /> | ||
template: ` <ckeditor [formControl]="footnoteControl" [config]="ckEditor.config" [editor]="editor" /> | ||
<mat-error *ngIf="control.touched && control.errors as errors">{{ errors | humanReadableError }}</mat-error>`, | ||
}) | ||
export class CkEditorComponent { | ||
export class CkEditorComponent implements OnInit { | ||
@Input({ required: true }) control!: FormControl<string>; | ||
footnoteControl = new FormControl<string>(''); | ||
|
||
readonly editor = Editor; | ||
protected readonly ckEditor = ckEditor; | ||
|
||
ngOnInit() { | ||
this.footnoteControl.setValue(this.control.value ? this._parseToFootnote(this.control.value) : null); | ||
|
||
this.footnoteControl.valueChanges.subscribe(value => { | ||
this.control.setValue(this._parseFromFootnote(value)); | ||
}); | ||
} | ||
|
||
private _parseToFootnote(rawHtml: string) { | ||
const _footnoteRegExp2 = /<footnote content="([^>]+)"\/>/g; | ||
return rawHtml.replace(_footnoteRegExp2, (match, content) => { | ||
return `<footnote content="${content}">[Footnote]</footnote>`; | ||
}); | ||
} | ||
|
||
private _parseFromFootnote(rawHtml: string) { | ||
const _footnoteRegExp = /<footnote content="([^>]+)">([^<]*)<\/footnote>/g; | ||
return rawHtml.replace(_footnoteRegExp, (match, content) => { | ||
const escapedContent = unescapeHtml(content); | ||
return `<footnote content="${escapedContent}"></footnote>`; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export function unescapeHtml(str: string) { | ||
const unescapeMap = { | ||
'&': '&', | ||
'<': '<', | ||
'>': '>', | ||
'"': '"', | ||
''': "'", | ||
}; | ||
return str.replace(/&(amp|lt|gt|quot|#039);/g, match => unescapeMap[match]); | ||
} |
Oops, something went wrong.