File tree Expand file tree Collapse file tree 3 files changed +17
-13
lines changed Expand file tree Collapse file tree 3 files changed +17
-13
lines changed Original file line number Diff line number Diff line change 11<?php
22
33class filter_gistembed extends moodle_text_filter {
4-
5- public function filter ($ text , array $ options = array ()) {
6- $ cnt = preg_match_all ( '/https?:\/\/gist\.github\.com\/(.*?)\/([a-f0-9]*)/ ' , $ text , $ matches );
7- if ( $ cnt ) {
8- for ( $ i = 0 ; $ i < $ cnt ; ++ $ i ) {
9- $ script = ' <script src="https://gist.github.com/ ' . $ matches [1 ][ $ i ] . ' / ' . $ matches [ 2 ][ $ i ] . ' .js"></script> ' ;
10- $ text = str_replace ( $ matches [0 ][ $ i ], $ script , $ text );
4+
5+ public function filter ( $ text , array $ options = [ ] ) {
6+ return preg_replace_callback ( '/https?:\/\/gist\.github\.com\/(.*?)\/([a-f0-9]*)(\?file=[^\s<>]*)? / ' , function ( $ matches ) {
7+ //echo '<pre>' . print_r($matches, true) . '</pre>';
8+ $ src = ' https://gist.github.com/ ' . $ matches [ 1 ] . ' / ' . $ matches [ 2 ] . ' .js ' ;
9+ if (! empty ( $ matches [3 ])) {
10+ $ src .= $ matches [3 ];
1111 }
12- }
13- return $ text;
12+ return ' <script src=" ' . $ src . ' "></script> ' ;
13+ }, $ text );
1414 }
15-
1615}
17-
Original file line number Diff line number Diff line change @@ -102,6 +102,12 @@ Forum button. You should see something like this.
102102
103103And that's it. You're all set.
104104
105+ #### Embedding single files
106+ If you're embedding a gist with multiple files, normally all files will embed. If you'd rather
107+ embed only a single file add ` ?file=Filename.ext ` to the end of the URL that you paste into
108+ Moodle and only that file will embed. If that file doesn't exist in your gist nothing
109+ will embed.
110+
105111### Settings
106112
107113There really aren't any. Just paste in the link.
Original file line number Diff line number Diff line change 22
33defined ('MOODLE_INTERNAL ' ) || die ();
44
5- $ plugin ->version = '2015092400 ' ;
5+ $ plugin ->version = '2017102100 ' ;
66$ plugin ->requires = '2014051200 ' ; // 2.7
77$ plugin ->cron = 0 ;
88$ plugin ->component = 'filter_gistembed ' ;
99$ plugin ->maturity = MATURITY_BETA ;
10- $ plugin ->release = '0.1 ' ;
10+ $ plugin ->release = '0.2 ' ;
You can’t perform that action at this time.
0 commit comments