Hi there.
I'm twiddling here around with a RE problem and was wondering if you could help me.
So here is the case. I want do do some tricky Syntax highlight matching, and wanted to have the visual sidebar with the line numbers.
So in order to test this, I do inside TM Document window this:
(^[^\n]*\n)
This seems to work fine, and will select every single line in document window.
But is I test the Javascript, which is:
linenum: { exp: /(^[^\n]*\n)/, replacement: "<span class="$0"> 1</span>$1\n"
},
It doesn't do the replacement. So I also added a line-break in the replacement-string, after the capture register, as you can see above, but no honey.
As you can see, I want to replace every single in the document, with the span instance above plus the Capture Register( Just like the Ruby code does in TM Bundle ), which is the whole line, whether it is empty or not.
Any Ideas ?
regards, marios
So here is the case. I want do do some tricky Syntax highlight matching, and wanted to have the visual sidebar with the line numbers. [...] As you can see, I want to replace every single in the document, with the span instance above plus the Capture Register( Just like the Ruby code does in TM Bundle ), which is the whole line, whether it is empty or not.
Actually, it's really hard to understand what you're aiming at, here. "Just like the Ruby code does in TM Bundle"... uh, which one? What command/snippet are you referring to?
I see several ways of adding line numbers to a document (bundle name): - Create HTML From Document / Selection with Line Numbers (TextMate) - Add Line Numbers to Document / Selection (Text) - Option + Command + L will show the line numbers in the gutter...
You "want to replace every single"... what? "in the document". And I'm really perplexed by the reference to testing "the JavaScript", which AFAIK isn't what bundles are written/tested/interpreted in.
I think more clarification is required so we can understand what exactly you want to do.
~ Daniel
Daniel Stockman wrote:
So here is the case. I want do do some tricky Syntax highlight matching, and wanted to have the visual sidebar with the line numbers. [...] As you can see, I want to replace every single in the document, with the span instance above plus the Capture Register( Just like the Ruby code does in TM Bundle ), which is the whole line, whether it is empty or not.
Actually, it's really hard to understand what you're aiming at, here. "Just like the Ruby code does in TM Bundle"... uh, which one? What command/snippet are you referring to?
I see several ways of adding line numbers to a document (bundle name):
- Create HTML From Document / Selection with Line Numbers (TextMate)
- Add Line Numbers to Document / Selection (Text)
- Option + Command + L will show the line numbers in the gutter...
You "want to replace every single"... what? "in the document". And I'm really perplexed by the reference to testing "the JavaScript", which AFAIK isn't what bundles are written/tested/interpreted in.
I think more clarification is required so we can understand what exactly you want to do.
~ Daniel
Sorry for the confusion. Ok, so how do we express ourselves better? Lemmy try once more.
The question, that I am asking, is related to Regular Expressions and Javascript. ( So this is not a Support request at all )
I am working on a Plugin for Textpattern, which will use a mootools class, to append the corresponding DOM nodes with the classed span tags.
This will all happen after the code that is to be displayed syntax highlighted is already encoded to entities. That works all so far.
Now in order to get the same effect as we do have with the Make HTML document from source with Line numbers (Which is located in the TextMate Bundle and uses Ruby for that), yes the one that makes the span tags for the line numbers,I am trying to figure out, why the same Regular expression, that I mentioned in my previous post, would not work, when used as above.
( I even checked the Syntax with Flanagan's Book, also tried global matching but no luck )
So this is the task:
Match every beginning of a line, including the first line of the document, and put that in Capture register one, then match every line until the end of the Line, end put that in Capture Register 2, then replace every instance, with some extra Markup (The spantags here ) plus Capture Register 2.
This works from within TextMate, but not in Javascript.
I hope, this explains better what I meant.
regards, marios
On 20/02/2008, marios tmtxpstuff@consking.com wrote:
So this is the task:
Match every beginning of a line, including the first line of the document, and put that in Capture register one, then match every line until the end of the Line, end put that in Capture Register 2, then replace every instance, with some extra Markup (The spantags here ) plus Capture Register 2.
This works from within TextMate, but not in Javascript.
OK, so this really hasn't anything to do with TextMate. Perhaps Javascript won't let you match newline characters? Try this regular expression instead, it may work better:
^(.*)$
Sven Axelsson wrote:
On 20/02/2008, marios tmtxpstuff@consking.com wrote:
So this is the task:
Match every beginning of a line, including the first line of the document, and put that in Capture register one, then match every line until the end of the Line, end put that in Capture Register 2, then replace every instance, with some extra Markup (The spantags here ) plus Capture Register 2.
This works from within TextMate, but not in Javascript.
OK, so this really hasn't anything to do with TextMate. Perhaps Javascript won't let you match newline characters? Try this regular expression instead, it may work better:
^(.*)$
That finally didn't work, but I've good news: This finally works:
pattern: /^(\n)|(\n)/, replacement: "$2<span class="$0"></span>"
What is interesting to not here, is that this, if I'm not mistaken is the only way to achieve this. ( Took me about 2 hours to figure this out ) The first part of the RE will take care of the one line that gets lost by the second part. Sounds weird.
Here is what I have now:
http://www.consking.com/screenshots/Texari_light.png
( Also a little tricky was to get the alignment of the line-numbers right )
I call it TeXarI Light. ( A lite version of Texari )
( Looks almost like TextMate, doesn't it ? )
regrds, marios