Update docdown to avoid escaping characters in code snippets. [ci skip]

This commit is contained in:
John-David Dalton
2013-11-14 22:40:48 -08:00
parent 5ccd63250b
commit 0563af682d
2 changed files with 56 additions and 20 deletions

View File

@@ -999,7 +999,7 @@ _.zip(['fred', 'barney'], [30, 40], [true, false]);
### <a id="_zipobjectkeys-values"></a>`_.zipObject(keys, [values=[]])`
<a href="#_zipobjectkeys-values">#</a> [&#x24C8;](https://github.com/lodash/lodash/blob/master/lodash.js#L5333 "View in source") [&#x24C9;][1]
Creates an object composed from arrays of `keys` and `values`. Provide either a single two dimensional array, i.e. `&#91;&#91;key1, value1&#93;, &#91;key2, value2&#93;&#93;` or two arrays, one of `keys` and one of corresponding `values`.
Creates an object composed from arrays of `keys` and `values`. Provide either a single two dimensional array, i.e. `[[key1, value1], [key2, value2]]` or two arrays, one of `keys` and one of corresponding `values`.
#### Aliases
*_.object*
@@ -2273,7 +2273,7 @@ jQuery('#docs').on('click', view.onClick);
### <a id="_bindkeyobject-key-arg"></a>`_.bindKey(object, key, [arg])`
<a href="#_bindkeyobject-key-arg">#</a> [&#x24C8;](https://github.com/lodash/lodash/blob/master/lodash.js#L5484 "View in source") [&#x24C9;][1]
Creates a function that, when called, invokes the method at `object&#91;key&#93;` and prepends any additional `bindKey` arguments to those provided to the bound function. This method differs from `_.bind` by allowing bound functions to reference methods that will be redefined or don't yet exist. See http://michaux.ca/articles/lazy-function-definition-pattern.
Creates a function that, when called, invokes the method at `object[key]` and prepends any additional `bindKey` arguments to those provided to the bound function. This method differs from `_.bind` by allowing bound functions to reference methods that will be redefined or don't yet exist. See http://michaux.ca/articles/lazy-function-definition-pattern.
#### Arguments
1. `object` *(Object)*: The object the method belongs to.
@@ -3823,7 +3823,7 @@ _.omit({ 'name': 'fred', 'age': 40 }, function(value) {
### <a id="_pairsobject"></a>`_.pairs(object)`
<a href="#_pairsobject">#</a> [&#x24C8;](https://github.com/lodash/lodash/blob/master/lodash.js#L3067 "View in source") [&#x24C9;][1]
Creates a two dimensional array of an object's key-value pairs, i.e. `&#91;&#91;key1, value1&#93;, &#91;key2, value2&#93;&#93;`.
Creates a two dimensional array of an object's key-value pairs, i.e. `[[key1, value1], [key2, value2]]`.
#### Arguments
1. `object` *(Object)*: The object to inspect.
@@ -4521,7 +4521,7 @@ In IE < `9` an objects own properties, shadowing non-enumerable ones, are made n
*(boolean)*: Detect if `Array#shift` and `Array#splice` augment array-like objects correctly.
Firefox < `10`, IE compatibility mode, and IE < `9` have buggy Array `shift()` and `splice()` functions that fail to remove the last element, `value&#91;0&#93;`, of array-like objects even though the `length` property is set to `0`. The `shift()` method is buggy in IE `8` compatibility mode, while `splice()` is buggy regardless of mode in IE < `9` and buggy in compatibility mode in IE `9`.
Firefox < `10`, IE compatibility mode, and IE < `9` have buggy Array `shift()` and `splice()` functions that fail to remove the last element, `value[0]`, of array-like objects even though the `length` property is set to `0`. The `shift()` method is buggy in IE `8` compatibility mode, while `splice()` is buggy regardless of mode in IE < `9` and buggy in compatibility mode in IE `9`.
* * *

View File

@@ -27,7 +27,6 @@ class MarkdownGenerator {
/**
* The HTML for the open tag.
*
* @static
* @memberOf MarkdownGenerator
* @type string
*/
@@ -49,6 +48,15 @@ class MarkdownGenerator {
*/
public $source = '';
/**
* The array of code snippets that are tokenized by `escape`.
*
* @private
* @memberOf MarkdownGenerator
* @type Array
*/
private $snippets = array();
/*--------------------------------------------------------------------------*/
/**
@@ -132,21 +140,6 @@ class MarkdownGenerator {
return trim($string);
}
/**
* Escapes special Markdown characters.
*
* @private
* @memberOf Entry
* @param {string} $string The string to escape.
* @returns {string} Returns the escaped string.
*/
private function escape( $string ) {
$string = preg_replace('/(?<!\\\)\*/', '&#42;', $string);
$string = preg_replace('/(?<!\\\)\[/', '&#91;', $string);
$string = preg_replace('/(?<!\\\)\]/', '&#93;', $string);
return $string;
}
/**
* Modify a string by replacing named tokens with matching assoc. array values.
*
@@ -252,6 +245,23 @@ class MarkdownGenerator {
}
}
/**
* Escapes special Markdown characters.
*
* @private
* @memberOf Entry
* @param {string} $string The string to escape.
* @returns {string} Returns the escaped string.
*/
private function escape( $string ) {
$string = preg_replace_callback('/`.*?\`/', array($this, 'swapSnippetsToTokens'), $string);
$string = preg_replace('/(?<!\\\)\*/', '&#42;', $string);
$string = preg_replace('/(?<!\\\)\[/', '&#91;', $string);
$string = preg_replace('/(?<!\\\)\]/', '&#93;', $string);
$string = preg_replace_callback('/@@token@@/', array($this, 'swapTokensToSnippets'), $string);
return $string;
}
/**
* Resolves the entry's hash used to navigate the documentation.
*
@@ -298,6 +308,32 @@ class MarkdownGenerator {
return $entry->isPlugin() ? '.prototype.' : '.';
}
/**
* Swaps code snippets with tokens as a `preg_replace_callback` callback
* used by `escape`.
*
* @private
* @memberOf Entry
* @param {Array} $matches The array of regexp matches.
* @returns {string} Returns the token.
*/
private function swapSnippetsToTokens( $matches ) {
$this->snippets[] = $matches[0];
return '@@token@@';
}
/**
* Swaps tokens with code snippets as a `preg_replace_callback` callback
* used by `escape`.
*
* @private
* @memberOf Entry
* @returns {string} Returns the code snippet.
*/
private function swapTokensToSnippets() {
return array_shift($this->snippets);
}
/*--------------------------------------------------------------------------*/
/**