File tree Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -2,10 +2,17 @@ import React from 'react'
2
2
import rehypeReact , { ComponentProps , ComponentPropsWithNode } from 'rehype-react'
3
3
import unified from 'unified'
4
4
import { Node } from 'unist'
5
+ import ReactGist from 'react-gist'
5
6
6
7
import { NextLink } from '@components/NextLink'
7
8
import { NextImage } from '@components/NextImage'
8
9
10
+ const gist_regex = / h t t p s : \/ \/ g i s t .g i t h u b .c o m \/ \S + \/ ( [ a - f 0 - 9 ] + ) \. j s / g
11
+
12
+ type ScriptNode = {
13
+ src : string
14
+ }
15
+
9
16
/* eslint-disable react/display-name */
10
17
const options = {
11
18
createElement : React . createElement ,
@@ -14,6 +21,15 @@ const options = {
14
21
components : {
15
22
Link : ( props : ComponentProps ) => < NextLink { ...( props as ComponentPropsWithNode ) } /> ,
16
23
Image : ( props : ComponentProps ) => < NextImage { ...( props as ComponentPropsWithNode ) } /> ,
24
+ script : ( props : ComponentProps ) => {
25
+ const properties = props as ScriptNode
26
+ const myRegexp = new RegExp ( gist_regex ) ;
27
+ const match = myRegexp . exec ( properties . src ) ;
28
+ if ( ! ! match && match . length > 1 ) {
29
+ return < ReactGist id = { match [ 1 ] } />
30
+ }
31
+ return null ;
32
+ }
17
33
} ,
18
34
}
19
35
Original file line number Diff line number Diff line change 53
53
"probe-image-size" : " ^7.2.2" ,
54
54
"react" : " 17.0.2" ,
55
55
"react-dom" : " 17.0.2" ,
56
+ "react-gist" : " ^1.2.4" ,
56
57
"react-is" : " ^17.0.2" ,
57
58
"refractor" : " ^3.3.1" ,
58
59
"rehype" : " ^11.0.0" ,
Original file line number Diff line number Diff line change @@ -4036,6 +4036,11 @@ react-dom@17.0.2:
4036
4036
object-assign "^4.1.1"
4037
4037
scheduler "^0.20.2"
4038
4038
4039
+ react-gist@^1.2.4 :
4040
+ version "1.2.4"
4041
+ resolved "https://registry.yarnpkg.com/react-gist/-/react-gist-1.2.4.tgz#4ee71f24cc6f60836354e2ad6e30f6d24e06e0f7"
4042
+ integrity sha512-uDgPJ08IJsl/7auK3CS53JKGC1P/X7tNCzo9k0r6D/5l+ilsxE1+SAaylJCh0aeyZoJOoxQikKU+MHsAvA9iFw==
4043
+
4039
4044
react-is@17.0.2, react-is@^17.0.1, react-is@^17.0.2 :
4040
4045
version "17.0.2"
4041
4046
resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0"
You can’t perform that action at this time.
0 commit comments