1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.wiki.translators;
24  
25  /**
26   * <a href="ClassicToCreoleTranslator.java.html"><b><i>View Source</i></b></a>
27   *
28   * @author Jorge Ferrer
29   */
30  public class ClassicToCreoleTranslator extends BaseTranslator {
31  
32      public ClassicToCreoleTranslator() {
33          initRegexps();
34      }
35  
36      protected void initRegexps() {
37  
38          // Bold and italics
39  
40          regexps.put(
41              "'''''((?s:.)*?)('''''|(\n\n|\r\r|\r\n\r\n))", "**//$1//**$3");
42  
43          // Bold
44  
45          regexps.put("'''((?s:.)*?)('''|(\n\n|\r\r|\r\n\r\n))", "**$1**$3");
46  
47          // Italics
48  
49          regexps.put("''((?s:.)*?)(''|(\n\n|\r\r|\r\n\r\n))", "//$1//$3");
50  
51          // Link
52  
53          regexps.put("\\[([^ ]*)\\]", "[[$1]]");
54  
55          // Link with label
56  
57          regexps.put("\\[([^ ]+) (.*)\\]", "[[$1|$2]]");
58  
59          // Monospace
60  
61          regexps.put("(^ (.+))(\\n (.+))*", "{{{\n$0\n}}}");
62  
63          // List item
64  
65          regexps.put("^\\t[\\*] (.*)", "* $1");
66  
67          // List subitem
68  
69          regexps.put("^\\t\\t[\\*] (.*)", "** $1");
70  
71          // List subsubitem
72  
73          regexps.put("^\\t\\t\\t[\\*] (.*)", "*** $1");
74  
75          // List subsubsubitem
76  
77          regexps.put("^\\t\\t\\t\\t[\\*] (.*)", "**** $1");
78  
79          // Ordered list item
80  
81          regexps.put("^\\t1 (.*)", "# $1");
82  
83          // Ordered list subitem
84  
85          regexps.put("^\\t\\t1 (.*)", "## $1");
86  
87          // Ordered list subsubitem
88  
89          regexps.put("^\\t\\t\\t1 (.*)", "### $1");
90  
91          // Ordered list subsubsubitem
92  
93          regexps.put("^\\t\\t\\t\\t1 (.*)", "#### $1");
94  
95          // Term and definition
96  
97          regexps.put("^\\t([\\w]+):\\t(.*)", "**$1**:\n$2");
98  
99          // Indented paragraph
100 
101         regexps.put("^\\t:\\t(.*)", "$1");
102 
103         // CamelCase
104 
105         regexps.put(
106             "(^|\\p{Punct}|\\p{Space})((\\p{Lu}\\p{Ll}+){2,})" +
107                 "(\\z|\\n|\\p{Punct}|\\p{Space})", " [[$2]] ");
108     }
109 
110 }