001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.wiki.translators;
016    
017    /**
018     * @author Jorge Ferrer
019     */
020    public class ClassicToCreoleTranslator extends BaseTranslator {
021    
022            public ClassicToCreoleTranslator() {
023                    initRegexps();
024            }
025    
026            protected void initRegexps() {
027    
028                    // Bold and italics
029    
030                    regexps.put(
031                            "'''''((?s:.)*?)('''''|(\n\n|\r\r|\r\n\r\n))", "**//$1//**$3");
032    
033                    // Bold
034    
035                    regexps.put("'''((?s:.)*?)('''|(\n\n|\r\r|\r\n\r\n))", "**$1**$3");
036    
037                    // Italics
038    
039                    regexps.put("''((?s:.)*?)(''|(\n\n|\r\r|\r\n\r\n))", "//$1//$3");
040    
041                    // Link
042    
043                    regexps.put("\\[([^ ]*)\\]", "[[$1]]");
044    
045                    // Link with label
046    
047                    regexps.put("\\[([^ ]+) (.*)\\]", "[[$1|$2]]");
048    
049                    // Monospace
050    
051                    regexps.put("(^ (.+))(\\n (.+))*", "{{{\n$0\n}}}");
052    
053                    // List item
054    
055                    regexps.put("^\\t[\\*] (.*)", "* $1");
056    
057                    // List subitem
058    
059                    regexps.put("^\\t\\t[\\*] (.*)", "** $1");
060    
061                    // List subsubitem
062    
063                    regexps.put("^\\t\\t\\t[\\*] (.*)", "*** $1");
064    
065                    // List subsubsubitem
066    
067                    regexps.put("^\\t\\t\\t\\t[\\*] (.*)", "**** $1");
068    
069                    // Ordered list item
070    
071                    regexps.put("^\\t1 (.*)", "# $1");
072    
073                    // Ordered list subitem
074    
075                    regexps.put("^\\t\\t1 (.*)", "## $1");
076    
077                    // Ordered list subsubitem
078    
079                    regexps.put("^\\t\\t\\t1 (.*)", "### $1");
080    
081                    // Ordered list subsubsubitem
082    
083                    regexps.put("^\\t\\t\\t\\t1 (.*)", "#### $1");
084    
085                    // Term and definition
086    
087                    regexps.put("^\\t([\\w]+):\\t(.*)", "**$1**:\n$2");
088    
089                    // Indented paragraph
090    
091                    regexps.put("^\\t:\\t(.*)", "$1");
092    
093                    // CamelCase
094    
095                    regexps.put(
096                            "(^|\\p{Punct}|\\p{Space})((\\p{Lu}\\p{Ll}+){2,})" +
097                                    "(\\z|\\n|\\p{Punct}|\\p{Space})", " [[$2]] ");
098            }
099    
100    }