diff --git a/live_templates/src/main/java/org/intellij/sdk/liveTemplates/TitleCaseMacro.java b/live_templates/src/main/java/org/intellij/sdk/liveTemplates/TitleCaseMacro.java new file mode 100644 index 000000000..92a8367ca --- /dev/null +++ b/live_templates/src/main/java/org/intellij/sdk/liveTemplates/TitleCaseMacro.java @@ -0,0 +1,41 @@ +// Copyright 2000-2020 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + +package org.intellij.sdk.liveTemplates; + +import com.intellij.codeInsight.template.*; +import com.intellij.codeInsight.template.macro.MacroBase; +import com.intellij.openapi.util.text.StringUtil; +import org.jetbrains.annotations.NotNull; + +public class TitleCaseMacro extends MacroBase { + + public TitleCaseMacro() { + super("TitleCase", "TitleCase(String)"); + } + + /** + * Strictly to uphold contract for constructors in base class. + */ + private TitleCaseMacro(String name, String description) { + super(name, description); + } + + @Override + protected Result calculateResult(@NotNull Expression[] params, ExpressionContext context, boolean quick) { + String text = getTextResult(params, context, true); + if (text != null) { + if (text.length() > 0) { + text = StringUtil.toTitleCase(text); + } + return new TextResult(text); + } + return null; + } + + @Override + public boolean isAcceptableInContext(TemplateContextType context) { + // Might want to be less restrictive in future + return (context instanceof MarkdownContext); + } + +} diff --git a/live_templates/src/main/resources/META-INF/plugin.xml b/live_templates/src/main/resources/META-INF/plugin.xml index 3071d91bd..86e64d89a 100644 --- a/live_templates/src/main/resources/META-INF/plugin.xml +++ b/live_templates/src/main/resources/META-INF/plugin.xml @@ -34,8 +34,12 @@ IntelliJ Platform SDK + + + + \ No newline at end of file diff --git a/live_templates/src/main/resources/liveTemplates/Markdown.xml b/live_templates/src/main/resources/liveTemplates/Markdown.xml index 611af85f9..69a7c72ad 100644 --- a/live_templates/src/main/resources/liveTemplates/Markdown.xml +++ b/live_templates/src/main/resources/liveTemplates/Markdown.xml @@ -10,4 +10,15 @@