Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static String genMarkdown(String text) {
        text = escapeXml(text);
        while (text.contains("[[")) {
            String left = text.substring(0, text.indexOf("[["));
            String url = text.substring(text.indexOf("[[") + 2, text.indexOf("]]"));
            String right = text.substring(text.indexOf("]]") + 2);
            text = left + "<a href=\"" + url + "\">" + url + "</a>" + right;
        }
        return text;
    }

    public static String escapeXml(String doco) {
        if (doco == null)
            return "";

        StringBuilder b = new StringBuilder();
        for (char c : doco.toCharArray()) {
            if (c == '<')
                b.append("&lt;");
            else if (c == '>')
                b.append("&gt;");
            else if (c == '&')
                b.append("&amp;");
            else if (c == '"')
                b.append("&quot;");
            else
                b.append(c);
        }
        return b.toString();
    }
}