@@ -132,6 +132,21 @@ private static function format( $string ) {
132
132
return trim ($ string );
133
133
}
134
134
135
+ /**
136
+ * Escapes special Markdown characters.
137
+ *
138
+ * @private
139
+ * @memberOf Entry
140
+ * @param {string} $string The string to escape.
141
+ * @returns {string} Returns the escaped string.
142
+ */
143
+ private function escape ( $ string ) {
144
+ $ string = preg_replace ('/(?<! \\\)\*/ ' , '* ' , $ string );
145
+ $ string = preg_replace ('/(?<! \\\)\[/ ' , '[ ' , $ string );
146
+ $ string = preg_replace ('/(?<! \\\)\]/ ' , '] ' , $ string );
147
+ return $ string ;
148
+ }
149
+
135
150
/**
136
151
* Modify a string by replacing named tokens with matching assoc. array values.
137
152
*
@@ -188,7 +203,14 @@ private function addEntries( &$result, $entries ) {
188
203
array_push (
189
204
$ result ,
190
205
$ this ->openTag ,
191
- MarkdownGenerator::interpolate ("### <a id= \"#{hash} \"></a>`#{member}#{separator}#{call}` \n<a href= \"##{hash} \">#</a> [Ⓢ](#{href} \"View in source \") [Ⓣ][1] \n\n#{desc} " , $ entry )
206
+ MarkdownGenerator::interpolate ("### <a id= \"#{hash} \"></a>`#{member}#{separator}#{call}` \n<a href= \"##{hash} \">#</a> [Ⓢ](#{href} \"View in source \") [Ⓣ][1] \n\n#{desc} " , array (
207
+ 'call ' => $ entry ->getCall (),
208
+ 'desc ' => $ this ->escape ($ entry ->getDesc ()),
209
+ 'hash ' => $ entry ->hash ,
210
+ 'href ' => $ entry ->href ,
211
+ 'member ' => $ entry ->member ,
212
+ 'separator ' => $ entry ->separator
213
+ ))
192
214
);
193
215
194
216
// @alias
@@ -204,10 +226,10 @@ private function addEntries( &$result, $entries ) {
204
226
array_push ($ result , '' , '#### Arguments ' );
205
227
foreach ($ params as $ index => $ param ) {
206
228
$ result [] = MarkdownGenerator::interpolate ('#{num}. `#{name}` (#{type}): #{desc} ' , array (
207
- 'desc ' => $ param [2 ],
229
+ 'desc ' => $ this -> escape ( $ param [2 ]) ,
208
230
'name ' => $ param [1 ],
209
231
'num ' => $ index + 1 ,
210
- 'type ' => preg_replace ( ' /(?<! \\ \)(\*)/ ' , '\\ \$1 ' , $ param [0 ])
232
+ 'type ' => $ this -> escape ( $ param [0 ])
211
233
));
212
234
}
213
235
}
@@ -217,8 +239,8 @@ private function addEntries( &$result, $entries ) {
217
239
$ result , '' ,
218
240
'#### Returns ' ,
219
241
MarkdownGenerator::interpolate ('(#{type}): #{desc} ' , array (
220
- 'desc ' => $ returns [1 ],
221
- 'type ' => preg_replace ( ' /(?<! \\ \)(\*)/ ' , '\\ \$1 ' , $ returns [0 ])
242
+ 'desc ' => $ this -> escape ( $ returns [1 ]) ,
243
+ 'type ' => $ this -> escape ( $ returns [0 ])
222
244
))
223
245
);
224
246
}
@@ -246,7 +268,7 @@ private function getHash( $entry, $member = '' ) {
246
268
$ result = ($ member ? $ member . ($ entry ->isPlugin () ? 'prototype ' : '' ) : '' ) . $ entry ->getCall ();
247
269
$ result = preg_replace ('/\(\[|\[\]/ ' , '' , $ result );
248
270
$ result = preg_replace ('/[\t =| \'"{}.()\]]/ ' , '' , $ result );
249
- $ result = preg_replace ('/[[#,]/ ' , '- ' , $ result );
271
+ $ result = preg_replace ('/[\ [#,]+ / ' , '- ' , $ result );
250
272
return strtolower ($ result );
251
273
}
252
274
@@ -347,6 +369,7 @@ public function generate() {
347
369
foreach ($ api as $ entry ) {
348
370
$ entry ->hash = $ this ->getHash ($ entry );
349
371
$ entry ->href = $ this ->getLineUrl ($ entry );
372
+ $ entry ->separator = '' ;
350
373
351
374
$ member = $ entry ->getMembers (0 );
352
375
$ member = ($ member ? $ member . $ this ->getSeparator ($ entry ) : '' ) . $ entry ->getName ();
@@ -448,7 +471,7 @@ function sortCompare($a, $b) {
448
471
}
449
472
// assign TOC hash
450
473
if (count ($ result ) == 2 ) {
451
- $ toc = $ category ;
474
+ $ toc = strtolower ( $ category) ;
452
475
}
453
476
// add category
454
477
array_push (
@@ -564,4 +587,4 @@ function sortCompare($a, $b) {
564
587
return trim (preg_replace ('/[\t ]+\n/ ' , "\n" , join ($ result , "\n" )));
565
588
}
566
589
}
567
- ?>
590
+ ?>
0 commit comments