Update hljs to 9.8.0

This commit is contained in:
Rodrigo Fernandes 2016-12-11 15:21:58 +00:00
parent 63e4caf59c
commit 22b9783d07
No known key found for this signature in database
GPG key ID: 08E3C5F38969078E
6 changed files with 122 additions and 93 deletions

View file

@ -33,7 +33,7 @@
<!-- Custom styles for this template --> <!-- Custom styles for this template -->
<link href="main.min.css" rel="stylesheet"> <link href="main.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.6.0/styles/github.min.css"> <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.8.0/styles/github.min.css">
<!-- diff2html --> <!-- diff2html -->
<link rel="stylesheet" type="text/css" href="assets/diff2html.min.css"> <link rel="stylesheet" type="text/css" href="assets/diff2html.min.css">
@ -240,8 +240,8 @@
} }
</script> </script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.6.0/highlight.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.8.0/highlight.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.6.0/languages/scala.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.8.0/languages/scala.min.js"></script>
<!-- diff2html --> <!-- diff2html -->
<script type="text/javascript" src="assets/diff2html.min.js"></script> <script type="text/javascript" src="assets/diff2html.min.js"></script>

View file

@ -21,6 +21,28 @@
arrayBuffer: 'ArrayBuffer' in self arrayBuffer: 'ArrayBuffer' in self
} }
if (support.arrayBuffer) {
var viewClasses = [
'[object Int8Array]',
'[object Uint8Array]',
'[object Uint8ClampedArray]',
'[object Int16Array]',
'[object Uint16Array]',
'[object Int32Array]',
'[object Uint32Array]',
'[object Float32Array]',
'[object Float64Array]'
]
var isDataView = function(obj) {
return obj && DataView.prototype.isPrototypeOf(obj)
}
var isArrayBufferView = ArrayBuffer.isView || function(obj) {
return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1
}
}
function normalizeName(name) { function normalizeName(name) {
if (typeof name !== 'string') { if (typeof name !== 'string') {
name = String(name) name = String(name)
@ -74,12 +96,8 @@
Headers.prototype.append = function(name, value) { Headers.prototype.append = function(name, value) {
name = normalizeName(name) name = normalizeName(name)
value = normalizeValue(value) value = normalizeValue(value)
var list = this.map[name] var oldValue = this.map[name]
if (!list) { this.map[name] = oldValue ? oldValue+','+value : value
list = []
this.map[name] = list
}
list.push(value)
} }
Headers.prototype['delete'] = function(name) { Headers.prototype['delete'] = function(name) {
@ -87,12 +105,8 @@
} }
Headers.prototype.get = function(name) { Headers.prototype.get = function(name) {
var values = this.map[normalizeName(name)] name = normalizeName(name)
return values ? values[0] : null return this.has(name) ? this.map[name] : null
}
Headers.prototype.getAll = function(name) {
return this.map[normalizeName(name)] || []
} }
Headers.prototype.has = function(name) { Headers.prototype.has = function(name) {
@ -100,15 +114,15 @@
} }
Headers.prototype.set = function(name, value) { Headers.prototype.set = function(name, value) {
this.map[normalizeName(name)] = [normalizeValue(value)] this.map[normalizeName(name)] = normalizeValue(value)
} }
Headers.prototype.forEach = function(callback, thisArg) { Headers.prototype.forEach = function(callback, thisArg) {
Object.getOwnPropertyNames(this.map).forEach(function(name) { for (var name in this.map) {
this.map[name].forEach(function(value) { if (this.map.hasOwnProperty(name)) {
callback.call(thisArg, value, name, this) callback.call(thisArg, this.map[name], name, this)
}, this) }
}, this) }
} }
Headers.prototype.keys = function() { Headers.prototype.keys = function() {
@ -153,14 +167,36 @@
function readBlobAsArrayBuffer(blob) { function readBlobAsArrayBuffer(blob) {
var reader = new FileReader() var reader = new FileReader()
var promise = fileReaderReady(reader)
reader.readAsArrayBuffer(blob) reader.readAsArrayBuffer(blob)
return fileReaderReady(reader) return promise
} }
function readBlobAsText(blob) { function readBlobAsText(blob) {
var reader = new FileReader() var reader = new FileReader()
var promise = fileReaderReady(reader)
reader.readAsText(blob) reader.readAsText(blob)
return fileReaderReady(reader) return promise
}
function readArrayBufferAsText(buf) {
var view = new Uint8Array(buf)
var chars = new Array(view.length)
for (var i = 0; i < view.length; i++) {
chars[i] = String.fromCharCode(view[i])
}
return chars.join('')
}
function bufferClone(buf) {
if (buf.slice) {
return buf.slice(0)
} else {
var view = new Uint8Array(buf.byteLength)
view.set(new Uint8Array(buf))
return view.buffer
}
} }
function Body() { function Body() {
@ -168,7 +204,9 @@
this._initBody = function(body) { this._initBody = function(body) {
this._bodyInit = body this._bodyInit = body
if (typeof body === 'string') { if (!body) {
this._bodyText = ''
} else if (typeof body === 'string') {
this._bodyText = body this._bodyText = body
} else if (support.blob && Blob.prototype.isPrototypeOf(body)) { } else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
this._bodyBlob = body this._bodyBlob = body
@ -176,11 +214,12 @@
this._bodyFormData = body this._bodyFormData = body
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) { } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
this._bodyText = body.toString() this._bodyText = body.toString()
} else if (!body) { } else if (support.arrayBuffer && support.blob && isDataView(body)) {
this._bodyText = '' this._bodyArrayBuffer = bufferClone(body.buffer)
} else if (support.arrayBuffer && ArrayBuffer.prototype.isPrototypeOf(body)) { // IE 10-11 can't handle a DataView body.
// Only support ArrayBuffers for POST method. this._bodyInit = new Blob([this._bodyArrayBuffer])
// Receiving ArrayBuffers happens via Blobs, instead. } else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) {
this._bodyArrayBuffer = bufferClone(body)
} else { } else {
throw new Error('unsupported BodyInit type') throw new Error('unsupported BodyInit type')
} }
@ -205,6 +244,8 @@
if (this._bodyBlob) { if (this._bodyBlob) {
return Promise.resolve(this._bodyBlob) return Promise.resolve(this._bodyBlob)
} else if (this._bodyArrayBuffer) {
return Promise.resolve(new Blob([this._bodyArrayBuffer]))
} else if (this._bodyFormData) { } else if (this._bodyFormData) {
throw new Error('could not read FormData body as blob') throw new Error('could not read FormData body as blob')
} else { } else {
@ -213,27 +254,28 @@
} }
this.arrayBuffer = function() { this.arrayBuffer = function() {
return this.blob().then(readBlobAsArrayBuffer) if (this._bodyArrayBuffer) {
} return consumed(this) || Promise.resolve(this._bodyArrayBuffer)
this.text = function() {
var rejected = consumed(this)
if (rejected) {
return rejected
}
if (this._bodyBlob) {
return readBlobAsText(this._bodyBlob)
} else if (this._bodyFormData) {
throw new Error('could not read FormData body as text')
} else { } else {
return Promise.resolve(this._bodyText) return this.blob().then(readBlobAsArrayBuffer)
} }
} }
} else { }
this.text = function() {
var rejected = consumed(this) this.text = function() {
return rejected ? rejected : Promise.resolve(this._bodyText) var rejected = consumed(this)
if (rejected) {
return rejected
}
if (this._bodyBlob) {
return readBlobAsText(this._bodyBlob)
} else if (this._bodyArrayBuffer) {
return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer))
} else if (this._bodyFormData) {
throw new Error('could not read FormData body as text')
} else {
return Promise.resolve(this._bodyText)
} }
} }
@ -261,7 +303,10 @@
function Request(input, options) { function Request(input, options) {
options = options || {} options = options || {}
var body = options.body var body = options.body
if (Request.prototype.isPrototypeOf(input)) {
if (typeof input === 'string') {
this.url = input
} else {
if (input.bodyUsed) { if (input.bodyUsed) {
throw new TypeError('Already read') throw new TypeError('Already read')
} }
@ -272,12 +317,10 @@
} }
this.method = input.method this.method = input.method
this.mode = input.mode this.mode = input.mode
if (!body) { if (!body && input._bodyInit != null) {
body = input._bodyInit body = input._bodyInit
input.bodyUsed = true input.bodyUsed = true
} }
} else {
this.url = input
} }
this.credentials = options.credentials || this.credentials || 'omit' this.credentials = options.credentials || this.credentials || 'omit'
@ -295,7 +338,7 @@
} }
Request.prototype.clone = function() { Request.prototype.clone = function() {
return new Request(this) return new Request(this, { body: this._bodyInit })
} }
function decode(body) { function decode(body) {
@ -311,16 +354,17 @@
return form return form
} }
function headers(xhr) { function parseHeaders(rawHeaders) {
var head = new Headers() var headers = new Headers()
var pairs = (xhr.getAllResponseHeaders() || '').trim().split('\n') rawHeaders.split('\r\n').forEach(function(line) {
pairs.forEach(function(header) { var parts = line.split(':')
var split = header.trim().split(':') var key = parts.shift().trim()
var key = split.shift().trim() if (key) {
var value = split.join(':').trim() var value = parts.join(':').trim()
head.append(key, value) headers.append(key, value)
}
}) })
return head return headers
} }
Body.call(Request.prototype) Body.call(Request.prototype)
@ -331,10 +375,10 @@
} }
this.type = 'default' this.type = 'default'
this.status = options.status this.status = 'status' in options ? options.status : 200
this.ok = this.status >= 200 && this.status < 300 this.ok = this.status >= 200 && this.status < 300
this.statusText = options.statusText this.statusText = 'statusText' in options ? options.statusText : 'OK'
this.headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers) this.headers = new Headers(options.headers)
this.url = options.url || '' this.url = options.url || ''
this._initBody(bodyInit) this._initBody(bodyInit)
} }
@ -372,35 +416,16 @@
self.fetch = function(input, init) { self.fetch = function(input, init) {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
var request var request = new Request(input, init)
if (Request.prototype.isPrototypeOf(input) && !init) {
request = input
} else {
request = new Request(input, init)
}
var xhr = new XMLHttpRequest() var xhr = new XMLHttpRequest()
function responseURL() {
if ('responseURL' in xhr) {
return xhr.responseURL
}
// Avoid security warnings on getResponseHeader when not allowed by CORS
if (/^X-Request-URL:/m.test(xhr.getAllResponseHeaders())) {
return xhr.getResponseHeader('X-Request-URL')
}
return
}
xhr.onload = function() { xhr.onload = function() {
var options = { var options = {
status: xhr.status, status: xhr.status,
statusText: xhr.statusText, statusText: xhr.statusText,
headers: headers(xhr), headers: parseHeaders(xhr.getAllResponseHeaders() || '')
url: responseURL()
} }
options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL')
var body = 'response' in xhr ? xhr.response : xhr.responseText var body = 'response' in xhr ? xhr.response : xhr.responseText
resolve(new Response(body, options)) resolve(new Response(body, options))
} }

2
docs/demo.min.js vendored

File diff suppressed because one or more lines are too long

View file

@ -14,6 +14,10 @@
* Will be removed when this part of the API is exposed * Will be removed when this part of the API is exposed
*/ */
/* Utility vars */
var ArrayProto = [];
/* Utility functions */ /* Utility functions */
function escape(value) { function escape(value) {
@ -86,11 +90,11 @@
} }
function open(node) { function open(node) {
function attrStr(a) { function attr_str(a) {
return ' ' + a.nodeName + '="' + escape(a.value) + '"'; return ' ' + a.nodeName + '="' + escape(a.value) + '"';
} }
result += '<' + tag(node) + Array.prototype.map.call(node.attributes, attrStr).join('') + '>'; result += '<' + tag(node) + ArrayProto.map.call(node.attributes, attr_str).join('') + '>';
} }
function close(node) { function close(node) {
@ -103,7 +107,7 @@
while (original.length || highlighted.length) { while (original.length || highlighted.length) {
var stream = selectStream(); var stream = selectStream();
result += escape(value.substr(processed, stream[0].offset - processed)); result += escape(value.substring(processed, stream[0].offset));
processed = stream[0].offset; processed = stream[0].offset;
if (stream === original) { if (stream === original) {
/* /*

View file

@ -1,4 +1,4 @@
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.6.0/styles/github.min.css"> <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.8.0/styles/github.min.css">
<!-- diff2html --> <!-- diff2html -->
<link rel="stylesheet" type="text/css" href="assets/diff2html.min.css"> <link rel="stylesheet" type="text/css" href="assets/diff2html.min.css">

View file

@ -1,5 +1,5 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.6.0/highlight.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.8.0/highlight.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.6.0/languages/scala.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.8.0/languages/scala.min.js"></script>
<!-- diff2html --> <!-- diff2html -->
<script type="text/javascript" src="assets/diff2html.min.js"></script> <script type="text/javascript" src="assets/diff2html.min.js"></script>