Page MenuHomePhabricator

Cannot parse source code containing < source >
Closed, ResolvedPublic

Description

Author: ronga

Description:
Originally reported at:
http://www.mediawiki.org/wiki/Extension_talk:SyntaxHighlight_GeSHi#Error_if_i_have_.3CSource.3E_inside_the_box....

The bug is tested and confirmed at:
http://bestbrute.wikia.com/index.php?title=Bestbrute_wiki:Sandbox&oldid=5415

How to reproduce bugs:
If your source code uses <source>, it will conflicts the syntax used in this extension. For example the following source code can't be parsed correctly:

<source lang="xml">
<?xml version="1.0"?>
<Object>
	<Control>
	    <Source>  // This is the original source from my XML file
	    	......
	    </Source> // This is the original source from my XML file
	</Control>
</Object>
</source>

Please fix so any <source> syntax inside the code is escaped!


Version: unspecified
Severity: major
URL: http://bestbrute.wikia.com/index.php?title=Bestbrute_wiki:Sandbox&oldid=5415

Details

Reference
bz18820

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 10:39 PM
bzimport added a project: SyntaxHighlight.
bzimport set Reference to bz18820.
bzimport added a subscriber: Unknown Object (MLST).

I don't think this is possible. The parser always chooses the first closing tag. It is impossible to know what the user really wants, so escape it yourself.

ronga wrote:

How to escape? None of the following methods work:

  • using <nowiki> tag
  • using <includeonly> tag
  • using &#60; (for obvious reasons)

It's impossible to escape it. What you can only do is to intentionally break that syntax, but this has display disadvantage and wrong syntax highlights. You have to tell the users about it too. But they often don't read so it will lead to unnecessary misunderstanding.

a)
I wonder if you could offer something like this:
http://www.mediawiki.org/w/index.php?title=Extension:Labeled_Section_Transclusion&oldid=255140#How_it_works

For example
<source begin=code1 />
this is your code
<source end=code1 />

b)
Or offer a second syntax, let's say <syntaxhighlight> or <sourcehighlight>??
So far no source code uses those syntax.

c)
Or offer a way to escape <source>??
This option is kinda suboptimal as this leads to extra work. Quite many source codes use the syntax <source> too:
http://www.google.com/codesearch?hl=en&lr=&q=%3Csource%3E&sbtn=Search

Thanks!

(In reply to comment #2)
Oh, you are correct actually, there is no way to escape it.

a)

Doesn't look nice nor easy.

b)
Or offer a second syntax, let's say <syntaxhighlight> or <sourcehighlight>??

This should be pretty easy.

c)

This would be quite ugly too, or at least I do not have any idea how to make it in nice way.

I would go for option b. If nobody opposes I will implement it shortly.

(In reply to comment #2)

How to escape? None of the following methods work:

  • using <nowiki> tag
  • using <includeonly> tag
  • using &#60; (for obvious reasons)

You could try something like

{{#tag:source|<nowiki>...Your XML
....goes ...
...here...</nowiki>|lang=xml}}

Of course this only works if you don't have a tag like </nowiki> in your XML.

Added <syntaxhighlight> alternative in r50696.

ronga wrote:

(In reply to comment #4)

(In reply to comment #2)

How to escape? None of the following methods work:

  • using <nowiki> tag
  • using <includeonly> tag
  • using &#60; (for obvious reasons)

You could try something like

{{#tag:source|<nowiki>...Your XML
....goes ...
...here...</nowiki>|lang=xml}}

Of course this only works if you don't have a tag like </nowiki> in your XML.

Put <nowiki> before and after the XML code defeats the purpose of this extension.
It's to highlight the codes with colors and formatting. Syntax highlight is disabled when inside <nowiki>.

After all I think either option (a) or (b) is the ideal way to solve this problem.
It seems solved now. :)