Skip to content

Commit b50fe64

Browse files
nutboltubvaughn
authored andcommitted
fix(unicode-to-char): Replaced other languages unicode to text (#1780)
* fix(unicode-to-char): Replaced other languages unicode to text * fix(unicode-to-char): run prettier to fix lint error * feat(unicode-to-char): modified the replace function with p1 parameter
1 parent e4015f3 commit b50fe64

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/components/CodeEditor/CodeEditor.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ import {LiveEditor, LiveProvider} from 'react-live';
1111
import {colors, media} from 'theme';
1212
import MetaTitle from 'templates/components/MetaTitle';
1313

14+
// Replace unicode to text for other languages
15+
const unicodeToText = text =>
16+
text.replace(/\\u([\dA-F]{4})/gi, (_, p1) =>
17+
String.fromCharCode(parseInt(p1, 16)),
18+
);
19+
1420
const compileES5 = (
1521
code, // eslint-disable-next-line no-undef
1622
) => Babel.transform(code, {presets: ['es2015', 'react']}).code;
@@ -271,7 +277,7 @@ class CodeEditor extends Component {
271277

272278
if (showJSX) {
273279
newState.code = code;
274-
newState.compiledES6 = compileES6(code);
280+
newState.compiledES6 = unicodeToText(compileES6(code));
275281
} else {
276282
newState.compiledES6 = code;
277283
}

0 commit comments

Comments
 (0)