User talk:Paxed/MixedSyntaxHighlight
Jump to navigation
Jump to search
Bug: regexp eats leading spaces
The regexp /^ <span id=\"line([0-9]{1,4})">[0-9]{1,4}\. *(.*)<\/span>$/
causes indentation using spaces to disappear; see e.g. Source:Pray.c#dosacrifice. Presumably, removing the first "*" (or replacing it with "?") would fix the problem. --Ilmari Karonen 07:10, 19 December 2010 (UTC)
- The problem is that lines have the same number of characters for the line numbers... but lines with fewer numbers are padded with spaces. --paxed 08:15, 19 December 2010 (UTC)
- Hmm, yeah, that's tricky... maybe you could make the regexp
/^ <span id=\"line([0-9]+)">[ 0]*\1\.( *)(.*)<\/span>$/
and do something like$text .= substr($matches[2], 5 - strlen($matches[1])) . $matches[3] . "\n";
? That should handle both left- and right-adjusted line numbers (and, coincidentally, should reject any lines where the number doesn't match the ID). --Ilmari Karonen 09:42, 19 December 2010 (UTC)- I'll look into it later today; hopefully this doesn't cause too much cpu usage increase... --paxed 10:30, 19 December 2010 (UTC)
- I don't see why it would. (If you want to optimize the CPU usage, I'd suggest collecting the pieces of text in an array and doing a single join() to concatenate them at the end.) --Ilmari Karonen 10:51, 19 December 2010 (UTC)
- I'll look into it later today; hopefully this doesn't cause too much cpu usage increase... --paxed 10:30, 19 December 2010 (UTC)
- Hmm, yeah, that's tricky... maybe you could make the regexp