File tree Expand file tree Collapse file tree 7 files changed +135
-18
lines changed Expand file tree Collapse file tree 7 files changed +135
-18
lines changed Original file line number Diff line number Diff line change 119
119
"redirect-webpack-plugin" : " ^1.0.0" ,
120
120
"remark" : " ^13.0.0" ,
121
121
"remark-autolink-headings" : " ^6.0.1" ,
122
- "remark-custom-blockquotes" : " 1.0.0" ,
123
122
"remark-emoji" : " ^2.1.0" ,
124
123
"remark-extract-anchors" : " 1.1.1" ,
125
124
"remark-frontmatter" : " ^3.0.0" ,
137
136
"static-site-generator-webpack-plugin" : " ^3.4.1" ,
138
137
"style-loader" : " ^2.0.0" ,
139
138
"tap-spot" : " ^1.1.1" ,
139
+ "unist-util-visit" : " ^2.0.3" ,
140
140
"webpack" : " ^5.11.1" ,
141
141
"webpack-bundle-analyzer" : " ^4.3.0" ,
142
142
"webpack-cli" : " ^4.3.1" ,
Original file line number Diff line number Diff line change @@ -97,6 +97,7 @@ $topHeightMobileWithBanner: $bannerHeight + $topHeightMobile;
97
97
98
98
p ,
99
99
blockquote ,
100
+ aside ,
100
101
table ,
101
102
pre {
102
103
margin : 1em 0 ;
@@ -159,24 +160,21 @@ $topHeightMobileWithBanner: $bannerHeight + $topHeightMobile;
159
160
}
160
161
}
161
162
162
- blockquote {
163
+ aside {
163
164
border-left : 4px solid #dddddd ;
164
165
padding : 0.75em 1em ;
165
166
color : getColor (dove-grey );
166
- font-style : italic ;
167
-
168
167
> :first-child {
169
168
margin-top : 0 ;
170
169
}
171
170
> :last-child {
172
171
margin-bottom : 0 ;
173
172
}
174
-
175
173
& .tip ,
176
174
& .warning ,
177
175
& .todo {
178
- border-left : none ;
179
- border-radius : 3 px ;
176
+ border-left-width : 3 px ;
177
+ border-left-style : solid ;
180
178
181
179
.tip-content {
182
180
font-style : italic ;
@@ -185,21 +183,33 @@ $topHeightMobileWithBanner: $bannerHeight + $topHeightMobile;
185
183
code {
186
184
color : inherit ;
187
185
}
186
+
187
+ > .tip__prefix ,
188
+ > .warning__prefix ,
189
+ > .todo__prefix {
190
+ text-transform : capitalize ;
191
+ font-weight : 700 ;
192
+ color : #000 ;
193
+ font-size : getFontSize (1 );
194
+ }
188
195
}
189
196
190
197
& .tip {
191
198
background-color : #eaf8ff ;
192
199
color : #4e7182 ;
200
+ border-left-color : darken (#eaf8ff , 40% );
193
201
}
194
202
195
203
& .warning {
196
204
background-color : #fdf5d8 ;
197
205
color : #716b53 ;
206
+ border-left-color : darken (#fdf5d8 , 40% );
198
207
}
199
208
200
209
& .todo {
201
210
background-color : #fbddcd ;
202
211
color : #907a6e ;
212
+ border-left-color : darken (#fbddcd , 40% );
203
213
204
214
.tip-content ::before {
205
215
content : ' [TODO]: ' ;
@@ -208,6 +218,20 @@ $topHeightMobileWithBanner: $bannerHeight + $topHeightMobile;
208
218
}
209
219
}
210
220
221
+ blockquote {
222
+ border-left : 4px solid #dddddd ;
223
+ padding : 0.75em 1em ;
224
+ color : getColor (dove-grey );
225
+ font-style : italic ;
226
+
227
+ > :first-child {
228
+ margin-top : 0 ;
229
+ }
230
+ > :last-child {
231
+ margin-bottom : 0 ;
232
+ }
233
+ }
234
+
211
235
table {
212
236
margin : 1em 0 ;
213
237
Original file line number Diff line number Diff line change
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports [` customize blockquote should transform W> into aside of warning 1` ] = `
4
+ "<aside class =\\"warning\\"><h6 class =\\"warning__prefix\\">warning</h6><p>hello world</p></aside>
5
+ "
6
+ `;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * based on https://github.com/montogeek/remark-custom-blockquotes
3
+ */
4
+
5
+ const visit = require ( 'unist-util-visit' ) ;
6
+ module . exports = function customAsides (
7
+ options = {
8
+ mapping : { } ,
9
+ }
10
+ ) {
11
+ const { mapping } = options ;
12
+ return function transformer ( tree ) {
13
+ // looking for `paragraph` node
14
+ visit ( tree , 'paragraph' , visitor ) ;
15
+ function visitor ( node ) {
16
+ const { children } = node ;
17
+ const textNode = children [ 0 ] . value ;
18
+
19
+ // could be link/etc.
20
+ if ( ! textNode ) return ;
21
+
22
+ // looking for mapping in the beginning
23
+ const className = mapping [ textNode . substr ( 0 , 2 ) ] ;
24
+ // >This is a joke <- ignore this
25
+ // >T hi there
26
+ const hasPostfixWhitespace = textNode . indexOf ( ' ' ) === 2 ;
27
+ if ( className && hasPostfixWhitespace ) {
28
+ // use `aside` element instead of `blockquote`
29
+ // which I believe is more suitable as per https://developer.mozilla.org/en-US/docs/Web/HTML/Element/aside
30
+ node . data = {
31
+ hName : 'aside' ,
32
+ hProperties : {
33
+ className,
34
+ } ,
35
+ } ;
36
+
37
+ // remove custom characters from paragraph
38
+ node . children = [
39
+ {
40
+ type : 'heading' ,
41
+ depth : 6 ,
42
+ data : {
43
+ // see https://github.com/syntax-tree/mdast-util-to-hast#hname
44
+ // add a className to heading
45
+ hProperties : {
46
+ className : `${ className } __prefix` ,
47
+ } ,
48
+ } ,
49
+ children : [
50
+ {
51
+ type : 'text' ,
52
+ value : `${ className } ` ,
53
+ } ,
54
+ ] ,
55
+ } ,
56
+ {
57
+ type : 'paragraph' ,
58
+ children : [
59
+ {
60
+ ...children [ 0 ] ,
61
+ value : children [ 0 ] . value . slice ( 3 ) ,
62
+ } ,
63
+ ...children . slice ( 1 ) ,
64
+ ] ,
65
+ } ,
66
+ ] ;
67
+ }
68
+ }
69
+ } ;
70
+ } ;
Original file line number Diff line number Diff line change
1
+ import remark from 'remark' ;
2
+ describe ( 'customize blockquote' , ( ) => {
3
+ it ( 'should transform W> into aside of warning' , ( ) => {
4
+ remark ( )
5
+ . use ( require ( './index.js' ) , {
6
+ mapping : {
7
+ 'W>' : 'warning' ,
8
+ } ,
9
+ } )
10
+ . use ( require ( 'remark-html' ) )
11
+ . process (
12
+ `
13
+ W> hello world
14
+ ` ,
15
+ function ( err , { contents } ) {
16
+ expect ( err ) . toBeNull ( ) ;
17
+ expect ( contents ) . toContain ( '<aside class="warning"' ) ;
18
+ expect ( contents ) . toContain ( '<h6 class="warning__prefix"' ) ;
19
+ expect ( contents ) . toContain ( 'warning' ) ;
20
+ expect ( contents ) . toMatchSnapshot ( ) ;
21
+ }
22
+ ) ;
23
+ } ) ;
24
+ } ) ;
Original file line number Diff line number Diff line change @@ -9,14 +9,14 @@ const mdPlugins = [
9
9
remarkResponsiveTable ,
10
10
require ( 'remark-emoji' ) ,
11
11
[
12
- require ( 'remark-custom-blockquotes ' ) ,
12
+ require ( './src/ remark-plugins/remark- custom-asides/index.js ' ) ,
13
13
{
14
14
mapping : {
15
15
'T>' : 'tip' ,
16
16
'W>' : 'warning' ,
17
- '?>' : 'todo'
18
- }
19
- }
17
+ '?>' : 'todo' ,
18
+ } ,
19
+ } ,
20
20
] ,
21
21
[
22
22
require ( 'remark-autolink-headings' ) ,
Original file line number Diff line number Diff line change @@ -11218,13 +11218,6 @@ remark-autolink-headings@^6.0.1:
11218
11218
extend "^3.0.0"
11219
11219
unist-util-visit "^2.0.0"
11220
11220
11221
- remark-custom-blockquotes@1.0.0:
11222
- version "1.0.0"
11223
- resolved "https://registry.yarnpkg.com/remark-custom-blockquotes/-/remark-custom-blockquotes-1.0.0.tgz#82ed4cebf45255a0d07ba81696f909c23b1d749d"
11224
- integrity sha512-R6/tiD4RE7rIaPAmZcVdbddH35DJraxNiVWo8nwF4QIhjwthClAkrzDzKcRHzf2sHL3OlG5jOBtwvZX7Dwww/w==
11225
- dependencies:
11226
- unist-util-visit "1.3.1"
11227
-
11228
11221
remark-emoji@^2.1.0:
11229
11222
version "2.1.0"
11230
11223
resolved "https://registry.yarnpkg.com/remark-emoji/-/remark-emoji-2.1.0.tgz#69165d1181b98a54ad5d9ef811003d53d7ebc7db"
You can’t perform that action at this time.
0 commit comments