balibabu commited on
Commit
944c0a6
·
1 Parent(s): d80b399

feat: add programming language highlighting for markdown syntax (#129)

Browse files
web/package-lock.json CHANGED
@@ -25,6 +25,7 @@
25
  "react-markdown": "^9.0.1",
26
  "react-pdf-highlighter": "^6.1.0",
27
  "react-string-replace": "^1.1.1",
 
28
  "remark-gfm": "^4.0.0",
29
  "umi": "^4.0.90",
30
  "umi-request": "^1.4.0",
@@ -36,6 +37,7 @@
36
  "@types/lodash": "^4.14.202",
37
  "@types/react": "^18.0.33",
38
  "@types/react-dom": "^18.0.11",
 
39
  "@types/uuid": "^9.0.8",
40
  "@umijs/lint": "^4.1.1",
41
  "@umijs/plugins": "^4.1.0",
@@ -2949,6 +2951,15 @@
2949
  "dev": true,
2950
  "peer": true
2951
  },
 
 
 
 
 
 
 
 
 
2952
  "node_modules/@types/scheduler": {
2953
  "version": "0.16.8",
2954
  "resolved": "https://registry.npmmirror.com/@types/scheduler/-/scheduler-0.16.8.tgz",
@@ -8394,6 +8405,14 @@
8394
  "reusify": "^1.0.4"
8395
  }
8396
  },
 
 
 
 
 
 
 
 
8397
  "node_modules/fb-watchman": {
8398
  "version": "2.0.2",
8399
  "resolved": "https://registry.npmmirror.com/fb-watchman/-/fb-watchman-2.0.2.tgz",
@@ -8669,6 +8688,14 @@
8669
  "node": ">= 6"
8670
  }
8671
  },
 
 
 
 
 
 
 
 
8672
  "node_modules/formdata-polyfill": {
8673
  "version": "4.0.10",
8674
  "resolved": "https://registry.npmmirror.com/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz",
@@ -9182,6 +9209,11 @@
9182
  "node": ">= 0.4"
9183
  }
9184
  },
 
 
 
 
 
9185
  "node_modules/hast-util-to-jsx-runtime": {
9186
  "version": "2.3.0",
9187
  "resolved": "https://registry.npmmirror.com/hast-util-to-jsx-runtime/-/hast-util-to-jsx-runtime-2.3.0.tgz",
@@ -9212,6 +9244,49 @@
9212
  "@types/hast": "^3.0.0"
9213
  }
9214
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9215
  "node_modules/he": {
9216
  "version": "1.2.0",
9217
  "resolved": "https://registry.npmmirror.com/he/-/he-1.2.0.tgz",
@@ -9220,6 +9295,14 @@
9220
  "he": "bin/he"
9221
  }
9222
  },
 
 
 
 
 
 
 
 
9223
  "node_modules/history": {
9224
  "version": "5.3.0",
9225
  "resolved": "https://registry.npmmirror.com/history/-/history-5.3.0.tgz",
@@ -11020,6 +11103,15 @@
11020
  "tslib": "^2.0.3"
11021
  }
11022
  },
 
 
 
 
 
 
 
 
 
11023
  "node_modules/lru-cache": {
11024
  "version": "5.1.1",
11025
  "resolved": "https://registry.npmmirror.com/lru-cache/-/lru-cache-5.1.1.tgz",
@@ -13409,6 +13501,14 @@
13409
  "renderkid": "^3.0.0"
13410
  }
13411
  },
 
 
 
 
 
 
 
 
13412
  "node_modules/process": {
13413
  "version": "0.11.10",
13414
  "resolved": "https://registry.npmmirror.com/process/-/process-0.11.10.tgz",
@@ -14846,6 +14946,21 @@
14846
  "node": ">=0.12.0"
14847
  }
14848
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14849
  "node_modules/reactcss": {
14850
  "version": "1.2.3",
14851
  "resolved": "https://registry.npmmirror.com/reactcss/-/reactcss-1.2.3.tgz",
@@ -15079,6 +15194,76 @@
15079
  "node": ">= 0.4"
15080
  }
15081
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15082
  "node_modules/regenerate": {
15083
  "version": "1.4.2",
15084
  "resolved": "https://registry.npmmirror.com/regenerate/-/regenerate-1.4.2.tgz",
 
25
  "react-markdown": "^9.0.1",
26
  "react-pdf-highlighter": "^6.1.0",
27
  "react-string-replace": "^1.1.1",
28
+ "react-syntax-highlighter": "^15.5.0",
29
  "remark-gfm": "^4.0.0",
30
  "umi": "^4.0.90",
31
  "umi-request": "^1.4.0",
 
37
  "@types/lodash": "^4.14.202",
38
  "@types/react": "^18.0.33",
39
  "@types/react-dom": "^18.0.11",
40
+ "@types/react-syntax-highlighter": "^15.5.11",
41
  "@types/uuid": "^9.0.8",
42
  "@umijs/lint": "^4.1.1",
43
  "@umijs/plugins": "^4.1.0",
 
2951
  "dev": true,
2952
  "peer": true
2953
  },
2954
+ "node_modules/@types/react-syntax-highlighter": {
2955
+ "version": "15.5.11",
2956
+ "resolved": "https://registry.npmmirror.com/@types/react-syntax-highlighter/-/react-syntax-highlighter-15.5.11.tgz",
2957
+ "integrity": "sha512-ZqIJl+Pg8kD+47kxUjvrlElrraSUrYa4h0dauY/U/FTUuprSCqvUj+9PNQNQzVc6AJgIWUUxn87/gqsMHNbRjw==",
2958
+ "dev": true,
2959
+ "dependencies": {
2960
+ "@types/react": "*"
2961
+ }
2962
+ },
2963
  "node_modules/@types/scheduler": {
2964
  "version": "0.16.8",
2965
  "resolved": "https://registry.npmmirror.com/@types/scheduler/-/scheduler-0.16.8.tgz",
 
8405
  "reusify": "^1.0.4"
8406
  }
8407
  },
8408
+ "node_modules/fault": {
8409
+ "version": "1.0.4",
8410
+ "resolved": "https://registry.npmmirror.com/fault/-/fault-1.0.4.tgz",
8411
+ "integrity": "sha512-CJ0HCB5tL5fYTEA7ToAq5+kTwd++Borf1/bifxd9iT70QcXr4MRrO3Llf8Ifs70q+SJcGHFtnIE/Nw6giCtECA==",
8412
+ "dependencies": {
8413
+ "format": "^0.2.0"
8414
+ }
8415
+ },
8416
  "node_modules/fb-watchman": {
8417
  "version": "2.0.2",
8418
  "resolved": "https://registry.npmmirror.com/fb-watchman/-/fb-watchman-2.0.2.tgz",
 
8688
  "node": ">= 6"
8689
  }
8690
  },
8691
+ "node_modules/format": {
8692
+ "version": "0.2.2",
8693
+ "resolved": "https://registry.npmmirror.com/format/-/format-0.2.2.tgz",
8694
+ "integrity": "sha512-wzsgA6WOq+09wrU1tsJ09udeR/YZRaeArL9e1wPbFg3GG2yDnC2ldKpxs4xunpFF9DgqCqOIra3bc1HWrJ37Ww==",
8695
+ "engines": {
8696
+ "node": ">=0.4.x"
8697
+ }
8698
+ },
8699
  "node_modules/formdata-polyfill": {
8700
  "version": "4.0.10",
8701
  "resolved": "https://registry.npmmirror.com/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz",
 
9209
  "node": ">= 0.4"
9210
  }
9211
  },
9212
+ "node_modules/hast-util-parse-selector": {
9213
+ "version": "2.2.5",
9214
+ "resolved": "https://registry.npmmirror.com/hast-util-parse-selector/-/hast-util-parse-selector-2.2.5.tgz",
9215
+ "integrity": "sha512-7j6mrk/qqkSehsM92wQjdIgWM2/BW61u/53G6xmC8i1OmEdKLHbk419QKQUjz6LglWsfqoiHmyMRkP1BGjecNQ=="
9216
+ },
9217
  "node_modules/hast-util-to-jsx-runtime": {
9218
  "version": "2.3.0",
9219
  "resolved": "https://registry.npmmirror.com/hast-util-to-jsx-runtime/-/hast-util-to-jsx-runtime-2.3.0.tgz",
 
9244
  "@types/hast": "^3.0.0"
9245
  }
9246
  },
9247
+ "node_modules/hastscript": {
9248
+ "version": "6.0.0",
9249
+ "resolved": "https://registry.npmmirror.com/hastscript/-/hastscript-6.0.0.tgz",
9250
+ "integrity": "sha512-nDM6bvd7lIqDUiYEiu5Sl/+6ReP0BMk/2f4U/Rooccxkj0P5nm+acM5PrGJ/t5I8qPGiqZSE6hVAwZEdZIvP4w==",
9251
+ "dependencies": {
9252
+ "@types/hast": "^2.0.0",
9253
+ "comma-separated-tokens": "^1.0.0",
9254
+ "hast-util-parse-selector": "^2.0.0",
9255
+ "property-information": "^5.0.0",
9256
+ "space-separated-tokens": "^1.0.0"
9257
+ }
9258
+ },
9259
+ "node_modules/hastscript/node_modules/@types/hast": {
9260
+ "version": "2.3.10",
9261
+ "resolved": "https://registry.npmmirror.com/@types/hast/-/hast-2.3.10.tgz",
9262
+ "integrity": "sha512-McWspRw8xx8J9HurkVBfYj0xKoE25tOFlHGdx4MJ5xORQrMGZNqJhVQWaIbm6Oyla5kYOXtDiopzKRJzEOkwJw==",
9263
+ "dependencies": {
9264
+ "@types/unist": "^2"
9265
+ }
9266
+ },
9267
+ "node_modules/hastscript/node_modules/@types/unist": {
9268
+ "version": "2.0.10",
9269
+ "resolved": "https://registry.npmmirror.com/@types/unist/-/unist-2.0.10.tgz",
9270
+ "integrity": "sha512-IfYcSBWE3hLpBg8+X2SEa8LVkJdJEkT2Ese2aaLs3ptGdVtABxndrMaxuFlQ1qdFf9Q5rDvDpxI3WwgvKFAsQA=="
9271
+ },
9272
+ "node_modules/hastscript/node_modules/comma-separated-tokens": {
9273
+ "version": "1.0.8",
9274
+ "resolved": "https://registry.npmmirror.com/comma-separated-tokens/-/comma-separated-tokens-1.0.8.tgz",
9275
+ "integrity": "sha512-GHuDRO12Sypu2cV70d1dkA2EUmXHgntrzbpvOB+Qy+49ypNfGgFQIC2fhhXbnyrJRynDCAARsT7Ou0M6hirpfw=="
9276
+ },
9277
+ "node_modules/hastscript/node_modules/property-information": {
9278
+ "version": "5.6.0",
9279
+ "resolved": "https://registry.npmmirror.com/property-information/-/property-information-5.6.0.tgz",
9280
+ "integrity": "sha512-YUHSPk+A30YPv+0Qf8i9Mbfe/C0hdPXk1s1jPVToV8pk8BQtpw10ct89Eo7OWkutrwqvT0eicAxlOg3dOAu8JA==",
9281
+ "dependencies": {
9282
+ "xtend": "^4.0.0"
9283
+ }
9284
+ },
9285
+ "node_modules/hastscript/node_modules/space-separated-tokens": {
9286
+ "version": "1.1.5",
9287
+ "resolved": "https://registry.npmmirror.com/space-separated-tokens/-/space-separated-tokens-1.1.5.tgz",
9288
+ "integrity": "sha512-q/JSVd1Lptzhf5bkYm4ob4iWPjx0KiRe3sRFBNrVqbJkFaBm5vbbowy1mymoPNLRa52+oadOhJ+K49wsSeSjTA=="
9289
+ },
9290
  "node_modules/he": {
9291
  "version": "1.2.0",
9292
  "resolved": "https://registry.npmmirror.com/he/-/he-1.2.0.tgz",
 
9295
  "he": "bin/he"
9296
  }
9297
  },
9298
+ "node_modules/highlight.js": {
9299
+ "version": "10.7.3",
9300
+ "resolved": "https://registry.npmmirror.com/highlight.js/-/highlight.js-10.7.3.tgz",
9301
+ "integrity": "sha512-tzcUFauisWKNHaRkN4Wjl/ZA07gENAjFl3J/c480dprkGTg5EQstgaNFqBfUqCq54kZRIEcreTsAgF/m2quD7A==",
9302
+ "engines": {
9303
+ "node": "*"
9304
+ }
9305
+ },
9306
  "node_modules/history": {
9307
  "version": "5.3.0",
9308
  "resolved": "https://registry.npmmirror.com/history/-/history-5.3.0.tgz",
 
11103
  "tslib": "^2.0.3"
11104
  }
11105
  },
11106
+ "node_modules/lowlight": {
11107
+ "version": "1.20.0",
11108
+ "resolved": "https://registry.npmmirror.com/lowlight/-/lowlight-1.20.0.tgz",
11109
+ "integrity": "sha512-8Ktj+prEb1RoCPkEOrPMYUN/nCggB7qAWe3a7OpMjWQkh3l2RD5wKRQ+o8Q8YuI9RG/xs95waaI/E6ym/7NsTw==",
11110
+ "dependencies": {
11111
+ "fault": "^1.0.0",
11112
+ "highlight.js": "~10.7.0"
11113
+ }
11114
+ },
11115
  "node_modules/lru-cache": {
11116
  "version": "5.1.1",
11117
  "resolved": "https://registry.npmmirror.com/lru-cache/-/lru-cache-5.1.1.tgz",
 
13501
  "renderkid": "^3.0.0"
13502
  }
13503
  },
13504
+ "node_modules/prismjs": {
13505
+ "version": "1.29.0",
13506
+ "resolved": "https://registry.npmmirror.com/prismjs/-/prismjs-1.29.0.tgz",
13507
+ "integrity": "sha512-Kx/1w86q/epKcmte75LNrEoT+lX8pBpavuAbvJWRXar7Hz8jrtF+e3vY751p0R8H9HdArwaCTNDDzHg/ScJK1Q==",
13508
+ "engines": {
13509
+ "node": ">=6"
13510
+ }
13511
+ },
13512
  "node_modules/process": {
13513
  "version": "0.11.10",
13514
  "resolved": "https://registry.npmmirror.com/process/-/process-0.11.10.tgz",
 
14946
  "node": ">=0.12.0"
14947
  }
14948
  },
14949
+ "node_modules/react-syntax-highlighter": {
14950
+ "version": "15.5.0",
14951
+ "resolved": "https://registry.npmmirror.com/react-syntax-highlighter/-/react-syntax-highlighter-15.5.0.tgz",
14952
+ "integrity": "sha512-+zq2myprEnQmH5yw6Gqc8lD55QHnpKaU8TOcFeC/Lg/MQSs8UknEA0JC4nTZGFAXC2J2Hyj/ijJ7NlabyPi2gg==",
14953
+ "dependencies": {
14954
+ "@babel/runtime": "^7.3.1",
14955
+ "highlight.js": "^10.4.1",
14956
+ "lowlight": "^1.17.0",
14957
+ "prismjs": "^1.27.0",
14958
+ "refractor": "^3.6.0"
14959
+ },
14960
+ "peerDependencies": {
14961
+ "react": ">= 0.14.0"
14962
+ }
14963
+ },
14964
  "node_modules/reactcss": {
14965
  "version": "1.2.3",
14966
  "resolved": "https://registry.npmmirror.com/reactcss/-/reactcss-1.2.3.tgz",
 
15194
  "node": ">= 0.4"
15195
  }
15196
  },
15197
+ "node_modules/refractor": {
15198
+ "version": "3.6.0",
15199
+ "resolved": "https://registry.npmmirror.com/refractor/-/refractor-3.6.0.tgz",
15200
+ "integrity": "sha512-MY9W41IOWxxk31o+YvFCNyNzdkc9M20NoZK5vq6jkv4I/uh2zkWcfudj0Q1fovjUQJrNewS9NMzeTtqPf+n5EA==",
15201
+ "dependencies": {
15202
+ "hastscript": "^6.0.0",
15203
+ "parse-entities": "^2.0.0",
15204
+ "prismjs": "~1.27.0"
15205
+ }
15206
+ },
15207
+ "node_modules/refractor/node_modules/character-entities": {
15208
+ "version": "1.2.4",
15209
+ "resolved": "https://registry.npmmirror.com/character-entities/-/character-entities-1.2.4.tgz",
15210
+ "integrity": "sha512-iBMyeEHxfVnIakwOuDXpVkc54HijNgCyQB2w0VfGQThle6NXn50zU6V/u+LDhxHcDUPojn6Kpga3PTAD8W1bQw=="
15211
+ },
15212
+ "node_modules/refractor/node_modules/character-entities-legacy": {
15213
+ "version": "1.1.4",
15214
+ "resolved": "https://registry.npmmirror.com/character-entities-legacy/-/character-entities-legacy-1.1.4.tgz",
15215
+ "integrity": "sha512-3Xnr+7ZFS1uxeiUDvV02wQ+QDbc55o97tIV5zHScSPJpcLm/r0DFPcoY3tYRp+VZukxuMeKgXYmsXQHO05zQeA=="
15216
+ },
15217
+ "node_modules/refractor/node_modules/character-reference-invalid": {
15218
+ "version": "1.1.4",
15219
+ "resolved": "https://registry.npmmirror.com/character-reference-invalid/-/character-reference-invalid-1.1.4.tgz",
15220
+ "integrity": "sha512-mKKUkUbhPpQlCOfIuZkvSEgktjPFIsZKRRbC6KWVEMvlzblj3i3asQv5ODsrwt0N3pHAEvjP8KTQPHkp0+6jOg=="
15221
+ },
15222
+ "node_modules/refractor/node_modules/is-alphabetical": {
15223
+ "version": "1.0.4",
15224
+ "resolved": "https://registry.npmmirror.com/is-alphabetical/-/is-alphabetical-1.0.4.tgz",
15225
+ "integrity": "sha512-DwzsA04LQ10FHTZuL0/grVDk4rFoVH1pjAToYwBrHSxcrBIGQuXrQMtD5U1b0U2XVgKZCTLLP8u2Qxqhy3l2Vg=="
15226
+ },
15227
+ "node_modules/refractor/node_modules/is-alphanumerical": {
15228
+ "version": "1.0.4",
15229
+ "resolved": "https://registry.npmmirror.com/is-alphanumerical/-/is-alphanumerical-1.0.4.tgz",
15230
+ "integrity": "sha512-UzoZUr+XfVz3t3v4KyGEniVL9BDRoQtY7tOyrRybkVNjDFWyo1yhXNGrrBTQxp3ib9BLAWs7k2YKBQsFRkZG9A==",
15231
+ "dependencies": {
15232
+ "is-alphabetical": "^1.0.0",
15233
+ "is-decimal": "^1.0.0"
15234
+ }
15235
+ },
15236
+ "node_modules/refractor/node_modules/is-decimal": {
15237
+ "version": "1.0.4",
15238
+ "resolved": "https://registry.npmmirror.com/is-decimal/-/is-decimal-1.0.4.tgz",
15239
+ "integrity": "sha512-RGdriMmQQvZ2aqaQq3awNA6dCGtKpiDFcOzrTWrDAT2MiWrKQVPmxLGHl7Y2nNu6led0kEyoX0enY0qXYsv9zw=="
15240
+ },
15241
+ "node_modules/refractor/node_modules/is-hexadecimal": {
15242
+ "version": "1.0.4",
15243
+ "resolved": "https://registry.npmmirror.com/is-hexadecimal/-/is-hexadecimal-1.0.4.tgz",
15244
+ "integrity": "sha512-gyPJuv83bHMpocVYoqof5VDiZveEoGoFL8m3BXNb2VW8Xs+rz9kqO8LOQ5DH6EsuvilT1ApazU0pyl+ytbPtlw=="
15245
+ },
15246
+ "node_modules/refractor/node_modules/parse-entities": {
15247
+ "version": "2.0.0",
15248
+ "resolved": "https://registry.npmmirror.com/parse-entities/-/parse-entities-2.0.0.tgz",
15249
+ "integrity": "sha512-kkywGpCcRYhqQIchaWqZ875wzpS/bMKhz5HnN3p7wveJTkTtyAB/AlnS0f8DFSqYW1T82t6yEAkEcB+A1I3MbQ==",
15250
+ "dependencies": {
15251
+ "character-entities": "^1.0.0",
15252
+ "character-entities-legacy": "^1.0.0",
15253
+ "character-reference-invalid": "^1.0.0",
15254
+ "is-alphanumerical": "^1.0.0",
15255
+ "is-decimal": "^1.0.0",
15256
+ "is-hexadecimal": "^1.0.0"
15257
+ }
15258
+ },
15259
+ "node_modules/refractor/node_modules/prismjs": {
15260
+ "version": "1.27.0",
15261
+ "resolved": "https://registry.npmmirror.com/prismjs/-/prismjs-1.27.0.tgz",
15262
+ "integrity": "sha512-t13BGPUlFDR7wRB5kQDG4jjl7XeuH6jbJGt11JHPL96qwsEHNX2+68tFXqc1/k+/jALsbSWJKUOT/hcYAZ5LkA==",
15263
+ "engines": {
15264
+ "node": ">=6"
15265
+ }
15266
+ },
15267
  "node_modules/regenerate": {
15268
  "version": "1.4.2",
15269
  "resolved": "https://registry.npmmirror.com/regenerate/-/regenerate-1.4.2.tgz",
web/package.json CHANGED
@@ -29,6 +29,7 @@
29
  "react-markdown": "^9.0.1",
30
  "react-pdf-highlighter": "^6.1.0",
31
  "react-string-replace": "^1.1.1",
 
32
  "remark-gfm": "^4.0.0",
33
  "umi": "^4.0.90",
34
  "umi-request": "^1.4.0",
@@ -40,6 +41,7 @@
40
  "@types/lodash": "^4.14.202",
41
  "@types/react": "^18.0.33",
42
  "@types/react-dom": "^18.0.11",
 
43
  "@types/uuid": "^9.0.8",
44
  "@umijs/lint": "^4.1.1",
45
  "@umijs/plugins": "^4.1.0",
 
29
  "react-markdown": "^9.0.1",
30
  "react-pdf-highlighter": "^6.1.0",
31
  "react-string-replace": "^1.1.1",
32
+ "react-syntax-highlighter": "^15.5.0",
33
  "remark-gfm": "^4.0.0",
34
  "umi": "^4.0.90",
35
  "umi-request": "^1.4.0",
 
41
  "@types/lodash": "^4.14.202",
42
  "@types/react": "^18.0.33",
43
  "@types/react-dom": "^18.0.11",
44
+ "@types/react-syntax-highlighter": "^15.5.11",
45
  "@types/uuid": "^9.0.8",
46
  "@umijs/lint": "^4.1.1",
47
  "@umijs/plugins": "^4.1.0",
web/src/pages/chat/chat-container/index.tsx CHANGED
@@ -24,6 +24,7 @@ import classNames from 'classnames';
24
  import { ChangeEventHandler, useCallback, useMemo, useState } from 'react';
25
  import Markdown from 'react-markdown';
26
  import reactStringReplace from 'react-string-replace';
 
27
  import remarkGfm from 'remark-gfm';
28
  import { visitParents } from 'unist-util-visit-parents';
29
  import {
@@ -42,7 +43,11 @@ const getChunkIndex = (match: string) => Number(match.slice(2, -2));
42
  const rehypeWrapReference = () => {
43
  return function wrapTextTransform(tree: any) {
44
  visitParents(tree, 'text', (node, ancestors) => {
45
- if (ancestors.at(-1).tagName !== 'custom-typography') {
 
 
 
 
46
  node.type = 'element';
47
  node.tagName = 'custom-typography';
48
  node.properties = {};
@@ -187,6 +192,23 @@ const MessageItem = ({
187
  }: {
188
  children: string;
189
  }) => renderReference(children),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
  } as any
191
  }
192
  >
@@ -246,7 +268,7 @@ const ChatContainer = () => {
246
 
247
  const handleInputChange: ChangeEventHandler<HTMLInputElement> = (e) => {
248
  const value = e.target.value.trim();
249
- const nextValue = value.replaceAll('\\n', '\n');
250
  setValue(nextValue);
251
  };
252
 
 
24
  import { ChangeEventHandler, useCallback, useMemo, useState } from 'react';
25
  import Markdown from 'react-markdown';
26
  import reactStringReplace from 'react-string-replace';
27
+ import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
28
  import remarkGfm from 'remark-gfm';
29
  import { visitParents } from 'unist-util-visit-parents';
30
  import {
 
43
  const rehypeWrapReference = () => {
44
  return function wrapTextTransform(tree: any) {
45
  visitParents(tree, 'text', (node, ancestors) => {
46
+ const latestAncestor = ancestors.at(-1);
47
+ if (
48
+ latestAncestor.tagName !== 'custom-typography' &&
49
+ latestAncestor.tagName !== 'code'
50
+ ) {
51
  node.type = 'element';
52
  node.tagName = 'custom-typography';
53
  node.properties = {};
 
192
  }: {
193
  children: string;
194
  }) => renderReference(children),
195
+ code(props: any) {
196
+ const { children, className, node, ...rest } = props;
197
+ const match = /language-(\w+)/.exec(className || '');
198
+ return match ? (
199
+ <SyntaxHighlighter
200
+ {...rest}
201
+ PreTag="div"
202
+ language={match[1]}
203
+ >
204
+ {String(children).replace(/\n$/, '')}
205
+ </SyntaxHighlighter>
206
+ ) : (
207
+ <code {...rest} className={className}>
208
+ {children}
209
+ </code>
210
+ );
211
+ },
212
  } as any
213
  }
214
  >
 
268
 
269
  const handleInputChange: ChangeEventHandler<HTMLInputElement> = (e) => {
270
  const value = e.target.value.trim();
271
+ const nextValue = value.replaceAll('\\n', '\n').replaceAll('\\t', '\t');
272
  setValue(nextValue);
273
  };
274