Skip to content

Commit 7a87189

Browse files
committed
markdown
1 parent 191a13f commit 7a87189

67 files changed

Lines changed: 6742 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

core/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@
9797
<groupId>commons-fileupload</groupId>
9898
<artifactId>commons-fileupload</artifactId>
9999
</dependency>
100+
<dependency>
101+
<groupId>org.markdownj</groupId>
102+
<artifactId>markdownj-core</artifactId>
103+
</dependency>
100104
</dependencies>
101105
<build>
102106
<plugins>
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
Copyright (c) 2005, Pete Bevin.
3+
<http://markdownj.petebevin.com>
4+
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without
8+
modification, are permitted provided that the following conditions are
9+
met:
10+
11+
* Redistributions of source code must retain the above copyright notice,
12+
this list of conditions and the following disclaimer.
13+
14+
* Redistributions in binary form must reproduce the above copyright
15+
notice, this list of conditions and the following disclaimer in the
16+
documentation and/or other materials provided with the distribution.
17+
18+
* Neither the name "Markdown" nor the names of its contributors may
19+
be used to endorse or promote products derived from this software
20+
without specific prior written permission.
21+
22+
This software is provided by the copyright holders and contributors "as
23+
is" and any express or implied warranties, including, but not limited
24+
to, the implied warranties of merchantability and fitness for a
25+
particular purpose are disclaimed. In no event shall the copyright owner
26+
or contributors be liable for any direct, indirect, incidental, special,
27+
exemplary, or consequential damages (including, but not limited to,
28+
procurement of substitute goods or services; loss of use, data, or
29+
profits; or business interruption) however caused and on any theory of
30+
liability, whether in contract, strict liability, or tort (including
31+
negligence or otherwise) arising in any way out of the use of this
32+
software, even if advised of the possibility of such damage.
33+
34+
*/
35+
36+
package info.xiaomo.core.markdown;
37+
38+
import java.util.Collection;
39+
import java.util.Collections;
40+
import java.util.Random;
41+
import java.util.concurrent.ConcurrentHashMap;
42+
import java.util.concurrent.ConcurrentMap;
43+
44+
public class CharacterProtector {
45+
private final ConcurrentMap<String, String> protectMap = new ConcurrentHashMap<String, String>();
46+
private final ConcurrentMap<String, String> unprotectMap = new ConcurrentHashMap<String, String>();
47+
private static final String GOOD_CHARS = "0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
48+
private Random rnd = new Random();
49+
50+
51+
public String encode(String literal) {
52+
String encoded = protectMap.get(literal);
53+
if (encoded == null) {
54+
synchronized (protectMap) {
55+
encoded = protectMap.get(literal);
56+
if (encoded == null) {
57+
encoded = addToken(literal);
58+
}
59+
}
60+
}
61+
return encoded;
62+
}
63+
64+
public String decode(String coded) {
65+
return unprotectMap.get(coded);
66+
}
67+
68+
public Collection<String> getAllEncodedTokens() {
69+
return Collections.unmodifiableSet(unprotectMap.keySet());
70+
}
71+
72+
private String addToken(String literal) {
73+
String encoded = longRandomString();
74+
75+
protectMap.put(literal, encoded);
76+
unprotectMap.put(encoded, literal);
77+
78+
return encoded;
79+
}
80+
81+
private String longRandomString() {
82+
StringBuilder sb = new StringBuilder();
83+
final int CHAR_MAX = GOOD_CHARS.length();
84+
for (int i = 0; i < 20; i++) {
85+
sb.append(GOOD_CHARS.charAt(rnd.nextInt(CHAR_MAX)));
86+
}
87+
return sb.toString();
88+
}
89+
90+
@Override
91+
public String toString() {
92+
return protectMap.toString();
93+
}
94+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
Copyright (c) 2005, Pete Bevin.
3+
<http://markdownj.petebevin.com>
4+
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without
8+
modification, are permitted provided that the following conditions are
9+
met:
10+
11+
* Redistributions of source code must retain the above copyright notice,
12+
this list of conditions and the following disclaimer.
13+
14+
* Redistributions in binary form must reproduce the above copyright
15+
notice, this list of conditions and the following disclaimer in the
16+
documentation and/or other materials provided with the distribution.
17+
18+
* Neither the name "Markdown" nor the names of its contributors may
19+
be used to endorse or promote products derived from this software
20+
without specific prior written permission.
21+
22+
This software is provided by the copyright holders and contributors "as
23+
is" and any express or implied warranties, including, but not limited
24+
to, the implied warranties of merchantability and fitness for a
25+
particular purpose are disclaimed. In no event shall the copyright owner
26+
or contributors be liable for any direct, indirect, incidental, special,
27+
exemplary, or consequential damages (including, but not limited to,
28+
procurement of substitute goods or services; loss of use, data, or
29+
profits; or business interruption) however caused and on any theory of
30+
liability, whether in contract, strict liability, or tort (including
31+
negligence or otherwise) arising in any way out of the use of this
32+
software, even if advised of the possibility of such damage.
33+
34+
*/
35+
36+
package info.xiaomo.core.markdown;
37+
38+
import java.util.regex.Pattern;
39+
40+
public class HTMLDecoder {
41+
public static String decode(String html) {
42+
TextEditor ed = new TextEditor(html);
43+
Pattern p1 = Pattern.compile("&#(\\d+);");
44+
ed.replaceAll(p1, m -> {
45+
String charDecimal = m.group(1);
46+
char ch = (char) Integer.parseInt(charDecimal);
47+
return Character.toString(ch);
48+
});
49+
50+
Pattern p2 = Pattern.compile("&#x([0-9a-fA-F]+);");
51+
ed.replaceAll(p2, m -> {
52+
String charHex = m.group(1);
53+
char ch = (char) Integer.parseInt(charHex, 16);
54+
return Character.toString(ch);
55+
});
56+
57+
return ed.toString();
58+
}
59+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package info.xiaomo.core.markdown;
2+
3+
public class HTMLToken {
4+
private boolean isTag;
5+
private String text;
6+
7+
private HTMLToken(boolean tag, String value) {
8+
isTag = tag;
9+
text = value;
10+
}
11+
12+
public static HTMLToken tag(String text) {
13+
return new HTMLToken(true, text);
14+
}
15+
16+
public static HTMLToken text(String text) {
17+
return new HTMLToken(false, text);
18+
}
19+
20+
/**
21+
* @return <code>true</code> if this is a tag, <code>false</code> if it's text.
22+
*/
23+
public boolean isTag() {
24+
return isTag;
25+
}
26+
27+
public String getText() {
28+
return text;
29+
}
30+
31+
@Override
32+
public String toString() {
33+
String type;
34+
if (isTag()) {
35+
type = "tag";
36+
} else {
37+
type = "text";
38+
}
39+
return type + ": " + getText();
40+
}
41+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
Copyright (c) 2005, Pete Bevin.
3+
<http://markdownj.petebevin.com>
4+
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without
8+
modification, are permitted provided that the following conditions are
9+
met:
10+
11+
* Redistributions of source code must retain the above copyright notice,
12+
this list of conditions and the following disclaimer.
13+
14+
* Redistributions in binary form must reproduce the above copyright
15+
notice, this list of conditions and the following disclaimer in the
16+
documentation and/or other materials provided with the distribution.
17+
18+
* Neither the name "Markdown" nor the names of its contributors may
19+
be used to endorse or promote products derived from this software
20+
without specific prior written permission.
21+
22+
This software is provided by the copyright holders and contributors "as
23+
is" and any express or implied warranties, including, but not limited
24+
to, the implied warranties of merchantability and fitness for a
25+
particular purpose are disclaimed. In no event shall the copyright owner
26+
or contributors be liable for any direct, indirect, incidental, special,
27+
exemplary, or consequential damages (including, but not limited to,
28+
procurement of substitute goods or services; loss of use, data, or
29+
profits; or business interruption) however caused and on any theory of
30+
liability, whether in contract, strict liability, or tort (including
31+
negligence or otherwise) arising in any way out of the use of this
32+
software, even if advised of the possibility of such damage.
33+
34+
*/
35+
36+
package info.xiaomo.core.markdown;
37+
38+
public class LinkDefinition {
39+
private String url;
40+
private String title;
41+
42+
public LinkDefinition(String url, String title) {
43+
this.url = url;
44+
this.title = title;
45+
}
46+
47+
public String getUrl() {
48+
return url;
49+
}
50+
51+
public String getTitle() {
52+
return title;
53+
}
54+
55+
@Override
56+
public String toString() {
57+
return url + " (" + title + ")";
58+
}
59+
}

0 commit comments

Comments
 (0)