Package org.sonar.api.web

Examples of org.sonar.api.web.CodeColorizerFormat


  public CodeColorizers() {
    this(Lists.<CodeColorizerFormat>newArrayList());
  }

  public String toHtml(String code, String language) {
    CodeColorizerFormat format = byLang.get(language);
    List<Tokenizer> tokenizers;
    if (format == null) {
      tokenizers = Collections.emptyList();
    } else {
      tokenizers = format.getTokenizers();
    }
    return new CodeColorizer(tokenizers).toHtml(new StringReader(code), HtmlOptions.ONLY_SYNTAX);
  }
View Full Code Here


import static org.fest.assertions.Assertions.assertThat;

public class CodeColorizersTest {
  @Test
  public void colorize_source_code() throws Exception {
    CodeColorizerFormat format = new LiteralFormat("java");
    CodeColorizers colorizers = new CodeColorizers(Arrays.asList(format));

    String html = colorizers.toHtml("String s = \"foo\";", "java");
    assertThat(html).isEqualTo("String s = <span class=\"s\">\"foo\"</span>;");
  }
View Full Code Here

    assertThat(html).isEqualTo("String s = <span class=\"s\">\"foo\"</span>;");
  }

  @Test
  public void do_not_fail_if_unsupported_language() throws Exception {
    CodeColorizerFormat format = new LiteralFormat("java");
    CodeColorizers colorizers = new CodeColorizers(Arrays.asList(format));

    String html = colorizers.toHtml("String s = \"foo\";", "groovy");
    assertThat(html).isEqualTo("String s = \"foo\";");
  }
View Full Code Here

TOP

Related Classes of org.sonar.api.web.CodeColorizerFormat

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.