| | |
| | | package com.gitblit.utils;
|
| | |
|
| | | import static org.pegdown.Extensions.ALL;
|
| | | import static org.pegdown.Extensions.ANCHORLINKS;
|
| | | import static org.pegdown.Extensions.SMARTYPANTS;
|
| | |
|
| | | import java.io.IOException;
|
| | |
| | | */
|
| | | public static String transformMarkdown(String markdown, LinkRenderer linkRenderer) {
|
| | | try {
|
| | | PegDownProcessor pd = new PegDownProcessor(ALL & ~SMARTYPANTS);
|
| | | PegDownProcessor pd = new PegDownProcessor(ALL & ~SMARTYPANTS & ~ANCHORLINKS);
|
| | | RootNode astRoot = pd.parseMarkdown(markdown.toCharArray());
|
| | | return new WorkaroundHtmlSerializer(linkRenderer == null ? new LinkRenderer() : linkRenderer).toHtml(astRoot);
|
| | | } catch (ParsingTimeoutException e) {
|
| | |
| | | String canonicalUrl = settings.getString(Keys.web.canonicalUrl, "https://localhost:8443");
|
| | |
|
| | | // emphasize and link mentions
|
| | | String mentionReplacement = String.format(" **<a href=\"%1s/user/$1\">@$1</a>**", canonicalUrl);
|
| | | String mentionReplacement = String.format(" **[@$1](%1s/user/$1)**", canonicalUrl);
|
| | | text = text.replaceAll("\\s@([A-Za-z0-9-_]+)", mentionReplacement);
|
| | |
|
| | | // link ticket refs |
| | |
| | | // link commit shas
|
| | | int shaLen = settings.getInteger(Keys.web.shortCommitIdLength, 6);
|
| | | String commitPattern = MessageFormat.format("\\s([A-Fa-f0-9]'{'{0}'}')([A-Fa-f0-9]'{'{1}'}')", shaLen, 40 - shaLen);
|
| | | String commitReplacement = String.format(" <a class='commit' href='%1$s/commit?r=%2$s&h=$1$2'>$1</a>", canonicalUrl, repositoryName);
|
| | | String commitReplacement = String.format(" [`$1`](%1$s/commit?r=%2$s&h=$1$2)", canonicalUrl, repositoryName);
|
| | | text = text.replaceAll(commitPattern, commitReplacement);
|
| | |
|
| | | String html = transformMarkdown(text);
|