Skip to content

Commit 847e990

Browse files
author
danad02
authored
Merge pull request #25 from utkukaratas/master
add onSanitizeOutputLine prop
2 parents 0a3cbea + c1bfc73 commit 847e990

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ https://webscopeio.github.io/react-console/
4545
| inputClassName | string | className for `input` |
4646
| history | string[] | history array |
4747
| onAddHistoryItem | (entry: string) => void | callback called when a new history entry is created |
48+
| onSanitizeOutputLine | (line: string) => string | callback called before a new output line is inserted to DOM |
4849

4950
\*_are mandatory_
5051

src/index.tsx

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export type ReactConsoleProps = {
3939
// history props
4040
history?: string[],
4141
onAddHistoryItem?: (entry: string) => void,
42+
onSanitizeOutputLine?: (line: string) => string,
4243
}
4344

4445
type ReactConsoleState = {
@@ -185,6 +186,16 @@ export default class ReactConsole extends React.Component<ReactConsoleProps, Rea
185186
autoFocus,
186187
} = this.props;
187188

189+
const sanitizeOutputLine = (line: string): string => {
190+
const {onSanitizeOutputLine} = this.props;
191+
192+
if (typeof onSanitizeOutputLine === 'function') {
193+
return onSanitizeOutputLine(line)
194+
}
195+
196+
return line
197+
}
198+
188199
return (
189200
<div
190201
className={classnames(styles.wrapper, wrapperClassName)}
@@ -196,13 +207,15 @@ export default class ReactConsole extends React.Component<ReactConsoleProps, Rea
196207
ref={ref => this.wrapperRef = ref}
197208
>
198209
<div>
199-
{this.state.output.map((line, key) =>
200-
<pre
201-
key={key}
202-
className={classnames(styles.line, lineClassName)}
203-
style={lineStyle}
204-
dangerouslySetInnerHTML={{__html: line}}
205-
/>
210+
{this.state.output
211+
.map(line => sanitizeOutputLine(line))
212+
.map((line, key) =>
213+
<pre
214+
key={key}
215+
className={classnames(styles.line, lineClassName)}
216+
style={lineStyle}
217+
dangerouslySetInnerHTML={{__html: line}}
218+
/>
206219
)}
207220
</div>
208221
<form

0 commit comments

Comments
 (0)