File tree Expand file tree Collapse file tree 3 files changed +20
-7
lines changed Expand file tree Collapse file tree 3 files changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -45,11 +45,11 @@ so they cannot be interpreted in their native form by the browser.
4545
4646In order to use it,
4747just prepend this fragment to the URL of any HTML file:
48- ** [ https://html-preview.github.io/ ?] ( https://html-preview.github.io/? ) **
48+ ** [ https://html-preview.github.io/?url= ] ( https://html-preview.github.io/?url= ) **
4949e.g.:
5050
51- - < https://html-preview.github.io/?https://github.com/twbs/bootstrap/gh-pages/2.3.2/index.html >
52- - < https://html-preview.github.io/?https://github.com/documentcloud/backbone/blob/master/examples/todos/index.html >
51+ - < https://html-preview.github.io/?url= https://github.com/twbs/bootstrap/gh-pages/2.3.2/index.html >
52+ - < https://html-preview.github.io/?url= https://github.com/documentcloud/backbone/blob/master/examples/todos/index.html >
5353
5454What it does:
5555
Original file line number Diff line number Diff line change 4646 * NOTE: This function 1 of 2 that is git-forge specific.
4747 */
4848 const getRawFileUrl = function ( ) {
49- return location . search . substring ( 1 )
49+ if ( location . search . length === 0 ) {
50+ return null ;
51+ }
52+
53+ const params = new URLSearchParams ( location . search ) ;
54+ const previewFileUrl = params . get ( 'url' ) ;
55+ if ( previewFileUrl === null ) {
56+ const errP = document . createElement ( 'p' ) ;
57+ errP . innerHTML = 'Please use "...?url=..." vs the old "...?..."!' ;
58+ document . body . appendChild ( errP ) ;
59+ throw new SyntaxError ( 'Missing required parameter "url"!' ) ;
60+ }
61+
62+ return previewFileUrl
5063 . replace ( / \/ \/ g i t h u b \. c o m / , '//raw.githubusercontent.com' )
5164 . replace ( / \/ b l o b \/ / , '/' ) . replace ( / \/ r a w \/ / , '/' ) ;
5265 } ;
152165 * @returns {string } The re-routed (for preview) version of the provided URL
153166 */
154167 const rewrite = function ( url ) {
155- return location . origin + location . pathname + '?' + url ;
168+ return location . origin + location . pathname + '?url= ' + url ;
156169 } ;
157170
158171 /**
171184 } ;
172185
173186 const serviceBase = getServiceBase ( ) ;
174- document . getElementById ( 'service_base' ) . innerHTML = serviceBase + '?' ;
187+ document . getElementById ( 'service_base' ) . innerHTML = serviceBase + '?url= ' ;
175188
176189 const previewForm = document . getElementById ( 'previewform' ) ;
177190
Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ <h1>Git-Forge HTML Preview</h1>
4747 </ p >
4848 < p >
4949 or prepend to the URL:
50- < code > < strong id ="service_base "> https://html-preview.github.io/?</ strong > https://github.com/twbs/bootstrap/blob/gh-pages/2.3.2/index.html</ code >
50+ < code > < strong id ="service_base "> https://html-preview.github.io/?url= </ strong > https://github.com/twbs/bootstrap/blob/gh-pages/2.3.2/index.html</ code >
5151 </ p >
5252 < p >
5353 Contribute on < a href ="https://github.com/html-preview/html-preview.github.io "> GitHub</ a >
You can’t perform that action at this time.
0 commit comments