-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
401 additions
and
379 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/java/com/github/houbb/markdown/toc/support/IncreaseMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.github.houbb.markdown.toc.support; | ||
|
||
import com.github.houbb.markdown.toc.constant.TocConstant; | ||
import com.github.houbb.markdown.toc.util.SpecialCharUtil; | ||
import com.github.houbb.markdown.toc.util.StringUtil; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
public class IncreaseMap { | ||
|
||
private Map<String, AtomicInteger> map = new ConcurrentHashMap<>(); | ||
|
||
|
||
/** | ||
* 构建确切的名称 | ||
* @param originalName 原始名称 | ||
* @return 最后的构建结果 | ||
*/ | ||
public String buildActualName(final String originalName) { | ||
String actualName; | ||
String tocHref = getTocHref(originalName); | ||
AtomicInteger value = map.get(tocHref); | ||
if(value != null) { | ||
int count = value.getAndIncrement(); | ||
actualName = TocConstant.ASTERISK+tocHref+TocConstant.MINUS+count; | ||
} else { | ||
AtomicInteger one = new AtomicInteger(0); | ||
map.put(tocHref, one); | ||
actualName = TocConstant.ASTERISK+tocHref; | ||
} | ||
return actualName; | ||
} | ||
|
||
/** | ||
* 对于首字母如果是 | ||
* @param tocTitle toc 标题 | ||
* @return 对应的连接名称 | ||
*/ | ||
private static String getTocHref(final String tocTitle) { | ||
if(StringUtil.isEmpty(tocTitle)) { | ||
return tocTitle; | ||
} | ||
|
||
//1. GITHUB 对于大写的处理 | ||
String result = tocTitle.toLowerCase(); | ||
|
||
//2. GITHUB 对于空格的处理 | ||
result = result.replace(' ', '-'); | ||
|
||
//3. 对于特殊字符的处理 | ||
for(String specialChar : SpecialCharUtil.getSpecialCharSet()) { | ||
result = result.replace(specialChar, ""); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters