Skip to content

How to add kind of validation for text? #411

Answered by NickRimmer
NickRimmer asked this question in Q&A
Discussion options

You must be logged in to vote

I found transformers, and at least we can set Background if it wasn't set by TextMate rules before.

Transformer example

public class ValidationDocumentTransformer : DocumentColorizingTransformer
{
    protected override void ColorizeLine(DocumentLine line)
    {
        var lineStartOffset = line.Offset;
        var text = CurrentContext.Document.GetText(line.Offset, line.Length);

        // check for {{...}} in the text
        var matches = Regex.Matches(text, @"{{(.+)}}");
        foreach (Match match in matches)
        {
            // TODO validation logic here
            if (match.Groups[1].Value.Equals("valid_text", StringComparison.Ordinal))
                continue;

            

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@NickRimmer
Comment options

@NickRimmer
Comment options

Answer selected by NickRimmer
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants