Item9389: Improve TML syntax highlighting

pencil
Priority: Enhancement
Current State: Closed
Released In: 1.1.0
Target Release: minor
Applies To: Extension
Component: JQueryPlugin
Branches:
Reported By: MichaelTempest
Waiting For:
Last Change By: KennethLavrsen
It is great having syntax highlighting for TML, but there is room for improvement.

  • Before this change:
    tml-chili-before.png

  • The first take at addressing this task:
    tml-chili-sample.png

  • The test TML:

%INCLUDE{"doc:Foswiki::IncludeHandlers::doc" pattern="(Foswiki .*?protocol)" warn="magic $topic foo"}% 

%FOO{"bar" baz='qu"ux' pox="\"eeuw\"" spim="moo"}% 
 
%JQPLUGINS{"chili" 
  format=" 
    Homepage: $homepage <br /> 
    Author(s): $author <br /> 
    Version: $version 
  " 
  extra="foo" 
}% 
 
%SEARCH{ "[T]opicClassification.*?value=\"[P]ublicFAQ\"" scope="text" type="regex" nonoise="on" format="| [[$topic]] | $formfield(OperatingSystem) | $formfield(OsVersion) |" }% 
 
%SEARCH{ "\*Back to:\* FrequentlyAskedQuestions" scope="text" type="regex" header="FAQs:" format="   * $pattern(.*?FAQ\:[\n\r]*([^\n\r]+).*) [[$topic][Answer...]]" footer="Found $ntopics FAQ topics" nonoise="on" }% 
 
%SEARCH{ "culture" format="   * $topic ref'd by --&gt; $n      * $percentSEARCH{ \"$topic\" format=\"$dollartopic\" separator=\", \" }$nop%" nonoise="on" }% 
 
&alpha; zzz &#62; zzz &#x3b5; 

-- MichaelTempest - 25 Jul 2010

Xcellent. Now here's some nested macro that doesnt hilite correctly. Maybe you have an idea how to fix it.

You type:

%MACRO{
   attr="
      blabla
      %MACRO{attr="blabla"}%
      blabla
   "
}%

You get:

ChiliSnap1.png

If that's not doable easily, I actually prefer the version with less highlightning. Maybe I just need to get used to it.

-- MichaelDaum - 26 Jul 2010

Good point - and when it doesn't work, I prefer the version without the background shading, too.

More generally:
%MACRO{
   attr="
      blabla
      %MACRO{attr="blabla"
             nother="bla%MAC%EN%RO{"foo"}%bla"}%
      blabla
   "
}%

I will see what I can do smile

-- MichaelTempest - 26 Jul 2010

Michael - How does it look now?

More examples:
<img href="%ATTACHURL%/image.gif" /> 
 
<!--[if IE]><style type="text/css" media="screen"> 
pre { 
   height:1%; 
   overflow-x:auto; 
} 
</style> 
<![endif]--> 
 
<font color="red">red text</font> 
 
<!-- hello --> 
 
<script foo="bar"> 
  var f = function ( apple) 
  { 
    alert("hello" + apple); 
  } 
  f('raisin'); 
</script> 

... and here is an example from GluePlugin:

%~~ SEARCH{ 
#~~ ################################# 
#~~ # this is the search expression 
~~~   "..." 
~~~ 
~~~   type="query" 
~~~ 
#~~ ################################# 
#~~ # this is the header of the result table 
~~~  
~~~   header=" 
~~~      <table 
~~~        width='100%' 
~~~        border=\"5px\" 
~~~      > 
~~~      <thead> 
~~~        <tr> 
~~~          <th>Name</th> 
~~~          <th>Description</th> 
~~~          <th>Date</th> 
~~~        </tr> 
~~~      </thead>" 
#~~ ################################# 
#~~ # every row will be formatted like this 
~~~ 
~~~   format=" 
~~~      <tr> 
~~~        <th>$formfield(Name)</th> 
~~~        <th>$summary</th> 
~~~        <th>$createdate</th> 
~~~      </tr>" 
#~~ ################################# 
#~~ # and finally we close this html table 
~~~ 
~~~   footer="</table>" 
~~~ }% 

-- MichaelTempest - 30 Jul 2010

This looks marvelous. Strangely, some parameter names don't get green:

ChiliSnap2.png

-- MichaelDaum - 30 Jul 2010

Those parameter names are not green because they are not recognised as parameter names. The pattern matches name="value", but it can only do that if it knows which is the closing ". That is a problem with nested macros that are intended to be evaluated inside out.

I see only one way to get it right, and that is to parse the macros and attributes in the same way that Foswiki does. I cannot figure out how to do it with regexes.

-- MichaelTempest - 30 Jul 2010

Okay then leave it as it is. Gr8.

-- MichaelDaum - 31 Jul 2010

While it was interesting the first time to use the :hover pseudoclass to hilite parameter arguments, I find this effect too flickering and more confusing than helpful, i.e. as matching the correct quote isn't working out 100% without reimplementing parsing macros and arguments in javascript. Let's please remove this for the sake of simplicity.

-- MichaelDaum - 09 Aug 2010

Okay - I removed that :hover shading.

-- MichaelTempest - 14 Aug 2010

 

I Attachment Action Size Date Who Comment
ChiliSnap1.pngpng ChiliSnap1.png manage 6 K 26 Jul 2010 - 08:51 MichaelDaum  
ChiliSnap2.pngpng ChiliSnap2.png manage 18 K 30 Jul 2010 - 18:58 MichaelDaum  
tml-chili-before.pngpng tml-chili-before.png manage 15 K 25 Jul 2010 - 21:02 MichaelTempest Before this change
tml-chili-sample.pngpng tml-chili-sample.png manage 19 K 25 Jul 2010 - 21:03 MichaelTempest The first take at addressing this task
Topic revision: r22 - 22 Sep 2010, KennethLavrsen
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy