File tree 3 files changed +25
-1
lines changed 3 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -3,11 +3,12 @@ module.exports = code
3
3
var repeat = require ( 'repeat-string' )
4
4
var streak = require ( 'longest-streak' )
5
5
var formatCodeAsIndented = require ( '../util/format-code-as-indented' )
6
+ var checkFence = require ( '../util/check-fence' )
6
7
var indentLines = require ( '../util/indent-lines' )
7
8
var safe = require ( '../util/safe' )
8
9
9
10
function code ( node , _ , context ) {
10
- var marker = context . options . fence || '`'
11
+ var marker = checkFence ( context )
11
12
var raw = node . value || ''
12
13
var suffix = marker === '`' ? 'GraveAccent' : 'Tilde'
13
14
var value
Original file line number Diff line number Diff line change
1
+ module . exports = checkFence
2
+
3
+ function checkFence ( context ) {
4
+ var marker = context . options . fence || '`'
5
+
6
+ if ( marker !== '`' && marker !== '~' ) {
7
+ throw new Error (
8
+ 'Cannot serialize code with `' +
9
+ marker +
10
+ '` for `options.fence`, expected `` ` `` or `~`'
11
+ )
12
+ }
13
+
14
+ return marker
15
+ }
Original file line number Diff line number Diff line change @@ -509,6 +509,14 @@ test('break', function (t) {
509
509
test ( 'code (flow)' , function ( t ) {
510
510
t . equal ( to ( { type : 'code' } ) , '```\n```' , 'should support empty code' )
511
511
512
+ t . throws (
513
+ function ( ) {
514
+ to ( { type : 'code' } , { fence : '+' } )
515
+ } ,
516
+ / C a n n o t s e r i a l i z e c o d e w i t h ` \+ ` f o r ` o p t i o n s \. f e n c e ` , e x p e c t e d ` ` ` ` ` o r ` ~ ` / ,
517
+ 'should throw on when given an incorrect `fence`'
518
+ )
519
+
512
520
t . equal (
513
521
to ( { type : 'code' , value : 'a' } ) ,
514
522
' a' ,
You can’t perform that action at this time.
0 commit comments