File tree 2 files changed +30
-0
lines changed
2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 8
8
use Hyde \Framework \Services \Markdown \CodeblockFilepathProcessor ;
9
9
use Hyde \Framework \Services \Markdown \ShortcodeProcessor ;
10
10
use League \CommonMark \CommonMarkConverter ;
11
+ use League \CommonMark \Extension \DisallowedRawHtml \DisallowedRawHtmlExtension ;
11
12
use League \CommonMark \Extension \HeadingPermalink \HeadingPermalinkExtension ;
12
13
use Torchlight \Commonmark \V2 \TorchlightExtension ;
13
14
@@ -85,6 +86,16 @@ protected function setupConverter(): void
85
86
$ this ->addExtension (TorchlightExtension::class);
86
87
}
87
88
89
+ if (config ('markdown.allow_html ' , false )) {
90
+ $ this ->addExtension (DisallowedRawHtmlExtension::class);
91
+
92
+ $ this ->config = array_merge ([
93
+ 'disallowed_raw_html ' => [
94
+ 'disallowed_tags ' => [],
95
+ ],
96
+ ], $ this ->config );
97
+ }
98
+
88
99
// Add any custom extensions defined in config
89
100
foreach (config ('markdown.extensions ' , []) as $ extensionClassName ) {
90
101
$ this ->addExtension ($ extensionClassName );
Original file line number Diff line number Diff line change @@ -77,4 +77,23 @@ public function test_bladedown_can_be_enabled()
77
77
$ service ->addFeature ('bladedown ' )->parse ();
78
78
$ this ->assertEquals ("Hello World! \n" , $ service ->parse ());
79
79
}
80
+
81
+ // test raw html tags are stripped by default
82
+ public function test_raw_html_tags_are_stripped_by_default ()
83
+ {
84
+ $ markdown = '<p>foo</p><style>bar</style><script>hat</script> ' ;
85
+ $ service = new MarkdownConverterService ($ markdown );
86
+ $ html = $ service ->parse ();
87
+ $ this ->assertEquals ("<p>foo</p><style>bar</style><script>hat</script> \n" , $ html );
88
+ }
89
+
90
+ // test raw html tags are not stripped when explicitly enabled
91
+ public function test_raw_html_tags_are_not_stripped_when_explicitly_enabled ()
92
+ {
93
+ config (['markdown.allow_html ' =>true ]);
94
+ $ markdown = '<p>foo</p><style>bar</style><script>hat</script> ' ;
95
+ $ service = new MarkdownConverterService ($ markdown );
96
+ $ html = $ service ->parse ();
97
+ $ this ->assertEquals ("<p>foo</p><style>bar</style><script>hat</script> \n" , $ html );
98
+ }
80
99
}
You can’t perform that action at this time.
0 commit comments