0

I am using Alex Gorbatchev's Syntax Highlighter to output some code, but I'm getting an issue where it's not retaining the initial indentation if I start the line with a php echo. For example where I would expect the following:

<pre class="brush: php;">
    <?php
        echo $variable->getScope() . " ";
        echo $variable->getName();
    ?>;
</pre>

to output the following:

    protected $variable;

it instead outputs the following:

protected $variable;

losing the indented four spaces. If I add a piece of static text on the line above it retains the spaces as intended.

I've also tried changing the third line to the following:

echo "    ".$variable->getScope() . " ";

which also has no effect. Here is the javascript where I am initialising Syntax Highlighter:

SyntaxHighlighter.defaults['gutter'] = false;
SyntaxHighlighter.defaults['toolbar'] = false;
SyntaxHighlighter.all()

To clarify, the highlighter is functioning as expected in every other way.

Any Ideas?

unfrev
  • 737
  • 1
  • 5
  • 19

1 Answers1

0

The syntax highlighter will indent the code, and it sees your code is in no bracket and so it does not indent. Code in a function will e.g. get indented.

tobspr
  • 8,200
  • 5
  • 33
  • 46
  • This does kind of seem to be the issue - it appears that the highlighter only adds formatting when it is in relation to another line, so if there is only one line all the indentation will be removed. – unfrev Nov 26 '12 at 15:57
  • I'm sure it indends your code automatically. Try `\n{\npublic $var;\n}` – tobspr Nov 26 '12 at 16:10
  • It doesn't seem to, it only indents when it is indented relative to another line. – unfrev Nov 26 '12 at 16:26
  • I have accepted this answer as it led to the issue which was that code that is not in relation to anything does not indent. – unfrev Dec 05 '12 at 09:33