mirror of
https://github.com/gitpitch/gitpitch.git
synced 2024-04-18 07:30:55 +08:00
Code delimiter support for highlighting language hint.
This commit is contained in:
parent
894757e33c
commit
742d3a1308
|
@ -67,6 +67,9 @@ public class CodeService {
|
||||||
|
|
||||||
String codePath = extractCodePath(md, gitRawBase, mdm);
|
String codePath = extractCodePath(md, gitRawBase, mdm);
|
||||||
|
|
||||||
|
String langHint = getLangHintOptionFromPath(codePath);
|
||||||
|
codePath = cleanOptionsFromPath(codePath);
|
||||||
|
|
||||||
GRS grs = grsManager.get(pp);
|
GRS grs = grsManager.get(pp);
|
||||||
GRSService grsService = grsManager.getService(grs);
|
GRSService grsService = grsManager.getService(grs);
|
||||||
|
|
||||||
|
@ -75,7 +78,7 @@ public class CodeService {
|
||||||
|
|
||||||
if(downStatus == 0) {
|
if(downStatus == 0) {
|
||||||
String code = diskService.asText(pp, SOURCE_CODE);
|
String code = diskService.asText(pp, SOURCE_CODE);
|
||||||
return buildCodeBlock(mdm.extractCodeDelim(md), code);
|
return buildCodeBlock(mdm.extractCodeDelim(md), code, langHint);
|
||||||
} else {
|
} else {
|
||||||
return buildCodeBlockError(mdm.extractCodeDelim(md),
|
return buildCodeBlockError(mdm.extractCodeDelim(md),
|
||||||
extractPath(md, mdm));
|
extractPath(md, mdm));
|
||||||
|
@ -114,10 +117,11 @@ public class CodeService {
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String buildCodeBlock(String delim, String code) {
|
private String buildCodeBlock(String delim, String code, String langHint) {
|
||||||
return new StringBuffer(delim)
|
return new StringBuffer(delim)
|
||||||
.append(MarkdownModel.MD_SPACER)
|
.append(MarkdownModel.MD_SPACER)
|
||||||
.append(MarkdownModel.MD_CODE_BLOCK_OPEN)
|
.append(MarkdownModel.MD_CODE_BLOCK_OPEN)
|
||||||
|
.append(langHint)
|
||||||
.append(MarkdownModel.MD_SPACER)
|
.append(MarkdownModel.MD_SPACER)
|
||||||
.append(code)
|
.append(code)
|
||||||
.append(MarkdownModel.MD_SPACER)
|
.append(MarkdownModel.MD_SPACER)
|
||||||
|
@ -138,10 +142,38 @@ public class CodeService {
|
||||||
.toString();
|
.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getLangHintOptionFromPath(String codePath) {
|
||||||
|
String extractedHint = NO_LANG_HINT;
|
||||||
|
try {
|
||||||
|
int hintOptIdx = codePath.indexOf(LANG_HINT_OPTION);
|
||||||
|
if(hintOptIdx != -1) {
|
||||||
|
int hintOffset = hintOptIdx + LANG_HINT_OPTION.length();
|
||||||
|
extractedHint = codePath.substring(hintOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch(Exception ex) {}
|
||||||
|
return extractedHint;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String cleanOptionsFromPath(String codePath) {
|
||||||
|
String cleanedPath = codePath;
|
||||||
|
try {
|
||||||
|
int hintOptIdx = codePath.indexOf(LANG_HINT_OPTION);
|
||||||
|
if(hintOptIdx != -1) {
|
||||||
|
cleanedPath = codePath.substring(0, hintOptIdx);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} catch(Exception cex) {}
|
||||||
|
return cleanedPath;
|
||||||
|
}
|
||||||
|
|
||||||
private static final String SOURCE_CODE = "PITCHME.code";
|
private static final String SOURCE_CODE = "PITCHME.code";
|
||||||
private static final String SOURCE_CODE_DELIMITER =
|
private static final String SOURCE_CODE_DELIMITER =
|
||||||
"### Code Block Delimiter";
|
"### Code Block Delimiter";
|
||||||
private static final String SOURCE_CODE_NOT_FOUND =
|
private static final String SOURCE_CODE_NOT_FOUND =
|
||||||
"### Source File Not Found";
|
"### Source File Not Found";
|
||||||
|
private static final String LANG_HINT_OPTION = "&lang=";
|
||||||
|
private static final String NO_LANG_HINT = "";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user