SubLanguage in a string ?

38 views
Skip to first unread message

HeySora

unread,
Feb 21, 2017, 5:07:04 AM2/21/17
to highlight.js
Hello !

I want to edit the XML language, but I can't do what I want.

I want to highlight correctly the XML format used in a video game.
Let's imagine I have this XML :

<Layer
    Type="Quad"
    OnCommand="%function(self)
        self:queuecommand('Update');
    end"
/>

Inside the string beginning with a "%", there is Lua.

I tried to add this in the xml.js
{
       
begin: /"%/, end: /"/,
        subLanguage
: 'lua'
},

But it doesn't change anything. The OnCommand value is still recognize as a string.

How can I fix this ? What am I doing wrong ?

Thanks !

P.S.: Here is my xml.js :

/*
Language: HTML, XML
Category: common
*/


function(hljs) {
   
var XML_IDENT_RE = '[A-Za-z0-9\\._:-]+';
   
var TAG_INTERNALS = {
        endsWithParent
: true,
        illegal
: /</,
        relevance
: 0,
        contains
: [
           
{
                className
: 'attr',
               
begin: XML_IDENT_RE,
                relevance
: 0
           
},
           
{
               
begin: /"%/, end: /"/,
                subLanguage
: 'lua'
           
},
           
{
               
begin: /=\s*/,
                relevance
: 0,
                contains
: [
                   
{
                        className
: 'string',
                        endsParent
: true,
                        variants
: [
                           
{begin: /"/, end: /"/},
                           
{begin: /'/, end: /'/},
                           
{begin: /[^\s"'=<>`]+/}
                       
]
                   
}
               
]
           
}
       
]
   
};
   
return {
        aliases
: ['html', 'xhtml', 'rss', 'atom', 'xjb', 'xsd', 'xsl', 'plist'],
        case_insensitive
: true,
        contains
: [
           
{
                className
: 'meta',
               
begin: '<!DOCTYPE', end: '>',
                relevance
: 10,
                contains
: [{begin: '\\[', end: '\\]'}]
           
},
            hljs
.COMMENT(
               
'<!--',
               
'-->',
               
{
                    relevance
: 10
               
}
           
),
           
{
               
begin: '<\\!\\[CDATA\\[', end: '\\]\\]>',
                relevance
: 10
           
},
           
{
               
begin: /<\?(php)?/, end: /\?>/,
                subLanguage
: 'php',
                contains
: [{begin: '/\\*', end: '\\*/', skip: true}]
           
},
           
{
                className
: 'tag',
               
/*
                The lookahead pattern (?=...) ensures that 'begin' only matches
                '<style' as a single word, followed by a whitespace or an
                ending braket. The '$' is needed for the lexeme to be recognized
                by hljs.subMode() that tests lexemes outside the stream.
                */

               
begin: '<style(?=\\s|>|$)', end: '>',
                keywords
: {name: 'style'},
                contains
: [TAG_INTERNALS],
                starts
: {
                   
end: '</style>', returnEnd: true,
                    subLanguage
: ['css', 'xml']
               
}
           
},
           
{
                className
: 'tag',
               
// See the comment in the <style tag about the lookahead pattern
               
begin: '<script(?=\\s|>|$)', end: '>',
                keywords
: {name: 'script'},
                contains
: [TAG_INTERNALS],
                starts
: {
                   
end: '\<\/script\>', returnEnd: true,
                    subLanguage
: ['actionscript', 'javascript', 'handlebars', 'xml']
               
}
           
},
           
{
                className
: 'meta',
                variants
: [
                   
{begin: /<\?xml/, end: /\?>/, relevance: 10},
                   
{begin: /<\?\w+/, end: /\?>/}
               
]
           
},
           
{
                className
: 'tag',
               
begin: '</?', end: '/?>',
                contains
: [
                   
{
                        className
: 'name', begin: /[^\/><\s]+/, relevance: 0
                   
},
                    TAG_INTERNALS
               
]
           
}
       
]
   
};
}



Reply all
Reply to author
Forward
0 new messages