Skip to content
This repository has been archived by the owner on Oct 26, 2022. It is now read-only.

Commit

Permalink
Add new syntax for enabled Prism plugins
Browse files Browse the repository at this point in the history
New syntaxes:
  * ln or linenumber
  * hl or highlight
  * cmd
  • Loading branch information
Siavash Safi committed Aug 24, 2017
1 parent 9f18403 commit 91a5df1
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 6 deletions.
10 changes: 9 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.catawiki.jira</groupId>
<artifactId>prism</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>

<organization>
<name>Catawiki B.V.</name>
Expand Down Expand Up @@ -160,6 +160,14 @@
<verbose>false</verbose>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
172 changes: 168 additions & 4 deletions src/main/java/com/catawiki/jira/prism/Code.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,46 @@ public RenderMode getBodyRenderMode() {
public String execute(Map<String, Object> parameters, String body, RenderContext renderContext) throws MacroException {

ImmutableMap.Builder<String, Object> templateParams = ImmutableMap.builder();

// Code body
templateParams.put("content", body);
String language = "ruby";
if (parameters.get("0") != null) {
language = (String) parameters.get("0");

// line numbers (optional)
if (parameters.containsValue("linenumbers") || parameters.containsValue("ln")) {
templateParams.put("linenumbers", true);
}

for (Map.Entry<String, Object> entry : parameters.entrySet()) {
switch (entry.getKey()) {
case "highlight":
case "hl":
templateParams.put("highlight", (String) entry.getValue());
break;
case "commandline":
case "cmd":
String cmd = (String) entry.getValue();
String parts[] = cmd.split(">");
String prompt[] = parts[0].split("@");
String output = parts[1];
String user = prompt[0];
String host = prompt[1];
templateParams.put("commandline", true);
templateParams.put("user", user);
templateParams.put("host", host);
templateParams.put("output", output);
break;
default:
}
}

if (parameters.containsKey("0")) {
String language = "ruby";
String parameter = (String) parameters.get("0");
if (checkLanguage(parameter)) {
language = parameter;
}
templateParams.put("language", language);
}
templateParams.put("language", language);

try {
return this.soyTemplateRenderer.render(
Expand All @@ -52,4 +86,134 @@ public String execute(Map<String, Object> parameters, String body, RenderContext
return String.format(FALLBACK_RENDER_OUTPUT, body);
}
}

private Boolean checkLanguage(String language) {
switch (language) {
case "abap":
case "actionscript":
case "ada":
case "apacheconf":
case "apl":
case "applescript":
case "asciidoc":
case "aspnet":
case "autohotkey":
case "autoit":
case "bash":
case "basic":
case "batch":
case "bison":
case "brainfuck":
case "bro":
case "c":
case "clike":
case "coffeescript":
case "cpp":
case "crystal":
case "csharp":
case "css":
case "css-extras":
case "d":
case "dart":
case "diff":
case "django":
case "docker":
case "eiffel":
case "elixir":
case "erlang":
case "fortran":
case "fsharp":
case "gherkin":
case "git":
case "glsl":
case "go":
case "graphql":
case "groovy":
case "haml":
case "handlebars":
case "haskell":
case "haxe":
case "http":
case "icon":
case "inform7":
case "ini":
case "j":
case "jade":
case "java":
case "javascript":
case "jolie":
case "json":
case "jsx":
case "julia":
case "keyman":
case "kotlin":
case "latex":
case "less":
case "livescript":
case "lolcode":
case "lua":
case "makefile":
case "markdown":
case "markup":
case "matlab":
case "mel":
case "mizar":
case "monkey":
case "nasm":
case "nginx":
case "nim":
case "nix":
case "nsis":
case "objectivec":
case "ocaml":
case "oz":
case "parigp":
case "parser":
case "pascal":
case "perl":
case "php":
case "php-extras":
case "powershell":
case "processing":
case "prolog":
case "properties":
case "protobuf":
case "puppet":
case "pure":
case "python":
case "q":
case "qore":
case "r":
case "reason":
case "rest":
case "rip":
case "roboconf":
case "ruby":
case "rust":
case "sas":
case "sass":
case "scala":
case "scheme":
case "scss":
case "smalltalk":
case "smarty":
case "sql":
case "stylus":
case "swift":
case "tcl":
case "textile":
case "twig":
case "typescript":
case "vbnet":
case "verilog":
case "vhdl":
case "vim":
case "wiki":
case "xojo":
case "yaml":
return true;
default:
return false;
}
}
}
17 changes: 16 additions & 1 deletion src/main/resources/soy/prism.soy
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,22 @@
/**
* @param content
* @param? language
* @param? linenumbers
* @param? highlight
* @param? commandline
* @param? user
* @param? host
* @param? output
*/
{template .html}
<pre><code{if $language} class="language-{$language}{/if}">{$content}</code></pre>
<pre
{if $linenumbers} class="line-numbers" {/if}
{if $highlight} data-line="{$highlight}" {/if}
{if $commandline} class="command-line" {/if}
{if $user} data-user="{$user}" {/if}
{if $host} data-host="{$host}" {/if}
{if $output} data-output="{$output}" {/if}
>
<code {if $language} class="language-{$language}" {/if}>{$content}</code>
</pre>
{/template}

0 comments on commit 91a5df1

Please sign in to comment.