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 1
1
<?php
2
2
3
3
class 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 ];
11
11
}
12
- }
13
- return $ text;
12
+ return ' <script src=" ' . $ src . ' "></script> ' ;
13
+ }, $ text );
14
14
}
15
-
16
15
}
17
-
Original file line number Diff line number Diff line change @@ -102,6 +102,12 @@ Forum button. You should see something like this.
102
102
103
103
And that's it. You're all set.
104
104
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
+
105
111
### Settings
106
112
107
113
There really aren't any. Just paste in the link.
Original file line number Diff line number Diff line change 2
2
3
3
defined ('MOODLE_INTERNAL ' ) || die ();
4
4
5
- $ plugin ->version = '2015092400 ' ;
5
+ $ plugin ->version = '2017102100 ' ;
6
6
$ plugin ->requires = '2014051200 ' ; // 2.7
7
7
$ plugin ->cron = 0 ;
8
8
$ plugin ->component = 'filter_gistembed ' ;
9
9
$ 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