Domanda

This is going to be a very picky question i'm afraid - and I have a feeling it will not be possible.

Situation

I need to have a textarea with highligting (Some css effect) of certain words and phrases. Previously I have got this working with editarea - however as it is a dead project more and more issues arose so I am trying an alternate more current editor - Ace.

Issue

I currenty have ace highlighting the sets of single words fine using a custom mode, however matching with the regex the phrases has proven beyond me (so far).

The relevant mode code - as it stands is below:

var highlightWords = "word1|word2|word3|phrase one|phrase number two|etc";
 var keywordMapper = this.createKeywordMapper({
     "highlightWords": highlightWords
}, "identifier", true);

this.$rules = {
    "start" : [
    {
        token : keywordMapper,
        regex : "[a-zA-Z0-9_$][a-zA-Z0-9_$]*\\b"
    },{
        token : "text",
        regex : "\\s+"
    }]

My attempt to match 2 word phrases is below (Didn't work) (Also attempted to match longer entries by adding coppies with {2} etc)

regex : "[a-zA-Z0-9_$][a-zA-Z0-9_$]*(?:\\s[a-zA-Z0-9_$][a-zA-Z0-9_$]*){1}\\b"

Anybody have any ideas for getting ace working - or any easier alternatives for live edit word & phrase highlighting?

È stato utile?

Soluzione

The regex you are passing to keywordMapper doesn't match space character.

use

this.$rules = {
    "start" : [
    {
        token : "highlightWords",
        regex : "word1|word2|word3|phrase one|phrase number two|etc"
    }]
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top