|
@ -229,6 +229,7 @@ class RoboFile extends \Robo\Tasks { |
|
|
} |
|
|
} |
|
|
// download highlight.js |
|
|
// download highlight.js |
|
|
$t->addCode(function() use ($languages, $tmp, $themeout) { |
|
|
$t->addCode(function() use ($languages, $tmp, $themeout) { |
|
|
|
|
|
// compile the list of desired language (enumerated above) into an application/x-www-form-urlencoded body |
|
|
$post = http_build_query((function($langs) { |
|
|
$post = http_build_query((function($langs) { |
|
|
$out = []; |
|
|
$out = []; |
|
|
foreach($langs as $l) { |
|
|
foreach($langs as $l) { |
|
@ -236,6 +237,7 @@ class RoboFile extends \Robo\Tasks { |
|
|
} |
|
|
} |
|
|
return $out; |
|
|
return $out; |
|
|
})($languages)); |
|
|
})($languages)); |
|
|
|
|
|
// get the two cross-site request forgery tokens the Highlight.js Web site requires |
|
|
$conn = @fopen("https://highlightjs.org/download/", "r"); |
|
|
$conn = @fopen("https://highlightjs.org/download/", "r"); |
|
|
if ($conn === false) { |
|
|
if ($conn === false) { |
|
|
throw new Exception("Unable to download Highlight.js"); |
|
|
throw new Exception("Unable to download Highlight.js"); |
|
@ -247,7 +249,9 @@ class RoboFile extends \Robo\Tasks { |
|
|
} |
|
|
} |
|
|
$token = stream_get_contents($conn); |
|
|
$token = stream_get_contents($conn); |
|
|
preg_match("/<input type='hidden' name='csrfmiddlewaretoken' value='([^']*)'/", $token, $token); |
|
|
preg_match("/<input type='hidden' name='csrfmiddlewaretoken' value='([^']*)'/", $token, $token); |
|
|
|
|
|
// add the form CSRF token to the POST body |
|
|
$post = "csrfmiddlewaretoken={$token[1]}&$post"; |
|
|
$post = "csrfmiddlewaretoken={$token[1]}&$post"; |
|
|
|
|
|
// download a copy of Highlight.js with the desired languages to a temporary file |
|
|
$hljs = @file_get_contents("https://highlightjs.org/download/", false, stream_context_create(['http' => [ |
|
|
$hljs = @file_get_contents("https://highlightjs.org/download/", false, stream_context_create(['http' => [ |
|
|
'method' => "POST", |
|
|
'method' => "POST", |
|
|
'content' => $post, |
|
|
'content' => $post, |
|
@ -262,6 +266,7 @@ class RoboFile extends \Robo\Tasks { |
|
|
} else { |
|
|
} else { |
|
|
file_put_contents($tmp."highlightjs.zip", $hljs); |
|
|
file_put_contents($tmp."highlightjs.zip", $hljs); |
|
|
} |
|
|
} |
|
|
|
|
|
// extract the downloaded zip file and keep only the JS file |
|
|
$this->taskExtract($tmp."highlightjs.zip")->to($tmp."hljs")->run(); |
|
|
$this->taskExtract($tmp."highlightjs.zip")->to($tmp."hljs")->run(); |
|
|
$this->taskFilesystemStack()->copy($tmp."hljs".\DIRECTORY_SEPARATOR."highlight.pack.js", $themeout."highlight.pack.js")->run(); |
|
|
$this->taskFilesystemStack()->copy($tmp."hljs".\DIRECTORY_SEPARATOR."highlight.pack.js", $themeout."highlight.pack.js")->run(); |
|
|
}, "downloadHighlightjs"); |
|
|
}, "downloadHighlightjs"); |
|
|