mjbvz / vscode-fenced-code-block-grammar-injection-example

Example of injecting a new grammar into VSCode's builtin markdown syntax highlighting for fenced code blocks
MIT License
98 stars 26 forks source link

Please help me to highlight embed in XML #8

Closed Serhioromano closed 4 years ago

Serhioromano commented 4 years ago

I have successfully accomplished highlights of ST language in markdown. Now I want to do the same in XML.

I have this example

<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.0">
  <DUT Name="ST_StateMachine" Id="{55662db1-7baf-4d79-8020-5daec45ea678}">
    <Declaration><![CDATA[TYPE ST_StateMachine :
STRUCT
    uiInit      : UINT;
    uiReady     : UINT;
    uiBusy      : UINT;
    uiWaiting   : UINT;
    uiIdle      : UINT;
    uiError     : UINT;
END_STRUCT
END_TYPE
]]></Declaration>
  </DUT>
</TcPlcObject>
  1. Created xml.codeblock.json file
{
    "fileTypes": [],
    "injectionSelector": "L:text.xml",
    "patterns": [
        {
            "include": "#xml-code-block"
        }
    ],
    "repository": {
        "xml-code-block": {
            "begin": "(<)(Declaration|ST)(>)\\s*",
            "end": "\\s*(<\\/)(\\2)(>)$",
            "beginCaptures": {
                "1": {
                    "name": "punctuation.definition.tag.xml"
                },
                "3": {
                    "name": "punctuation.definition.tag.xml"
                },
                "2": {
                    "name": "entity.name.tag.localname.xml"
                }
            },
            "endCaptures": {
                "1": {
                    "name": "punctuation.definition.tag.xml"
                },
                "3": {
                    "name": "punctuation.definition.tag.xml"
                },
                "2": {
                    "name": "entity.name.tag.localname.xml"
                }
            },
            "patterns": [
                {
                    "begin": "\\s*(<!\\[CDATA\\[)\\s*",
                    "end": "\\s*(\\]\\]>)",
                    "beginCaptures": {
                        "1": {
                            "name": "string.unquoted.cdata.xml"
                        }
                    },
                    "endCaptures": {
                        "1": {
                            "name": "string.unquoted.cdata.xml"
                        }
                    },
                    "contentName": "meta.embedded.block.iecst",
                    "patterns": [
                        {
                            "include": "source.st"
                        }
                    ]
                }
            ]
        }
    },
    "scopeName": "xml.iecst.codeblock"
}
  1. Add to project.json
"grammars": [
    {
        "scopeName": "source.st",
        "language": "st",
        "path": "./syntaxes/st.tmLanguage.json"
    },
    {
        "scopeName": "markdown.iecst.codeblock",
        "path": "./syntaxes/md.codeblock.json",
        "injectTo": [
            "text.html.markdown"
        ],
        "embeddedLanguages": {
            "meta.embedded.block.iecstmd": "st"
        }
    },
    {
        "scopeName": "xml.iecst.codeblock",
        "path": "./syntaxes/xml.codeblock.json",
        "injectTo": [
            "text.xml"
        ],
        "embeddedLanguages": {
            "meta.embedded.block.iecstxml": "st"
        }
    }
],

Everything works fine except thing I cannot understand.

855D1B44-D7BD-4FBD-B20E-B9A57F83847E

Look somehow second declaration tag does not work and if I change PROTECTED key it works. If I change LIBRARY to FUNCTION_BLOCK for example it works.

I have no idea where to dig. Could you please help me?

mjbvz commented 4 years ago

Try asking for help on Stack Overflow. I don't have time to debug the grammar but if you feel there is a bug with this project, please create a minimal repo so we can investigate