File tree Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -3,11 +3,12 @@ module.exports = code
33var repeat = require ( 'repeat-string' )
44var streak = require ( 'longest-streak' )
55var formatCodeAsIndented = require ( '../util/format-code-as-indented' )
6+ var checkFence = require ( '../util/check-fence' )
67var indentLines = require ( '../util/indent-lines' )
78var safe = require ( '../util/safe' )
89
910function code ( node , _ , context ) {
10- var marker = context . options . fence || '`'
11+ var marker = checkFence ( context )
1112 var raw = node . value || ''
1213 var suffix = marker === '`' ? 'GraveAccent' : 'Tilde'
1314 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) {
509509test ( 'code (flow)' , function ( t ) {
510510 t . equal ( to ( { type : 'code' } ) , '```\n```' , 'should support empty code' )
511511
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+
512520 t . equal (
513521 to ( { type : 'code' , value : 'a' } ) ,
514522 ' a' ,
You can’t perform that action at this time.
0 commit comments