-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: footnotes escape html only once #2088
Merged
+2,282
−5,517
Merged
Changes from 28 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
e747c09
fix
derschnee68 ebbe53f
fix
derschnee68 30a35b1
fix
derschnee68 dc7f3da
Merge remote-tracking branch 'origin/main' into julien/footnote
derschnee68 39f6190
fix
derschnee68 ef987c2
wip
derschnee68 15278ca
wip
derschnee68 f1af65c
fix
derschnee68 743b8c2
fix
derschnee68 a7e8f02
fix
derschnee68 6ec48eb
fix
derschnee68 a0295d7
fix
derschnee68 13d96d7
fix
derschnee68 44136c8
fix
derschnee68 002756e
Merge remote-tracking branch 'origin/main' into julien/footnote-test
derschnee68 59afe29
fix: add e2e test
derschnee68 8077473
wip
derschnee68 8e32812
fix
derschnee68 f0c803b
fix
derschnee68 90c952f
Merge branch 'julien/footnote-test' into julien/footnote-pipe
derschnee68 8350a08
fix
derschnee68 c05fbe5
fix
derschnee68 b5cc934
fix
derschnee68 ca96869
Merge branch 'main' into julien/footnote-pipe
derschnee68 9ac8c23
Merge branch 'main' into julien/footnote-pipe
derschnee68 4cf96bc
fix
derschnee68 e1e0307
fix
derschnee68 3893703
fix
derschnee68 a3822b7
fix
derschnee68 7269e66
fix
derschnee68 69b23fa
fix
derschnee68 35b54a9
fix
derschnee68 e0e0fde
Merge branch 'main' into julien/footnote-pipe
derschnee68 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 { 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to extract this single function like that? Would it make more sense to keep it where it was or move it to
CkEditorComponent
or ideally to service which handles footnote (not sure if this exists, but if not creating it for single function doesn't make sense).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is used in two different nx libs so to me that seems like the cleanest way