Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
solo-1
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
solo-1
Commits
bfc0c295
Commit
bfc0c295
authored
Dec 16, 2017
by
Liang Ding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
✨
Fix #12383
parent
d3c0584d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
2 deletions
+57
-2
pom.xml
pom.xml
+8
-1
src/main/java/org/b3log/solo/util/Markdowns.java
src/main/java/org/b3log/solo/util/Markdowns.java
+49
-1
No files found.
pom.xml
View file @
bfc0c295
<?xml version="1.0" encoding="UTF-8"?>
<!--
Description: Solo POM.
Version: 3.1
7.2.50, Nov 9
, 2017
Version: 3.1
8.2.50, Dec 16
, 2017
Author: <a href="http://88250.b3log.org">Liang Ding</a>
Author: <a href="http://www.annpeter.cn">Ann Peter</a>
Author: <a href="http://vanessa.b3log.org">Vanessa</a>
...
...
@@ -85,6 +85,7 @@
<qiniu.version>
7.0.4.1
</qiniu.version>
<jetty.version>
9.2.9.v20150224
</jetty.version>
<commons-cli.version>
1.3.1
</commons-cli.version>
<commons-codec.version>
1.10
</commons-codec.version>
<emoji-java.version>
3.2.0
</emoji-java.version>
<jodd.version>
3.6.6
</jodd.version>
<snakeyaml.version>
1.18
</snakeyaml.version>
...
...
@@ -215,6 +216,12 @@
<version>
${snakeyaml.version}
</version>
</dependency>
<dependency>
<groupId>
commons-codec
</groupId>
<artifactId>
commons-codec
</artifactId>
<version>
${commons-codec.version}
</version>
</dependency>
<dependency>
<groupId>
org.mockito
</groupId>
<artifactId>
mockito-all
</artifactId>
...
...
src/main/java/org/b3log/solo/util/Markdowns.java
View file @
bfc0c295
...
...
@@ -19,9 +19,12 @@ import com.vladsch.flexmark.html.HtmlRenderer;
import
com.vladsch.flexmark.profiles.pegdown.Extensions
;
import
com.vladsch.flexmark.profiles.pegdown.PegdownOptionsAdapter
;
import
com.vladsch.flexmark.util.options.DataHolder
;
import
org.apache.commons.codec.digest.DigestUtils
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.b3log.latke.Latkes
;
import
org.b3log.latke.cache.Cache
;
import
org.b3log.latke.cache.CacheFactory
;
import
org.b3log.latke.ioc.LatkeBeanManagerImpl
;
import
org.b3log.latke.logging.Level
;
import
org.b3log.latke.logging.Logger
;
...
...
@@ -30,6 +33,7 @@ import org.b3log.latke.service.LangPropsServiceImpl;
import
org.b3log.latke.util.Callstacks
;
import
org.b3log.latke.util.Stopwatchs
;
import
org.b3log.latke.util.Strings
;
import
org.json.JSONObject
;
import
org.jsoup.Jsoup
;
import
org.jsoup.nodes.Document
;
...
...
@@ -48,7 +52,7 @@ import java.util.concurrent.*;
* </p>
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 2.
2
.0.6, Dec 16, 2017
* @version 2.
3
.0.6, Dec 16, 2017
* @since 0.4.5
*/
public
final
class
Markdowns
{
...
...
@@ -63,6 +67,11 @@ public final class Markdowns {
*/
private
static
final
LangPropsService
LANG_PROPS_SERVICE
=
LatkeBeanManagerImpl
.
getInstance
().
getReference
(
LangPropsServiceImpl
.
class
);
/**
* Markdown cache.
*/
private
static
final
Cache
MD_CACHE
=
CacheFactory
.
getCache
(
"markdown"
);
/**
* Markdown to HTML timeout.
*/
...
...
@@ -98,6 +107,8 @@ public final class Markdowns {
public
static
boolean
MARKED_AVAILABLE
;
static
{
MD_CACHE
.
setMaxCount
(
1024
*
10
*
4
);
try
{
final
URL
url
=
new
URL
(
MARKED_ENGINE_URL
);
final
HttpURLConnection
conn
=
(
HttpURLConnection
)
url
.
openConnection
();
...
...
@@ -144,6 +155,11 @@ public final class Markdowns {
return
""
;
}
final
String
cachedHTML
=
getHTML
(
markdownText
);
if
(
null
!=
cachedHTML
)
{
return
cachedHTML
;
}
final
ExecutorService
pool
=
Executors
.
newSingleThreadExecutor
();
final
long
[]
threadId
=
new
long
[
1
];
...
...
@@ -177,6 +193,9 @@ public final class Markdowns {
String
ret
=
doc
.
select
(
"body"
).
html
();
ret
=
StringUtils
.
trim
(
ret
);
// cache it
putHTML
(
markdownText
,
ret
);
return
ret
;
};
...
...
@@ -225,4 +244,33 @@ public final class Markdowns {
return
html
;
}
/**
* Gets HTML for the specified markdown text.
*
* @param markdownText the specified markdown text
* @return HTML
*/
private
static
String
getHTML
(
final
String
markdownText
)
{
final
String
hash
=
DigestUtils
.
md5Hex
(
markdownText
);
final
JSONObject
value
=
MD_CACHE
.
get
(
hash
);
if
(
null
==
value
)
{
return
null
;
}
return
value
.
optString
(
"data"
);
}
/**
* Puts the specified HTML into cache.
*
* @param markdownText the specified markdown text
* @param html the specified HTML
*/
private
static
void
putHTML
(
final
String
markdownText
,
final
String
html
)
{
final
String
hash
=
DigestUtils
.
md5Hex
(
markdownText
);
final
JSONObject
value
=
new
JSONObject
();
value
.
put
(
"data"
,
html
);
MD_CACHE
.
put
(
hash
,
value
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment