code
stringlengths
24
2.07M
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
92
language
stringclasses
1 value
repo
stringlengths
5
64
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
renderAnchorLink = function renderAnchorLink(anchor, options, tokens, idx) { var _tokens$children; var linkTokens = [_extends({}, new Token("link_open", "a", 1), { attrs: [["class", options.anchorClassName], ["href", "#" + anchor]] })].concat(_toConsumableArray(renderAnchorLinkSymbol(options)), [new Token("link_close", "a", -1)]); // `push` or `unshift` according to anchorLinkBefore option // space is at the opposite side. var actionOnArray = { false: "push", true: "unshift" }; // insert space between anchor link and heading ? if (options.anchorLinkSpace) { linkTokens[actionOnArray[!options.anchorLinkBefore]](space()); } (_tokens$children = tokens[idx + 1].children)[actionOnArray[options.anchorLinkBefore]].apply(_tokens$children, _toConsumableArray(linkTokens)); }
Clones (copies) an Object using deep copying. This function supports circular references by default, but if you are certain there are no circular references in your object, you can save some CPU time by calling clone(obj, false). Caution: if `circular` is false and `parent` contains circular references, your program may enter an infinite loop and crash. @param `parent` - the object to be cloned @param `circular` - set to true if the object to be cloned may contain circular references. (optional - true by default) @param `depth` - set to a number if the object is only to be cloned to a particular depth. (optional - defaults to Infinity) @param `prototype` - sets the prototype to be used when cloning an object. (optional - defaults to parent prototype). @param `includeNonEnumerable` - set to true if the non-enumerable properties should be cloned as well. Non-enumerable properties on the prototype chain will be ignored. (optional - false by default)
renderAnchorLink
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
treeToMarkdownBulletList = function treeToMarkdownBulletList(tree) { var indent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; return tree.map(function (item) { var indentation = " "; var node = repeat(indentation, indent) + "*"; if (item.heading.content) { node += " " + ("[" + item.heading.content + "](#" + item.heading.anchor + ")\n"); } else { node += "\n"; } if (item.nodes.length) { node += treeToMarkdownBulletList(item.nodes, indent + 1); } return node; }).join(""); }
Clones (copies) an Object using deep copying. This function supports circular references by default, but if you are certain there are no circular references in your object, you can save some CPU time by calling clone(obj, false). Caution: if `circular` is false and `parent` contains circular references, your program may enter an infinite loop and crash. @param `parent` - the object to be cloned @param `circular` - set to true if the object to be cloned may contain circular references. (optional - true by default) @param `depth` - set to a number if the object is only to be cloned to a particular depth. (optional - defaults to Infinity) @param `prototype` - sets the prototype to be used when cloning an object. (optional - defaults to parent prototype). @param `includeNonEnumerable` - set to true if the non-enumerable properties should be cloned as well. Non-enumerable properties on the prototype chain will be ignored. (optional - false by default)
treeToMarkdownBulletList
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
generateTocMarkdownFromArray = function generateTocMarkdownFromArray(headings, options) { var tree = { nodes: [] }; // create an ast headings.forEach(function (heading) { if (heading.level < options.tocFirstLevel || heading.level > options.tocLastLevel) { return; } var i = 1; var lastItem = tree; for (; i < heading.level - options.tocFirstLevel + 1; i++) { if (lastItem.nodes.length === 0) { lastItem.nodes.push({ heading: {}, nodes: [] }); } lastItem = lastItem.nodes[lastItem.nodes.length - 1]; } lastItem.nodes.push({ heading: heading, nodes: [] }); }); return treeToMarkdownBulletList(tree.nodes); }
Clones (copies) an Object using deep copying. This function supports circular references by default, but if you are certain there are no circular references in your object, you can save some CPU time by calling clone(obj, false). Caution: if `circular` is false and `parent` contains circular references, your program may enter an infinite loop and crash. @param `parent` - the object to be cloned @param `circular` - set to true if the object to be cloned may contain circular references. (optional - true by default) @param `depth` - set to a number if the object is only to be cloned to a particular depth. (optional - defaults to Infinity) @param `prototype` - sets the prototype to be used when cloning an object. (optional - defaults to parent prototype). @param `includeNonEnumerable` - set to true if the non-enumerable properties should be cloned as well. Non-enumerable properties on the prototype chain will be ignored. (optional - false by default)
generateTocMarkdownFromArray
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function _instanceof(obj, type) { return type != null && obj instanceof type; }
Clones (copies) an Object using deep copying. This function supports circular references by default, but if you are certain there are no circular references in your object, you can save some CPU time by calling clone(obj, false). Caution: if `circular` is false and `parent` contains circular references, your program may enter an infinite loop and crash. @param `parent` - the object to be cloned @param `circular` - set to true if the object to be cloned may contain circular references. (optional - true by default) @param `depth` - set to a number if the object is only to be cloned to a particular depth. (optional - defaults to Infinity) @param `prototype` - sets the prototype to be used when cloning an object. (optional - defaults to parent prototype). @param `includeNonEnumerable` - set to true if the non-enumerable properties should be cloned as well. Non-enumerable properties on the prototype chain will be ignored. (optional - false by default)
_instanceof
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function __objToStr(o) { return Object.prototype.toString.call(o); }
Functionally equivalent to Buffer(arg, encoding) but throws a TypeError if value is a number. Buffer.from(str[, encoding]) Buffer.from(array) Buffer.from(buffer) Buffer.from(arrayBuffer[, byteOffset[, length]])
__objToStr
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function __isDate(o) { return typeof o === 'object' && __objToStr(o) === '[object Date]'; }
Functionally equivalent to Buffer(arg, encoding) but throws a TypeError if value is a number. Buffer.from(str[, encoding]) Buffer.from(array) Buffer.from(buffer) Buffer.from(arrayBuffer[, byteOffset[, length]])
__isDate
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function __isArray(o) { return typeof o === 'object' && __objToStr(o) === '[object Array]'; }
Functionally equivalent to Buffer(arg, encoding) but throws a TypeError if value is a number. Buffer.from(str[, encoding]) Buffer.from(array) Buffer.from(buffer) Buffer.from(arrayBuffer[, byteOffset[, length]])
__isArray
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function __isRegExp(o) { return typeof o === 'object' && __objToStr(o) === '[object RegExp]'; }
Functionally equivalent to Buffer(arg, encoding) but throws a TypeError if value is a number. Buffer.from(str[, encoding]) Buffer.from(array) Buffer.from(buffer) Buffer.from(arrayBuffer[, byteOffset[, length]])
__isRegExp
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function __getRegExpFlags(re) { var flags = ''; if (re.global) flags += 'g'; if (re.ignoreCase) flags += 'i'; if (re.multiline) flags += 'm'; return flags; }
Creates a new filled Buffer instance. alloc(size[, fill[, encoding]])
__getRegExpFlags
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function typedArraySupport () { try { var arr = new Uint8Array(1) arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }} return arr.foo() === 42 && // typed array instances can be augmented typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray` arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` } catch (e) { return false } }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
typedArraySupport
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function kMaxLength () { return Buffer.TYPED_ARRAY_SUPPORT ? 0x7fffffff : 0x3fffffff }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
kMaxLength
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function createBuffer (that, length) { if (kMaxLength() < length) { throw new RangeError('Invalid typed array length') } if (Buffer.TYPED_ARRAY_SUPPORT) { // Return an augmented `Uint8Array` instance, for best performance that = new Uint8Array(length) that.__proto__ = Buffer.prototype } else { // Fallback: Return an object instance of the Buffer class if (that === null) { that = new Buffer(length) } that.length = length } return that }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
createBuffer
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function Buffer (arg, encodingOrOffset, length) { if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) { return new Buffer(arg, encodingOrOffset, length) } // Common case. if (typeof arg === 'number') { if (typeof encodingOrOffset === 'string') { throw new Error( 'If encoding is specified then the first argument must be a string' ) } return allocUnsafe(this, arg) } return from(this, arg, encodingOrOffset, length) }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
Buffer
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function from (that, value, encodingOrOffset, length) { if (typeof value === 'number') { throw new TypeError('"value" argument must not be a number') } if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) { return fromArrayBuffer(that, value, encodingOrOffset, length) } if (typeof value === 'string') { return fromString(that, value, encodingOrOffset) } return fromObject(that, value) }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
from
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function assertSize (size) { if (typeof size !== 'number') { throw new TypeError('"size" argument must be a number') } else if (size < 0) { throw new RangeError('"size" argument must not be negative') } }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
assertSize
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function alloc (that, size, fill, encoding) { assertSize(size) if (size <= 0) { return createBuffer(that, size) } if (fill !== undefined) { // Only pay attention to encoding if it's a string. This // prevents accidentally sending in a number that would // be interpretted as a start offset. return typeof encoding === 'string' ? createBuffer(that, size).fill(fill, encoding) : createBuffer(that, size).fill(fill) } return createBuffer(that, size) }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
alloc
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function allocUnsafe (that, size) { assertSize(size) that = createBuffer(that, size < 0 ? 0 : checked(size) | 0) if (!Buffer.TYPED_ARRAY_SUPPORT) { for (var i = 0; i < size; ++i) { that[i] = 0 } } return that }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
allocUnsafe
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function fromString (that, string, encoding) { if (typeof encoding !== 'string' || encoding === '') { encoding = 'utf8' } if (!Buffer.isEncoding(encoding)) { throw new TypeError('"encoding" must be a valid string encoding') } var length = byteLength(string, encoding) | 0 that = createBuffer(that, length) var actual = that.write(string, encoding) if (actual !== length) { // Writing a hex string, for example, that contains invalid characters will // cause everything after the first invalid character to be ignored. (e.g. // 'abxxcd' will be treated as 'ab') that = that.slice(0, actual) } return that }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
fromString
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function fromArrayLike (that, array) { var length = array.length < 0 ? 0 : checked(array.length) | 0 that = createBuffer(that, length) for (var i = 0; i < length; i += 1) { that[i] = array[i] & 255 } return that }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
fromArrayLike
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function fromArrayBuffer (that, array, byteOffset, length) { array.byteLength // this throws if `array` is not a valid ArrayBuffer if (byteOffset < 0 || array.byteLength < byteOffset) { throw new RangeError('\'offset\' is out of bounds') } if (array.byteLength < byteOffset + (length || 0)) { throw new RangeError('\'length\' is out of bounds') } if (byteOffset === undefined && length === undefined) { array = new Uint8Array(array) } else if (length === undefined) { array = new Uint8Array(array, byteOffset) } else { array = new Uint8Array(array, byteOffset, length) } if (Buffer.TYPED_ARRAY_SUPPORT) { // Return an augmented `Uint8Array` instance, for best performance that = array that.__proto__ = Buffer.prototype } else { // Fallback: Return an object instance of the Buffer class that = fromArrayLike(that, array) } return that }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
fromArrayBuffer
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function fromObject (that, obj) { if (Buffer.isBuffer(obj)) { var len = checked(obj.length) | 0 that = createBuffer(that, len) if (that.length === 0) { return that } obj.copy(that, 0, 0, len) return that } if (obj) { if ((typeof ArrayBuffer !== 'undefined' && obj.buffer instanceof ArrayBuffer) || 'length' in obj) { if (typeof obj.length !== 'number' || isnan(obj.length)) { return createBuffer(that, 0) } return fromArrayLike(that, obj) } if (obj.type === 'Buffer' && isArray(obj.data)) { return fromArrayLike(that, obj.data) } } throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.') }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
fromObject
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function checked (length) { // Note: cannot use `length < kMaxLength()` here because that fails when // length is NaN (which is otherwise coerced to zero.) if (length >= kMaxLength()) { throw new RangeError('Attempt to allocate Buffer larger than maximum ' + 'size: 0x' + kMaxLength().toString(16) + ' bytes') } return length | 0 }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
checked
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function SlowBuffer (length) { if (+length != length) { // eslint-disable-line eqeqeq length = 0 } return Buffer.alloc(+length) }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
SlowBuffer
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function byteLength (string, encoding) { if (Buffer.isBuffer(string)) { return string.length } if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' && (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) { return string.byteLength } if (typeof string !== 'string') { string = '' + string } var len = string.length if (len === 0) return 0 // Use a for loop to avoid recursion var loweredCase = false for (;;) { switch (encoding) { case 'ascii': case 'latin1': case 'binary': return len case 'utf8': case 'utf-8': case undefined: return utf8ToBytes(string).length case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': return len * 2 case 'hex': return len >>> 1 case 'base64': return base64ToBytes(string).length default: if (loweredCase) return utf8ToBytes(string).length // assume utf8 encoding = ('' + encoding).toLowerCase() loweredCase = true } } }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
byteLength
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function slowToString (encoding, start, end) { var loweredCase = false // No need to verify that "this.length <= MAX_UINT32" since it's a read-only // property of a typed array. // This behaves neither like String nor Uint8Array in that we set start/end // to their upper/lower bounds if the value passed is out of range. // undefined is handled specially as per ECMA-262 6th Edition, // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization. if (start === undefined || start < 0) { start = 0 } // Return early if start > this.length. Done here to prevent potential uint32 // coercion fail below. if (start > this.length) { return '' } if (end === undefined || end > this.length) { end = this.length } if (end <= 0) { return '' } // Force coersion to uint32. This will also coerce falsey/NaN values to 0. end >>>= 0 start >>>= 0 if (end <= start) { return '' } if (!encoding) encoding = 'utf8' while (true) { switch (encoding) { case 'hex': return hexSlice(this, start, end) case 'utf8': case 'utf-8': return utf8Slice(this, start, end) case 'ascii': return asciiSlice(this, start, end) case 'latin1': case 'binary': return latin1Slice(this, start, end) case 'base64': return base64Slice(this, start, end) case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': return utf16leSlice(this, start, end) default: if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) encoding = (encoding + '').toLowerCase() loweredCase = true } } }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
slowToString
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function swap (b, n, m) { var i = b[n] b[n] = b[m] b[m] = i }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
swap
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) { // Empty buffer means no match if (buffer.length === 0) return -1 // Normalize byteOffset if (typeof byteOffset === 'string') { encoding = byteOffset byteOffset = 0 } else if (byteOffset > 0x7fffffff) { byteOffset = 0x7fffffff } else if (byteOffset < -0x80000000) { byteOffset = -0x80000000 } byteOffset = +byteOffset // Coerce to Number. if (isNaN(byteOffset)) { // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer byteOffset = dir ? 0 : (buffer.length - 1) } // Normalize byteOffset: negative offsets start from the end of the buffer if (byteOffset < 0) byteOffset = buffer.length + byteOffset if (byteOffset >= buffer.length) { if (dir) return -1 else byteOffset = buffer.length - 1 } else if (byteOffset < 0) { if (dir) byteOffset = 0 else return -1 } // Normalize val if (typeof val === 'string') { val = Buffer.from(val, encoding) } // Finally, search either indexOf (if dir is true) or lastIndexOf if (Buffer.isBuffer(val)) { // Special case: looking for empty string/buffer always fails if (val.length === 0) { return -1 } return arrayIndexOf(buffer, val, byteOffset, encoding, dir) } else if (typeof val === 'number') { val = val & 0xFF // Search for a byte value [0-255] if (Buffer.TYPED_ARRAY_SUPPORT && typeof Uint8Array.prototype.indexOf === 'function') { if (dir) { return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset) } else { return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset) } } return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir) } throw new TypeError('val must be string, number or Buffer') }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
bidirectionalIndexOf
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function arrayIndexOf (arr, val, byteOffset, encoding, dir) { var indexSize = 1 var arrLength = arr.length var valLength = val.length if (encoding !== undefined) { encoding = String(encoding).toLowerCase() if (encoding === 'ucs2' || encoding === 'ucs-2' || encoding === 'utf16le' || encoding === 'utf-16le') { if (arr.length < 2 || val.length < 2) { return -1 } indexSize = 2 arrLength /= 2 valLength /= 2 byteOffset /= 2 } } function read (buf, i) { if (indexSize === 1) { return buf[i] } else { return buf.readUInt16BE(i * indexSize) } } var i if (dir) { var foundIndex = -1 for (i = byteOffset; i < arrLength; i++) { if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) { if (foundIndex === -1) foundIndex = i if (i - foundIndex + 1 === valLength) return foundIndex * indexSize } else { if (foundIndex !== -1) i -= i - foundIndex foundIndex = -1 } } } else { if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength for (i = byteOffset; i >= 0; i--) { var found = true for (var j = 0; j < valLength; j++) { if (read(arr, i + j) !== read(val, j)) { found = false break } } if (found) return i } } return -1 }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
arrayIndexOf
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function read (buf, i) { if (indexSize === 1) { return buf[i] } else { return buf.readUInt16BE(i * indexSize) } }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
read
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function hexWrite (buf, string, offset, length) { offset = Number(offset) || 0 var remaining = buf.length - offset if (!length) { length = remaining } else { length = Number(length) if (length > remaining) { length = remaining } } // must be an even number of digits var strLen = string.length if (strLen % 2 !== 0) throw new TypeError('Invalid hex string') if (length > strLen / 2) { length = strLen / 2 } for (var i = 0; i < length; ++i) { var parsed = parseInt(string.substr(i * 2, 2), 16) if (isNaN(parsed)) return i buf[offset + i] = parsed } return i }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
hexWrite
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function utf8Write (buf, string, offset, length) { return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length) }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
utf8Write
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function asciiWrite (buf, string, offset, length) { return blitBuffer(asciiToBytes(string), buf, offset, length) }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
asciiWrite
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function latin1Write (buf, string, offset, length) { return asciiWrite(buf, string, offset, length) }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
latin1Write
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function base64Write (buf, string, offset, length) { return blitBuffer(base64ToBytes(string), buf, offset, length) }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
base64Write
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function ucs2Write (buf, string, offset, length) { return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length) }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
ucs2Write
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function base64Slice (buf, start, end) { if (start === 0 && end === buf.length) { return base64.fromByteArray(buf) } else { return base64.fromByteArray(buf.slice(start, end)) } }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
base64Slice
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function utf8Slice (buf, start, end) { end = Math.min(buf.length, end) var res = [] var i = start while (i < end) { var firstByte = buf[i] var codePoint = null var bytesPerSequence = (firstByte > 0xEF) ? 4 : (firstByte > 0xDF) ? 3 : (firstByte > 0xBF) ? 2 : 1 if (i + bytesPerSequence <= end) { var secondByte, thirdByte, fourthByte, tempCodePoint switch (bytesPerSequence) { case 1: if (firstByte < 0x80) { codePoint = firstByte } break case 2: secondByte = buf[i + 1] if ((secondByte & 0xC0) === 0x80) { tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F) if (tempCodePoint > 0x7F) { codePoint = tempCodePoint } } break case 3: secondByte = buf[i + 1] thirdByte = buf[i + 2] if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F) if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) { codePoint = tempCodePoint } } break case 4: secondByte = buf[i + 1] thirdByte = buf[i + 2] fourthByte = buf[i + 3] if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F) if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) { codePoint = tempCodePoint } } } } if (codePoint === null) { // we did not generate a valid codePoint so insert a // replacement char (U+FFFD) and advance only 1 byte codePoint = 0xFFFD bytesPerSequence = 1 } else if (codePoint > 0xFFFF) { // encode to utf16 (surrogate pair dance) codePoint -= 0x10000 res.push(codePoint >>> 10 & 0x3FF | 0xD800) codePoint = 0xDC00 | codePoint & 0x3FF } res.push(codePoint) i += bytesPerSequence } return decodeCodePointsArray(res) }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
utf8Slice
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function decodeCodePointsArray (codePoints) { var len = codePoints.length if (len <= MAX_ARGUMENTS_LENGTH) { return String.fromCharCode.apply(String, codePoints) // avoid extra slice() } // Decode in chunks to avoid "call stack size exceeded". var res = '' var i = 0 while (i < len) { res += String.fromCharCode.apply( String, codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH) ) } return res }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
decodeCodePointsArray
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function asciiSlice (buf, start, end) { var ret = '' end = Math.min(buf.length, end) for (var i = start; i < end; ++i) { ret += String.fromCharCode(buf[i] & 0x7F) } return ret }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
asciiSlice
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function latin1Slice (buf, start, end) { var ret = '' end = Math.min(buf.length, end) for (var i = start; i < end; ++i) { ret += String.fromCharCode(buf[i]) } return ret }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
latin1Slice
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function hexSlice (buf, start, end) { var len = buf.length if (!start || start < 0) start = 0 if (!end || end < 0 || end > len) end = len var out = '' for (var i = start; i < end; ++i) { out += toHex(buf[i]) } return out }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
hexSlice
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function utf16leSlice (buf, start, end) { var bytes = buf.slice(start, end) var res = '' for (var i = 0; i < bytes.length; i += 2) { res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256) } return res }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
utf16leSlice
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function checkOffset (offset, ext, length) { if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint') if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length') }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
checkOffset
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function checkInt (buf, value, offset, ext, max, min) { if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance') if (value > max || value < min) throw new RangeError('"value" argument is out of bounds') if (offset + ext > buf.length) throw new RangeError('Index out of range') }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
checkInt
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function objectWriteUInt16 (buf, value, offset, littleEndian) { if (value < 0) value = 0xffff + value + 1 for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) { buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>> (littleEndian ? i : 1 - i) * 8 } }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
objectWriteUInt16
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function objectWriteUInt32 (buf, value, offset, littleEndian) { if (value < 0) value = 0xffffffff + value + 1 for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) { buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff } }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
objectWriteUInt32
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function checkIEEE754 (buf, value, offset, ext, max, min) { if (offset + ext > buf.length) throw new RangeError('Index out of range') if (offset < 0) throw new RangeError('Index out of range') }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
checkIEEE754
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function writeFloat (buf, value, offset, littleEndian, noAssert) { if (!noAssert) { checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38) } ieee754.write(buf, value, offset, littleEndian, 23, 4) return offset + 4 }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
writeFloat
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function writeDouble (buf, value, offset, littleEndian, noAssert) { if (!noAssert) { checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308) } ieee754.write(buf, value, offset, littleEndian, 52, 8) return offset + 8 }
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
writeDouble
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function isValidDelim(state, pos) { var prevChar, nextChar, max = state.posMax, can_open = true, can_close = true; prevChar = pos > 0 ? state.src.charCodeAt(pos - 1) : -1; nextChar = pos + 1 <= max ? state.src.charCodeAt(pos + 1) : -1; // Check non-whitespace conditions for opening and closing, and // check that closing delimeter isn't followed by a number if (prevChar === 0x20/* " " */ || prevChar === 0x09/* \t */ || (nextChar >= 0x30/* "0" */ && nextChar <= 0x39/* "9" */)) { can_close = false; } if (nextChar === 0x20/* " " */ || nextChar === 0x09/* \t */) { can_open = false; } return { can_open: can_open, can_close: can_close }; }
Parse and build an expression, and return the markup for that.
isValidDelim
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function math_block(state, start, end, silent){ var firstLine, lastLine, next, lastPos, found = false, token, pos = state.bMarks[start] + state.tShift[start], max = state.eMarks[start] if(pos + 2 > max){ return false; } if(state.src.slice(pos,pos+2)!=='$$'){ return false; } pos += 2; firstLine = state.src.slice(pos,max); if(silent){ return true; } if(firstLine.trim().slice(-2)==='$$'){ // Single line expression firstLine = firstLine.trim().slice(0, -2); found = true; } for(next = start; !found; ){ next++; if(next >= end){ break; } pos = state.bMarks[next]+state.tShift[next]; max = state.eMarks[next]; if(pos < max && state.tShift[next] < state.blkIndent){ // non-empty line with negative indent should stop the list: break; } if(state.src.slice(pos,max).trim().slice(-2)==='$$'){ lastPos = state.src.slice(0,max).lastIndexOf('$$'); lastLine = state.src.slice(pos,lastPos); found = true; } } state.line = next + 1; token = state.push('math_block', 'math', 0); token.block = true; token.content = (firstLine && firstLine.trim() ? firstLine + '\n' : '') + state.getLines(start + 1, next, state.tShift[start], true) + (lastLine && lastLine.trim() ? lastLine : ''); token.map = [ start, state.line ]; token.markup = '$$'; return true; }
The main Settings object The current options stored are: - displayMode: Whether the expression should be typeset by default in textstyle or displaystyle (default false)
math_block
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
inlineRenderer = function(tokens, idx){ return katexInline(tokens[idx].content); }
This file does the main work of building a domTree structure from a parse tree. The entry point is the `buildHTML` function, which takes a parse tree. Then, the buildExpression, buildGroup, and various groupTypes functions are called, to produce a final HTML tree.
inlineRenderer
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
katexBlock = function(latex){ options.displayMode = true; try{ return "<p>" + katex.renderToString(latex, options) + "</p>"; } catch(error){ if(options.throwOnError){ console.log(error); } return latex; } }
This file does the main work of building a domTree structure from a parse tree. The entry point is the `buildHTML` function, which takes a parse tree. Then, the buildExpression, buildGroup, and various groupTypes functions are called, to produce a final HTML tree.
katexBlock
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
blockRenderer = function(tokens, idx){ return katexBlock(tokens[idx].content) + '\n'; }
Take a list of nodes, build them in order, and return a list of the built nodes. This function handles the `prev` node correctly, and passes the previous element from the list as the prev of the next element.
blockRenderer
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
render = function(expression, baseNode, options) { utils.clearNode(baseNode); var settings = new Settings(options); var tree = parseTree(expression, settings); var node = buildTree(tree, expression, settings).toNode(); baseNode.appendChild(node); }
Take a list of nodes, build them in order, and return a list of the built nodes. This function handles the `prev` node correctly, and passes the previous element from the list as the prev of the next element.
render
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
renderToString = function(expression, options) { var settings = new Settings(options); var tree = parseTree(expression, settings); return buildTree(tree, expression, settings).toMarkup(); }
Gets the final math type of an expression, given its group type. This type is used to determine spacing between elements, and affects bin elements by causing them to change depending on what types are around them. This type must be attached to the outermost node of an element as a CSS class so that spacing with its surrounding elements works correctly. Some elements can be mapped one-to-one from group type to math type, and those are listed in the `groupToType` table. Others (usually elements that wrap around other elements) often have recursive definitions, and thus call `getTypeOfGroup` on their inner elements.
renderToString
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
generateParseTree = function(expression, options) { var settings = new Settings(options); return parseTree(expression, settings); }
Gets the final math type of an expression, given its group type. This type is used to determine spacing between elements, and affects bin elements by causing them to change depending on what types are around them. This type must be attached to the outermost node of an element as a CSS class so that spacing with its surrounding elements works correctly. Some elements can be mapped one-to-one from group type to math type, and those are listed in the `groupToType` table. Others (usually elements that wrap around other elements) often have recursive definitions, and thus call `getTypeOfGroup` on their inner elements.
generateParseTree
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function ParseError(message, lexer, position) { var error = "KaTeX parse error: " + message; if (lexer !== undefined && position !== undefined) { // If we have the input and a position, make the error a bit fancier // Prepend some information error += " at position " + position + ": "; // Get the input var input = lexer._input; // Insert a combining underscore at the correct position input = input.slice(0, position) + "\u0332" + input.slice(position); // Extract some context from the input and add it to the error var begin = Math.max(0, position - 15); var end = position + 15; error += input.slice(begin, end); } // Some hackery to make ParseError a prototype of Error // See http://stackoverflow.com/a/8460753 var self = new Error(error); self.name = "ParseError"; self.__proto__ = ParseError.prototype; self.position = position; return self; }
Sometimes, groups perform special rules when they have superscripts or subscripts attached to them. This function lets the `supsub` group know that its inner element should handle the superscripts and subscripts instead of handling them itself.
ParseError
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function get(option, defaultValue) { return option === undefined ? defaultValue : option; }
TeXbook algorithms often reference "character boxes", which are simply groups with a single character in them. To decide if something is a character box, we find its innermost group, and see if it is a single character.
get
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function Settings(options) { // allow null options options = options || {}; this.displayMode = get(options.displayMode, false); this.throwOnError = get(options.throwOnError, true); this.errorColor = get(options.errorColor, "#cc0000"); }
TeXbook algorithms often reference "character boxes", which are simply groups with a single character in them. To decide if something is a character box, we find its innermost group, and see if it is a single character.
Settings
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
buildTree = function(tree, expression, settings) { settings = settings || new Settings({}); var startStyle = Style.TEXT; if (settings.displayMode) { startStyle = Style.DISPLAY; } // Setup the default options var options = new Options({ style: startStyle, size: "size5", }); // `buildHTML` sometimes messes with the parse tree (like turning bins -> // ords), so we build the MathML version first. var mathMLNode = buildMathML(tree, expression, options); var htmlNode = buildHTML(tree, options); var katexNode = makeSpan(["katex"], [ mathMLNode, htmlNode, ]); if (settings.displayMode) { return makeSpan(["katex-display"], [katexNode]); } else { return katexNode; } }
This is a map of group types to the function used to handle that type. Simpler types come at the beginning, while complicated types come afterwards.
buildTree
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
buildExpression = function(expression, options, prev) { var groups = []; for (var i = 0; i < expression.length; i++) { var group = expression[i]; groups.push(buildGroup(group, options, prev)); prev = group; } return groups; }
This is a map of group types to the function used to handle that type. Simpler types come at the beginning, while complicated types come afterwards.
buildExpression
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
getTypeOfGroup = function(group) { if (group == null) { // Like when typesetting $^3$ return groupToType.mathord; } else if (group.type === "supsub") { return getTypeOfGroup(group.value.base); } else if (group.type === "llap" || group.type === "rlap") { return getTypeOfGroup(group.value); } else if (group.type === "color") { return getTypeOfGroup(group.value.value); } else if (group.type === "sizing") { return getTypeOfGroup(group.value.value); } else if (group.type === "styling") { return getTypeOfGroup(group.value.value); } else if (group.type === "delimsizing") { return groupToType[group.value.delimType]; } else { return groupToType[group.type]; } }
This is a map of group types to the function used to handle that type. Simpler types come at the beginning, while complicated types come afterwards.
getTypeOfGroup
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
shouldHandleSupSub = function(group, options) { if (!group) { return false; } else if (group.type === "op") { // Operators handle supsubs differently when they have limits // (e.g. `\displaystyle\sum_2^3`) return group.value.limits && (options.style.size === Style.DISPLAY.size || group.value.alwaysHandleSupSub); } else if (group.type === "accent") { return isCharacterBox(group.value.base); } else { return null; } }
This is a map of group types to the function used to handle that type. Simpler types come at the beginning, while complicated types come afterwards.
shouldHandleSupSub
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
getBaseElem = function(group) { if (!group) { return false; } else if (group.type === "ordgroup") { if (group.value.length === 1) { return getBaseElem(group.value[0]); } else { return group; } } else if (group.type === "color") { if (group.value.value.length === 1) { return getBaseElem(group.value.value[0]); } else { return group; } } else { return group; } }
This is a map of group types to the function used to handle that type. Simpler types come at the beginning, while complicated types come afterwards.
getBaseElem
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
isCharacterBox = function(group) { var baseElem = getBaseElem(group); // These are all they types of groups which hold single characters return baseElem.type === "mathord" || baseElem.type === "textord" || baseElem.type === "bin" || baseElem.type === "rel" || baseElem.type === "inner" || baseElem.type === "open" || baseElem.type === "close" || baseElem.type === "punct"; }
This is a map of group types to the function used to handle that type. Simpler types come at the beginning, while complicated types come afterwards.
isCharacterBox
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
makeNullDelimiter = function(options) { return makeSpan([ "sizing", "reset-" + options.size, "size5", options.style.reset(), Style.TEXT.cls(), "nulldelimiter", ]); }
This is a map of group types to the function used to handle that type. Simpler types come at the beginning, while complicated types come afterwards.
makeNullDelimiter
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
buildGroup = function(group, options, prev) { if (!group) { return makeSpan(); } if (groupTypes[group.type]) { // Call the groupTypes function var groupNode = groupTypes[group.type](group, options, prev); var multiplier; // If the style changed between the parent and the current group, // account for the size difference if (options.style !== options.parentStyle) { multiplier = options.style.sizeMultiplier / options.parentStyle.sizeMultiplier; groupNode.height *= multiplier; groupNode.depth *= multiplier; } // If the size changed between the parent and the current group, account // for that size difference. if (options.size !== options.parentSize) { multiplier = buildCommon.sizingMultiplier[options.size] / buildCommon.sizingMultiplier[options.parentSize]; groupNode.height *= multiplier; groupNode.depth *= multiplier; } return groupNode; } else { throw new ParseError( "Got group of unknown type: '" + group.type + "'"); } }
Makes a symbolNode after translation via the list of symbols in symbols.js. Correctly pulls out metrics for the character, and optionally takes a list of classes to be attached to the node.
buildGroup
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
buildHTML = function(tree, options) { // buildExpression is destructive, so we need to make a clone // of the incoming tree so that it isn't accidentally changed tree = JSON.parse(JSON.stringify(tree)); // Build the expression contained in the tree var expression = buildExpression(tree, options); var body = makeSpan(["base", options.style.cls()], expression); // Add struts, which ensure that the top of the HTML element falls at the // height of the expression, and the bottom of the HTML element falls at the // depth of the expression. var topStrut = makeSpan(["strut"]); var bottomStrut = makeSpan(["strut", "bottom"]); topStrut.style.height = body.height + "em"; bottomStrut.style.height = (body.height + body.depth) + "em"; // We'd like to use `vertical-align: top` but in IE 9 this lowers the // baseline of the box to the bottom of this strut (instead staying in the // normal place) so we use an absolute value for vertical-align instead bottomStrut.style.verticalAlign = -body.depth + "em"; // Wrap the struts and body together var htmlNode = makeSpan(["katex-html"], [topStrut, bottomStrut, body]); htmlNode.setAttribute("aria-hidden", "true"); return htmlNode; }
Makes a symbol in Main-Regular or AMS-Regular. Used for rel, bin, open, close, inner, and punct.
buildHTML
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function Style(id, size, multiplier, cramped) { this.id = id; this.size = size; this.cramped = cramped; this.sizeMultiplier = multiplier; }
Makes either a mathord or textord in the correct font and color.
Style
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
makeSymbol = function(value, style, mode, color, classes) { // Replace the value with its replaced value from symbol.js if (symbols[mode][value] && symbols[mode][value].replace) { value = symbols[mode][value].replace; } var metrics = fontMetrics.getCharacterMetrics(value, style); var symbolNode; if (metrics) { symbolNode = new domTree.symbolNode( value, metrics.height, metrics.depth, metrics.italic, metrics.skew, classes); } else { // TODO(emily): Figure out a good way to only print this in development typeof console !== "undefined" && console.warn( "No character metrics for '" + value + "' in style '" + style + "'"); symbolNode = new domTree.symbolNode(value, 0, 0, 0, 0, classes); } if (color) { symbolNode.style.color = color; } return symbolNode; }
Makes an element placed in each of the vlist elements to ensure that each element has the same max font size. To do this, we create a zero-width space with the correct font size.
makeSymbol
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
mathsym = function(value, mode, color, classes) { // Decide what font to render the symbol in by its entry in the symbols // table. // Have a special case for when the value = \ because the \ is used as a // textord in unsupported command errors but cannot be parsed as a regular // text ordinal and is therefore not present as a symbol in the symbols // table for text if (value === "\\" || symbols[mode][value].font === "main") { return makeSymbol(value, "Main-Regular", mode, color, classes); } else { return makeSymbol( value, "AMS-Regular", mode, color, classes.concat(["amsrm"])); } }
Makes a vertical list by stacking elements and kerns on top of each other. Allows for many different ways of specifying the positioning method. Arguments: - children: A list of child or kern nodes to be stacked on top of each other (i.e. the first element will be at the bottom, and the last at the top). Element nodes are specified as {type: "elem", elem: node} while kern nodes are specified as {type: "kern", size: size} - positionType: The method by which the vlist should be positioned. Valid values are: - "individualShift": The children list only contains elem nodes, and each node contains an extra "shift" value of how much it should be shifted (note that shifting is always moving downwards). positionData is ignored. - "top": The positionData specifies the topmost point of the vlist (note this is expected to be a height, so positive values move up) - "bottom": The positionData specifies the bottommost point of the vlist (note this is expected to be a depth, so positive values move down - "shift": The vlist will be positioned such that its baseline is positionData away from the baseline of the first child. Positive values move downwards. - "firstBaseline": The vlist will be positioned such that its baseline is aligned with the baseline of the first child. positionData is ignored. (this is equivalent to "shift" with positionData=0) - positionData: Data used in different ways depending on positionType - options: An Options object
mathsym
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
mathDefault = function(value, mode, color, classes, type) { if (type === "mathord") { return mathit(value, mode, color, classes); } else if (type === "textord") { return makeSymbol( value, "Main-Regular", mode, color, classes.concat(["mathrm"])); } else { throw new Error("unexpected type: " + type + " in mathDefault"); } }
Makes a vertical list by stacking elements and kerns on top of each other. Allows for many different ways of specifying the positioning method. Arguments: - children: A list of child or kern nodes to be stacked on top of each other (i.e. the first element will be at the bottom, and the last at the top). Element nodes are specified as {type: "elem", elem: node} while kern nodes are specified as {type: "kern", size: size} - positionType: The method by which the vlist should be positioned. Valid values are: - "individualShift": The children list only contains elem nodes, and each node contains an extra "shift" value of how much it should be shifted (note that shifting is always moving downwards). positionData is ignored. - "top": The positionData specifies the topmost point of the vlist (note this is expected to be a height, so positive values move up) - "bottom": The positionData specifies the bottommost point of the vlist (note this is expected to be a depth, so positive values move down - "shift": The vlist will be positioned such that its baseline is positionData away from the baseline of the first child. Positive values move downwards. - "firstBaseline": The vlist will be positioned such that its baseline is aligned with the baseline of the first child. positionData is ignored. (this is equivalent to "shift" with positionData=0) - positionData: Data used in different ways depending on positionType - options: An Options object
mathDefault
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
mathit = function(value, mode, color, classes) { if (/[0-9]/.test(value.charAt(0)) || // glyphs for \imath and \jmath do not exist in Math-Italic so we // need to use Main-Italic instead utils.contains(dotlessLetters, value) || utils.contains(greekCapitals, value)) { return makeSymbol( value, "Main-Italic", mode, color, classes.concat(["mainit"])); } else { return makeSymbol( value, "Math-Italic", mode, color, classes.concat(["mathit"])); } }
Makes a vertical list by stacking elements and kerns on top of each other. Allows for many different ways of specifying the positioning method. Arguments: - children: A list of child or kern nodes to be stacked on top of each other (i.e. the first element will be at the bottom, and the last at the top). Element nodes are specified as {type: "elem", elem: node} while kern nodes are specified as {type: "kern", size: size} - positionType: The method by which the vlist should be positioned. Valid values are: - "individualShift": The children list only contains elem nodes, and each node contains an extra "shift" value of how much it should be shifted (note that shifting is always moving downwards). positionData is ignored. - "top": The positionData specifies the topmost point of the vlist (note this is expected to be a height, so positive values move up) - "bottom": The positionData specifies the bottommost point of the vlist (note this is expected to be a depth, so positive values move down - "shift": The vlist will be positioned such that its baseline is positionData away from the baseline of the first child. Positive values move downwards. - "firstBaseline": The vlist will be positioned such that its baseline is aligned with the baseline of the first child. positionData is ignored. (this is equivalent to "shift" with positionData=0) - positionData: Data used in different ways depending on positionType - options: An Options object
mathit
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
makeOrd = function(group, options, type) { var mode = group.mode; var value = group.value; if (symbols[mode][value] && symbols[mode][value].replace) { value = symbols[mode][value].replace; } var classes = ["mord"]; var color = options.getColor(); var font = options.font; if (font) { if (font === "mathit" || utils.contains(dotlessLetters, value)) { return mathit(value, mode, color, classes); } else { var fontName = fontMap[font].fontName; if (fontMetrics.getCharacterMetrics(value, fontName)) { return makeSymbol( value, fontName, mode, color, classes.concat([font])); } else { return mathDefault(value, mode, color, classes, type); } } } else { return mathDefault(value, mode, color, classes, type); } }
Makes a vertical list by stacking elements and kerns on top of each other. Allows for many different ways of specifying the positioning method. Arguments: - children: A list of child or kern nodes to be stacked on top of each other (i.e. the first element will be at the bottom, and the last at the top). Element nodes are specified as {type: "elem", elem: node} while kern nodes are specified as {type: "kern", size: size} - positionType: The method by which the vlist should be positioned. Valid values are: - "individualShift": The children list only contains elem nodes, and each node contains an extra "shift" value of how much it should be shifted (note that shifting is always moving downwards). positionData is ignored. - "top": The positionData specifies the topmost point of the vlist (note this is expected to be a height, so positive values move up) - "bottom": The positionData specifies the bottommost point of the vlist (note this is expected to be a depth, so positive values move down - "shift": The vlist will be positioned such that its baseline is positionData away from the baseline of the first child. Positive values move downwards. - "firstBaseline": The vlist will be positioned such that its baseline is aligned with the baseline of the first child. positionData is ignored. (this is equivalent to "shift" with positionData=0) - positionData: Data used in different ways depending on positionType - options: An Options object
makeOrd
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
sizeElementFromChildren = function(elem) { var height = 0; var depth = 0; var maxFontSize = 0; if (elem.children) { for (var i = 0; i < elem.children.length; i++) { if (elem.children[i].height > height) { height = elem.children[i].height; } if (elem.children[i].depth > depth) { depth = elem.children[i].depth; } if (elem.children[i].maxFontSize > maxFontSize) { maxFontSize = elem.children[i].maxFontSize; } } } elem.height = height; elem.depth = depth; elem.maxFontSize = maxFontSize; }
Makes a vertical list by stacking elements and kerns on top of each other. Allows for many different ways of specifying the positioning method. Arguments: - children: A list of child or kern nodes to be stacked on top of each other (i.e. the first element will be at the bottom, and the last at the top). Element nodes are specified as {type: "elem", elem: node} while kern nodes are specified as {type: "kern", size: size} - positionType: The method by which the vlist should be positioned. Valid values are: - "individualShift": The children list only contains elem nodes, and each node contains an extra "shift" value of how much it should be shifted (note that shifting is always moving downwards). positionData is ignored. - "top": The positionData specifies the topmost point of the vlist (note this is expected to be a height, so positive values move up) - "bottom": The positionData specifies the bottommost point of the vlist (note this is expected to be a depth, so positive values move down - "shift": The vlist will be positioned such that its baseline is positionData away from the baseline of the first child. Positive values move downwards. - "firstBaseline": The vlist will be positioned such that its baseline is aligned with the baseline of the first child. positionData is ignored. (this is equivalent to "shift" with positionData=0) - positionData: Data used in different ways depending on positionType - options: An Options object
sizeElementFromChildren
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
makeSpan = function(classes, children, color) { var span = new domTree.span(classes, children); sizeElementFromChildren(span); if (color) { span.style.color = color; } return span; }
Makes a vertical list by stacking elements and kerns on top of each other. Allows for many different ways of specifying the positioning method. Arguments: - children: A list of child or kern nodes to be stacked on top of each other (i.e. the first element will be at the bottom, and the last at the top). Element nodes are specified as {type: "elem", elem: node} while kern nodes are specified as {type: "kern", size: size} - positionType: The method by which the vlist should be positioned. Valid values are: - "individualShift": The children list only contains elem nodes, and each node contains an extra "shift" value of how much it should be shifted (note that shifting is always moving downwards). positionData is ignored. - "top": The positionData specifies the topmost point of the vlist (note this is expected to be a height, so positive values move up) - "bottom": The positionData specifies the bottommost point of the vlist (note this is expected to be a depth, so positive values move down - "shift": The vlist will be positioned such that its baseline is positionData away from the baseline of the first child. Positive values move downwards. - "firstBaseline": The vlist will be positioned such that its baseline is aligned with the baseline of the first child. positionData is ignored. (this is equivalent to "shift" with positionData=0) - positionData: Data used in different ways depending on positionType - options: An Options object
makeSpan
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
makeFragment = function(children) { var fragment = new domTree.documentFragment(children); sizeElementFromChildren(fragment); return fragment; }
Makes a vertical list by stacking elements and kerns on top of each other. Allows for many different ways of specifying the positioning method. Arguments: - children: A list of child or kern nodes to be stacked on top of each other (i.e. the first element will be at the bottom, and the last at the top). Element nodes are specified as {type: "elem", elem: node} while kern nodes are specified as {type: "kern", size: size} - positionType: The method by which the vlist should be positioned. Valid values are: - "individualShift": The children list only contains elem nodes, and each node contains an extra "shift" value of how much it should be shifted (note that shifting is always moving downwards). positionData is ignored. - "top": The positionData specifies the topmost point of the vlist (note this is expected to be a height, so positive values move up) - "bottom": The positionData specifies the bottommost point of the vlist (note this is expected to be a depth, so positive values move down - "shift": The vlist will be positioned such that its baseline is positionData away from the baseline of the first child. Positive values move downwards. - "firstBaseline": The vlist will be positioned such that its baseline is aligned with the baseline of the first child. positionData is ignored. (this is equivalent to "shift" with positionData=0) - positionData: Data used in different ways depending on positionType - options: An Options object
makeFragment
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
makeFontSizer = function(options, fontSize) { var fontSizeInner = makeSpan([], [new domTree.symbolNode("\u200b")]); fontSizeInner.style.fontSize = (fontSize / options.style.sizeMultiplier) + "em"; var fontSizer = makeSpan( ["fontsize-ensurer", "reset-" + options.size, "size5"], [fontSizeInner]); return fontSizer; }
Maps TeX font commands to objects containing: - variant: string used for "mathvariant" attribute in buildMathML.js - fontName: the "style" parameter to fontMetrics.getCharacterMetrics
makeFontSizer
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
makeVList = function(children, positionType, positionData, options) { var depth; var currPos; var i; if (positionType === "individualShift") { var oldChildren = children; children = [oldChildren[0]]; // Add in kerns to the list of children to get each element to be // shifted to the correct specified shift depth = -oldChildren[0].shift - oldChildren[0].elem.depth; currPos = depth; for (i = 1; i < oldChildren.length; i++) { var diff = -oldChildren[i].shift - currPos - oldChildren[i].elem.depth; var size = diff - (oldChildren[i - 1].elem.height + oldChildren[i - 1].elem.depth); currPos = currPos + diff; children.push({type: "kern", size: size}); children.push(oldChildren[i]); } } else if (positionType === "top") { // We always start at the bottom, so calculate the bottom by adding up // all the sizes var bottom = positionData; for (i = 0; i < children.length; i++) { if (children[i].type === "kern") { bottom -= children[i].size; } else { bottom -= children[i].elem.height + children[i].elem.depth; } } depth = bottom; } else if (positionType === "bottom") { depth = -positionData; } else if (positionType === "shift") { depth = -children[0].elem.depth - positionData; } else if (positionType === "firstBaseline") { depth = -children[0].elem.depth; } else { depth = 0; } // Make the fontSizer var maxFontSize = 0; for (i = 0; i < children.length; i++) { if (children[i].type === "elem") { maxFontSize = Math.max(maxFontSize, children[i].elem.maxFontSize); } } var fontSizer = makeFontSizer(options, maxFontSize); // Create a new list of actual children at the correct offsets var realChildren = []; currPos = depth; for (i = 0; i < children.length; i++) { if (children[i].type === "kern") { currPos += children[i].size; } else { var child = children[i].elem; var shift = -child.depth - currPos; currPos += child.height + child.depth; var childWrap = makeSpan([], [fontSizer, child]); childWrap.height -= shift; childWrap.depth += shift; childWrap.style.top = shift + "em"; realChildren.push(childWrap); } } // Add in an element at the end with no offset to fix the calculation of // baselines in some browsers (namely IE, sometimes safari) var baselineFix = makeSpan( ["baseline-fix"], [fontSizer, new domTree.symbolNode("\u200b")]); realChildren.push(baselineFix); var vlist = makeSpan(["vlist"], realChildren); // Fix the final height and depth, in case there were kerns at the ends // since the makeSpan calculation won't take that in to account. vlist.height = Math.max(currPos, vlist.height); vlist.depth = Math.max(-depth, vlist.depth); return vlist; }
Create an HTML className based on a list of classes. In addition to joining with spaces, we also remove null or empty classes.
makeVList
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function span(classes, children, height, depth, maxFontSize, style) { this.classes = classes || []; this.children = children || []; this.height = height || 0; this.depth = depth || 0; this.maxFontSize = maxFontSize || 0; this.style = style || {}; this.attributes = {}; }
Provide an `indexOf` function which works in IE8, but defers to native if possible.
span
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function documentFragment(children, height, depth, maxFontSize) { this.children = children || []; this.height = height || 0; this.depth = depth || 0; this.maxFontSize = maxFontSize || 0; }
This file contains metrics regarding fonts and individual symbols. The sigma and xi variables, as well as the metricMap map contain data extracted from TeX, TeX font metrics, and the TTF files. These data are then exposed via the `metrics` variable and the getCharacterMetrics function.
documentFragment
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function symbolNode(value, height, depth, italic, skew, classes, style) { this.value = value || ""; this.height = height || 0; this.depth = depth || 0; this.italic = italic || 0; this.skew = skew || 0; this.classes = classes || []; this.style = style || {}; this.maxFontSize = 0; }
This file contains metrics regarding fonts and individual symbols. The sigma and xi variables, as well as the metricMap map contain data extracted from TeX, TeX font metrics, and the TTF files. These data are then exposed via the `metrics` variable and the getCharacterMetrics function.
symbolNode
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function defineSymbol(mode, font, group, replace, name) { module.exports[mode][name] = { font: font, group: group, replace: replace, }; }
This file holds a list of all no-argument functions and single-character symbols (like 'a' or ';'). For each of the symbols, there are three properties they can have: - font (required): the font to be used for this symbol. Either "main" (the normal font), or "ams" (the ams fonts). - group (required): the ParseNode group type the symbol should have (i.e. "textord", "mathord", etc). See https://github.com/Khan/KaTeX/wiki/Examining-TeX#group-types - replace: the character that this symbol or function should be replaced with (i.e. "\phi" has a replace value of "\u03d5", the phi character in the main font). The outermost map in the table indicates what mode the symbols should be accepted in (e.g. "math" or "text").
defineSymbol
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
makeSizedDelim = function(delim, size, options, mode) { // < and > turn into \langle and \rangle in delimiters if (delim === "<" || delim === "\\lt") { delim = "\\langle"; } else if (delim === ">" || delim === "\\gt") { delim = "\\rangle"; } // Sized delimiters are never centered. if (utils.contains(stackLargeDelimiters, delim) || utils.contains(stackNeverDelimiters, delim)) { return makeLargeDelim(delim, size, false, options, mode); } else if (utils.contains(stackAlwaysDelimiters, delim)) { return makeStackedDelim( delim, sizeToMaxHeight[size], false, options, mode); } else { throw new ParseError("Illegal delimiter: '" + delim + "'"); } }
This file converts a parse tree into a cooresponding MathML tree. The main entry point is the `buildMathML` function, which takes a parse tree from the parser.
makeSizedDelim
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
delimTypeToFont = function(type) { if (type.type === "small") { return "Main-Regular"; } else if (type.type === "large") { return "Size" + type.size + "-Regular"; } else if (type.type === "stack") { return "Size4-Regular"; } }
Functions for handling the different types of groups found in the parse tree. Each function should take a parse group and return a MathML node.
delimTypeToFont
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
traverseSequence = function(delim, height, sequence, options) { // Here, we choose the index we should start at in the sequences. In smaller // sizes (which correspond to larger numbers in style.size) we start earlier // in the sequence. Thus, scriptscript starts at index 3-3=0, script starts // at index 3-2=1, text starts at 3-1=2, and display starts at min(2,3-0)=2 var start = Math.min(2, 3 - options.style.size); for (var i = start; i < sequence.length; i++) { if (sequence[i].type === "stack") { // This is always the last delimiter, so we just break the loop now. break; } var metrics = getMetrics(delim, delimTypeToFont(sequence[i])); var heightDepth = metrics.height + metrics.depth; // Small delimiters are scaled down versions of the same font, so we // account for the style change size. if (sequence[i].type === "small") { heightDepth *= sequence[i].style.sizeMultiplier; } // Check if the delimiter at this size works for the given height. if (heightDepth > height) { return sequence[i]; } } // If we reached the end of the sequence, return the last sequence element. return sequence[sequence.length - 1]; }
Functions for handling the different types of groups found in the parse tree. Each function should take a parse group and return a MathML node.
traverseSequence
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
makeCustomSizedDelim = function(delim, height, center, options, mode) { if (delim === "<" || delim === "\\lt") { delim = "\\langle"; } else if (delim === ">" || delim === "\\gt") { delim = "\\rangle"; } // Decide what sequence to use var sequence; if (utils.contains(stackNeverDelimiters, delim)) { sequence = stackNeverDelimiterSequence; } else if (utils.contains(stackLargeDelimiters, delim)) { sequence = stackLargeDelimiterSequence; } else { sequence = stackAlwaysDelimiterSequence; } // Look through the sequence var delimType = traverseSequence(delim, height, sequence, options); // Depending on the sequence element we decided on, call the appropriate // function. if (delimType.type === "small") { return makeSmallDelim(delim, delimType.style, center, options, mode); } else if (delimType.type === "large") { return makeLargeDelim(delim, delimType.size, center, options, mode); } else if (delimType.type === "stack") { return makeStackedDelim(delim, height, center, options, mode); } }
Functions for handling the different types of groups found in the parse tree. Each function should take a parse group and return a MathML node.
makeCustomSizedDelim
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
makeLeftRightDelim = function(delim, height, depth, options, mode) { // We always center \left/\right delimiters, so the axis is always shifted var axisHeight = fontMetrics.metrics.axisHeight * options.style.sizeMultiplier; // Taken from TeX source, tex.web, function make_left_right var delimiterFactor = 901; var delimiterExtend = 5.0 / fontMetrics.metrics.ptPerEm; var maxDistFromAxis = Math.max( height - axisHeight, depth + axisHeight); var totalHeight = Math.max( // In real TeX, calculations are done using integral values which are // 65536 per pt, or 655360 per em. So, the division here truncates in // TeX but doesn't here, producing different results. If we wanted to // exactly match TeX's calculation, we could do // Math.floor(655360 * maxDistFromAxis / 500) * // delimiterFactor / 655360 // (To see the difference, compare // x^{x^{\left(\rule{0.1em}{0.68em}\right)}} // in TeX and KaTeX) maxDistFromAxis / 500 * delimiterFactor, 2 * maxDistFromAxis - delimiterExtend); // Finally, we defer to `makeCustomSizedDelim` with our calculated total // height return makeCustomSizedDelim(delim, totalHeight, true, options, mode); }
Functions for handling the different types of groups found in the parse tree. Each function should take a parse group and return a MathML node.
makeLeftRightDelim
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
makeText = function(text, mode) { if (symbols[mode][text] && symbols[mode][text].replace) { text = symbols[mode][text].replace; } return new mathMLTree.TextNode(text); }
Functions for handling the different types of groups found in the parse tree. Each function should take a parse group and return a MathML node.
makeText
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
getVariant = function(group, options) { var font = options.font; if (!font) { return null; } var mode = group.mode; if (font === "mathit") { return "italic"; } var value = group.value; if (utils.contains(["\\imath", "\\jmath"], value)) { return null; } if (symbols[mode][value] && symbols[mode][value].replace) { value = symbols[mode][value].replace; } var fontName = fontMap[font].fontName; if (fontMetrics.getCharacterMetrics(value, fontName)) { return fontMap[options.font].variant; } return null; }
Functions for handling the different types of groups found in the parse tree. Each function should take a parse group and return a MathML node.
getVariant
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
buildExpression = function(expression, options) { var groups = []; for (var i = 0; i < expression.length; i++) { var group = expression[i]; groups.push(buildGroup(group, options)); } return groups; }
Create a new options object with the given size.
buildExpression
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
buildGroup = function(group, options) { if (!group) { return new mathMLTree.MathNode("mrow"); } if (groupTypes[group.type]) { // Call the groupTypes function return groupTypes[group.type](group, options); } else { throw new ParseError( "Got group of unknown type: '" + group.type + "'"); } }
Create a new options object with "phantom" set to true.
buildGroup
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
buildMathML = function(tree, texExpression, options) { var expression = buildExpression(tree, options); // Wrap up the expression in an mrow so it is presented in the semantics // tag correctly. var wrapper = new mathMLTree.MathNode("mrow", expression); // Build a TeX annotation of the source var annotation = new mathMLTree.MathNode( "annotation", [new mathMLTree.TextNode(texExpression)]); annotation.setAttribute("encoding", "application/x-tex"); var semantics = new mathMLTree.MathNode( "semantics", [wrapper, annotation]); var math = new mathMLTree.MathNode("math", [semantics]); // You can't style <math> nodes, so we wrap the node in a span. return makeSpan(["katex-mathml"], [math]); }
A map of color names to CSS colors. TODO(emily): Remove this when we have real macros
buildMathML
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function MathNode(type, children) { this.type = type; this.attributes = {}; this.children = children || []; }
A map of color names to CSS colors. TODO(emily): Remove this when we have real macros
MathNode
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
parseTree = function(toParse, settings) { var parser = new Parser(toParse, settings); return parser.parse(); }
Rewrites infix operators such as \over with corresponding commands such as \frac. There can only be one infix operator per group. If there's more than one then the expression is ambiguous. This can be resolved by adding {}. @returns {Array}
parseTree
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function Parser(input, settings) { // Make a new lexer this.lexer = new Lexer(input); // Store the settings for use in parsing this.settings = settings; }
Converts the textual input of an unsupported command into a text node contained within a color node whose color is determined by errorColor
Parser
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function ParseFuncOrArgument(result, isFunction) { this.result = result; // Is this a function (i.e. is it something defined in functions.js)? this.isFunction = isFunction; }
Converts the textual input of an unsupported command into a text node contained within a color node whose color is determined by errorColor
ParseFuncOrArgument
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function defineEnvironment(names, props, handler) { if (typeof names === "string") { names = [names]; } if (typeof props === "number") { props = { numArgs: props }; } // Set default values of environments var data = { numArgs: props.numArgs || 0, argTypes: props.argTypes, greediness: 1, allowedInText: !!props.allowedInText, numOptionalArgs: props.numOptionalArgs || 0, handler: handler, }; for (var i = 0; i < names.length; ++i) { module.exports[names[i]] = data; } }
This function lexes a single normal token. It takes a position and whether it should completely ignore whitespace or not.
defineEnvironment
javascript
arturssmirnovs/github-profile-readme-generator
js/markdown.js
https://github.com/arturssmirnovs/github-profile-readme-generator/blob/master/js/markdown.js
MIT
function createPrivateKey(entropy) { if (entropy) { if (!Buffer.isBuffer(entropy)) throw new Error('EthCrypto.createPrivateKey(): given entropy is no Buffer'); if (Buffer.byteLength(entropy, 'utf8') < MIN_ENTROPY_SIZE) throw new Error('EthCrypto.createPrivateKey(): Entropy-size must be at least ' + MIN_ENTROPY_SIZE); var outerHex = keccak256(entropy); return outerHex; } else { var innerHex = keccak256(ethersUtils.concat([ethersUtils.randomBytes(32), ethersUtils.randomBytes(32)])); var middleHex = ethersUtils.concat([ethersUtils.concat([ethersUtils.randomBytes(32), innerHex]), ethersUtils.randomBytes(32)]); var _outerHex = keccak256(middleHex); return _outerHex; } }
create a privateKey from the given entropy or a new one @param {Buffer} entropy @return {string}
createPrivateKey
javascript
pubkey/eth-crypto
dist/es/create-identity.js
https://github.com/pubkey/eth-crypto/blob/master/dist/es/create-identity.js
MIT