ITextProcessor

Certain standard content components in Veva, such as the heading and paragraph components, can be extended with "text processors".  The Markdown support is provided with a text processor which converts markdown syntax to HTML, for example.  You can extend this functionality by implementing your own text processor.  A text processor needs to implement the Process() method which receives a TextProcessorContext class and the raw content to process.  It needs to return a list of ITextTokens.  There are two types of text tokens available, MarkupTextToken and PlainTextToken.  If the processor returns HTML markup which needs to be rendered out to the page as markup, then it should return MarkupTextTokens, otherwise it should just return PlainTextTokens.  If you try to return an HTML string as a PlainTextToken, it will be escaped to HTML entities and just printed out on the page as is, i.e not rendered as HTML.

Interface declaration

public interface ITextProcessor
{
	IEnumerable<ITextToken> Process(TextProcessorContext context, string input);
}

Example

In this example, we implement a text processor which makes all occurences of the word Veva bold.  This text processor will return a mix of plain text tokens and markup tokens.  It uses the standard <strong> tag to make the text bold, so in order for it to have an effect, it needs to returned as a markup token but the rest of the string can be returned as a plain text token.

[DisplayName("Make Veva bold!")]
[Description("Makes all instances of the word Veva become bold")]
public class MakeVevaBoldTextProcessor : ITextProcessor
{
    public IEnumerable<ITextToken> Process(TextProcessorContext context, string input)
    {
        var result = new List<ITextToken>();

        if (!string.IsNullOrEmpty(input))
        {
            var words = input.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            foreach (var word in words)
            {
                if (word.Equals("Veva", StringComparison.InvariantCultureIgnoreCase))
                {
                    result.Add(new MarkupTextToken($"<strong>{word}</strong>"));
                }
                else
                {
                    result.Add(new PlainTextToken(word));
                }

                result.Add(new PlainTextToken(" "));
            }
        }
        
        return result;
    }
}

Registration

This is how the implementation is registered into the DI container in Veva, this should be done in your module config file (The class which implements IModule).

public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
    services.AddNamed<ITextProcessor, MakeVevaBoldTextProcessor>(ServiceLifetime.Transient);
}

To use a text processor, go to the websites section in Veva, click the website and then go to the "Text processing settings" tab. There you'll see a list of all registered text processors. Add the text processor you wish to add, and then save the website settings.