1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.wiki.translators;
16  
17  /**
18   * <a href="ClassicToCreoleTranslator.java.html"><b><i>View Source</i></b></a>
19   *
20   * @author Jorge Ferrer
21   */
22  public class ClassicToCreoleTranslator extends BaseTranslator {
23  
24      public ClassicToCreoleTranslator() {
25          initRegexps();
26      }
27  
28      protected void initRegexps() {
29  
30          // Bold and italics
31  
32          regexps.put(
33              "'''''((?s:.)*?)('''''|(\n\n|\r\r|\r\n\r\n))", "**//$1//**$3");
34  
35          // Bold
36  
37          regexps.put("'''((?s:.)*?)('''|(\n\n|\r\r|\r\n\r\n))", "**$1**$3");
38  
39          // Italics
40  
41          regexps.put("''((?s:.)*?)(''|(\n\n|\r\r|\r\n\r\n))", "//$1//$3");
42  
43          // Link
44  
45          regexps.put("\\[([^ ]*)\\]", "[[$1]]");
46  
47          // Link with label
48  
49          regexps.put("\\[([^ ]+) (.*)\\]", "[[$1|$2]]");
50  
51          // Monospace
52  
53          regexps.put("(^ (.+))(\\n (.+))*", "{{{\n$0\n}}}");
54  
55          // List item
56  
57          regexps.put("^\\t[\\*] (.*)", "* $1");
58  
59          // List subitem
60  
61          regexps.put("^\\t\\t[\\*] (.*)", "** $1");
62  
63          // List subsubitem
64  
65          regexps.put("^\\t\\t\\t[\\*] (.*)", "*** $1");
66  
67          // List subsubsubitem
68  
69          regexps.put("^\\t\\t\\t\\t[\\*] (.*)", "**** $1");
70  
71          // Ordered list item
72  
73          regexps.put("^\\t1 (.*)", "# $1");
74  
75          // Ordered list subitem
76  
77          regexps.put("^\\t\\t1 (.*)", "## $1");
78  
79          // Ordered list subsubitem
80  
81          regexps.put("^\\t\\t\\t1 (.*)", "### $1");
82  
83          // Ordered list subsubsubitem
84  
85          regexps.put("^\\t\\t\\t\\t1 (.*)", "#### $1");
86  
87          // Term and definition
88  
89          regexps.put("^\\t([\\w]+):\\t(.*)", "**$1**:\n$2");
90  
91          // Indented paragraph
92  
93          regexps.put("^\\t:\\t(.*)", "$1");
94  
95          // CamelCase
96  
97          regexps.put(
98              "(^|\\p{Punct}|\\p{Space})((\\p{Lu}\\p{Ll}+){2,})" +
99                  "(\\z|\\n|\\p{Punct}|\\p{Space})", " [[$2]] ");
100     }
101 
102 }