@@ -900,68 +900,10 @@ describe('Marked renderer', () => {
900
900
} ) ;
901
901
} ) ;
902
902
903
- describe ( 'nunjucks' , ( ) => {
904
- const hexo = new Hexo ( __dirname , { silent : true } ) ;
905
- const loremFn = ( ) => { return 'ipsum' ; } ;
906
- const engine = 'md' ;
907
-
908
- before ( async ( ) => {
909
- await hexo . init ( ) ;
910
- hexo . extend . tag . register ( 'lorem' , loremFn ) ;
911
- hexo . extend . renderer . register ( 'md' , 'html' , require ( '../lib/renderer' ) , true ) ;
912
- } ) ;
913
-
914
- beforeEach ( ( ) => { hexo . config . marked = { } ; } ) ;
915
-
916
- it ( 'default' , async ( ) => {
917
- const result = await hexo . post . render ( null , { content : '**foo** {% lorem %}' , engine } ) ;
918
- result . content . should . eql ( '<p><strong>foo</strong> ipsum</p>\n' ) ;
919
- } ) ;
920
-
921
- it ( 'enable disableNunjucks' , async ( ) => {
922
- const renderer = hexo . render . renderer . get ( 'md' ) ;
923
- renderer . disableNunjucks = true ;
924
- hexo . extend . renderer . register ( 'md' , 'html' , renderer , true ) ;
925
- const result = await hexo . post . render ( null , { content : '**foo** {% lorem %}' , engine } ) ;
926
- result . content . should . eql ( '<p><strong>foo</strong> {% lorem %}</p>\n' ) ;
927
- } ) ;
928
- } ) ;
929
-
930
- describe ( 'sanitize HTML with DOMPurify' , ( ) => {
931
- const body = [
932
- '**safe markdown**' ,
933
- '' ,
934
- '<a onclick="alert(1)">unsafe link</a>' ,
935
- '' ,
936
- '[Hexo](http://hexo.io)'
937
- ] . join ( '\n' ) ;
938
-
939
- it ( 'sanitize enabled, default options' , ( ) => {
940
- hexo . config . marked . dompurify = true ;
941
- const result = r ( { text : body } ) ;
942
-
943
- result . should . eql ( [
944
- '<p><strong>safe markdown</strong></p>\n' ,
945
- '<p><a>unsafe link</a></p>\n' ,
946
- '<p><a href="http://hexo.io/">Hexo</a></p>\n'
947
- ] . join ( '' ) ) ;
948
- } ) ;
949
-
950
- it ( 'sanitize enabled, with options' , ( ) => {
951
- hexo . config . marked . dompurify = { FORBID_TAGS : [ 'strong' ] } ;
952
- const result = r ( { text : body } ) ;
953
-
954
- result . should . eql ( [
955
- '<p>safe markdown</p>\n' ,
956
- '<p><a>unsafe link</a></p>\n' ,
957
- '<p><a href="http://hexo.io/">Hexo</a></p>\n'
958
- ] . join ( '' ) ) ;
959
- } ) ;
960
- } ) ;
961
-
962
- // Put this part at the end, as the filter might permanently modify the tokenizer
963
- // thereby affecting other test cases
964
903
describe ( 'exec filter to extend' , ( ) => {
904
+ // Clear the cache, as the filter might permanently modify the tokenizer
905
+ // thereby affecting other test cases
906
+ delete require . cache [ require . resolve ( '../lib/renderer' ) ] ;
965
907
const hexo = new Hexo ( __dirname , { silent : true } ) ;
966
908
hexo . config . marked = { } ;
967
909
@@ -1045,4 +987,63 @@ describe('Marked renderer', () => {
1045
987
result . should . eql ( `<p class="math block">${ escapeHTML ( 'E=mc^2' ) } </p>\n` ) ;
1046
988
} ) ;
1047
989
} ) ;
990
+
991
+ describe ( 'nunjucks' , ( ) => {
992
+ const hexo = new Hexo ( __dirname , { silent : true } ) ;
993
+ const loremFn = ( ) => { return 'ipsum' ; } ;
994
+ const engine = 'md' ;
995
+
996
+ before ( async ( ) => {
997
+ await hexo . init ( ) ;
998
+ hexo . extend . tag . register ( 'lorem' , loremFn ) ;
999
+ hexo . extend . renderer . register ( 'md' , 'html' , require ( '../lib/renderer' ) , true ) ;
1000
+ } ) ;
1001
+
1002
+ beforeEach ( ( ) => { hexo . config . marked = { } ; } ) ;
1003
+
1004
+ it ( 'default' , async ( ) => {
1005
+ const result = await hexo . post . render ( null , { content : '**foo** {% lorem %}' , engine } ) ;
1006
+ result . content . should . eql ( '<p><strong>foo</strong> ipsum</p>\n' ) ;
1007
+ } ) ;
1008
+
1009
+ it ( 'enable disableNunjucks' , async ( ) => {
1010
+ const renderer = hexo . render . renderer . get ( 'md' ) ;
1011
+ renderer . disableNunjucks = true ;
1012
+ hexo . extend . renderer . register ( 'md' , 'html' , renderer , true ) ;
1013
+ const result = await hexo . post . render ( null , { content : '**foo** {% lorem %}' , engine } ) ;
1014
+ result . content . should . eql ( '<p><strong>foo</strong> {% lorem %}</p>\n' ) ;
1015
+ } ) ;
1016
+ } ) ;
1017
+
1018
+ describe ( 'sanitize HTML with DOMPurify' , ( ) => {
1019
+ const body = [
1020
+ '**safe markdown**' ,
1021
+ '' ,
1022
+ '<a onclick="alert(1)">unsafe link</a>' ,
1023
+ '' ,
1024
+ '[Hexo](http://hexo.io)'
1025
+ ] . join ( '\n' ) ;
1026
+
1027
+ it ( 'sanitize enabled, default options' , ( ) => {
1028
+ hexo . config . marked . dompurify = true ;
1029
+ const result = r ( { text : body } ) ;
1030
+
1031
+ result . should . eql ( [
1032
+ '<p><strong>safe markdown</strong></p>\n' ,
1033
+ '<p><a>unsafe link</a></p>\n' ,
1034
+ '<p><a href="http://hexo.io/">Hexo</a></p>\n'
1035
+ ] . join ( '' ) ) ;
1036
+ } ) ;
1037
+
1038
+ it ( 'sanitize enabled, with options' , ( ) => {
1039
+ hexo . config . marked . dompurify = { FORBID_TAGS : [ 'strong' ] } ;
1040
+ const result = r ( { text : body } ) ;
1041
+
1042
+ result . should . eql ( [
1043
+ '<p>safe markdown</p>\n' ,
1044
+ '<p><a>unsafe link</a></p>\n' ,
1045
+ '<p><a href="http://hexo.io/">Hexo</a></p>\n'
1046
+ ] . join ( '' ) ) ;
1047
+ } ) ;
1048
+ } ) ;
1048
1049
} ) ;
0 commit comments