Question

I'm working on a bundle for DocBook 5 XML, which frequently includes content like:

<section>
  <title>This is my awesome Java Class called <classname>FunBunny</classname></title>
  <para>FunBunny is your friend.</para>
</section>

I want the titles for sections to appear in the function popup at the bottom of the window. I have this partially working using the following bundle items.

Language Grammar:

{   patterns = (
    {   name = 'meta.tag.xml.docbook5.title';
        match = '<title>(.*?)</title>';
        /* patterns = ( { include = 'text.xml'; } ); */
    },
    {   include = 'text.xml'; },
);
}

Settings/Preferences Item with scope selector meta.tag.xml.docbook5.title:

{   showInSymbolList = 1;
symbolTransformation = 's/^\s*<title\s?.*?>\s*(.*)\s*<\/title>/$1/';
}

The net effect of this is that all title elements in the document are matched and appear in the function popup, excluding the <title></title> tag content based on the symbolTransformation.

I would be happy with this much functionality, since other interesting things (like figures) tend to have formal titles, but there is one issue.

The content of the title tags is not parsed and recognized according to the rest of the text.xml language grammar. The commented-out patterns section in the above language grammar does not have the desired effect of fixing this issue -- it puts everything into the meta.tag.xml.docbook5.title scope.

Is there a way to get what I want here? That is, the content of the title elements, optionally just for section titles, in the function popup and recognized as normal XML content by the parser.

Was it helpful?

Solution

In TextMate grammars you need to use the begin/end type rules instead of match type rules, if you want to 'match within a match'. (You can actually use a match as well, but then you need to use currently undocumented behavior, available only for TextMate 2)

{   patterns = (
    {   name = 'meta.tag.xml.docbook5.title';
        begin = '<title>';
        end = '</title>';
        patterns = ( { include = 'text.xml'; } ); 
    },
    {   include = 'text.xml'; },
);
}

This has the added benefit of allowing <title>...</title> that span more than one line.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top