mirror of
https://github.com/gitpitch/gitpitch.git
synced 2024-04-18 07:30:55 +08:00
Added support for FontAwesome shortcuts.
This commit is contained in:
parent
75f3929f84
commit
632ba2dd1b
|
@ -109,6 +109,8 @@ public class MarkdownModel implements Markdown {
|
||||||
|
|
||||||
consumed = stream.map(md -> {
|
consumed = stream.map(md -> {
|
||||||
return process(md, pp, yOpts, gitRawBase);
|
return process(md, pp, yOpts, gitRawBase);
|
||||||
|
}).map(md -> {
|
||||||
|
return shortcutsService.process(md, pp, yOpts);
|
||||||
}).collect(Collectors.joining("\n"));
|
}).collect(Collectors.joining("\n"));
|
||||||
|
|
||||||
consumed = postProcess(consumed, pp, yOpts, gitRawBase);
|
consumed = postProcess(consumed, pp, yOpts, gitRawBase);
|
||||||
|
@ -658,6 +660,10 @@ public class MarkdownModel implements Markdown {
|
||||||
public static final String MD_CODE_BLOCK_CLOSE = "```";
|
public static final String MD_CODE_BLOCK_CLOSE = "```";
|
||||||
public static final String MD_TITLE_HINT_OPEN = "@title[";
|
public static final String MD_TITLE_HINT_OPEN = "@title[";
|
||||||
public static final String MD_TITLE_HINT_CLOSE = "]";
|
public static final String MD_TITLE_HINT_CLOSE = "]";
|
||||||
|
public static final String MD_FA_OPEN = "@fa[";
|
||||||
|
public static final String MD_FA_CLOSE = "]";
|
||||||
|
public static final String MD_FA_NOTE_OPEN = "(";
|
||||||
|
public static final String MD_FA_NOTE_CLOSE = ")";
|
||||||
|
|
||||||
private static final String MD_HSLIDE_IMAGE = "?image=";
|
private static final String MD_HSLIDE_IMAGE = "?image=";
|
||||||
private static final String MD_VSLIDE_IMAGE = "?image=";
|
private static final String MD_VSLIDE_IMAGE = "?image=";
|
||||||
|
|
|
@ -40,6 +40,22 @@ public class ShortcutsService {
|
||||||
|
|
||||||
private final Logger.ALogger log = Logger.of(this.getClass());
|
private final Logger.ALogger log = Logger.of(this.getClass());
|
||||||
|
|
||||||
|
public String process(String md, PitchParams pp, YAMLOptions yOpts) {
|
||||||
|
|
||||||
|
String processed = md;
|
||||||
|
|
||||||
|
try {
|
||||||
|
int faCycles = 5; // Prevent infinite loop.
|
||||||
|
while(fontAwesomeFound(processed) && faCycles > 0) {
|
||||||
|
String expanded = expandFontAwesome(processed);
|
||||||
|
faCycles = processed.equals(expanded) ? 0 : (faCycles-1);
|
||||||
|
processed = expanded;
|
||||||
|
}
|
||||||
|
} catch(Exception ex) {}
|
||||||
|
|
||||||
|
return processed;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean listFragmentFound(String md) {
|
public boolean listFragmentFound(String md) {
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
if(md != null) {
|
if(md != null) {
|
||||||
|
@ -72,6 +88,16 @@ public class ShortcutsService {
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean fontAwesomeFound(String md) {
|
||||||
|
boolean found = false;
|
||||||
|
if(md != null) {
|
||||||
|
if(md.contains(MarkdownModel.MD_FA_OPEN)) {
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Expand shortcut syntax for list fragment with fully expanded
|
* Expand shortcut syntax for list fragment with fully expanded
|
||||||
* HTML comment syntax.
|
* HTML comment syntax.
|
||||||
|
@ -149,6 +175,53 @@ public class ShortcutsService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Expand shortcut syntax for font-awesome with fully expanded
|
||||||
|
* HTML span syntax with optional text.
|
||||||
|
*/
|
||||||
|
public String expandFontAwesome(String md) {
|
||||||
|
|
||||||
|
String mdLeft = "";
|
||||||
|
String faName = "";
|
||||||
|
String faNote = "";
|
||||||
|
String mdRight = "";
|
||||||
|
String expandedFA = "";
|
||||||
|
|
||||||
|
try {
|
||||||
|
int faOpen = md.indexOf(MarkdownModel.MD_FA_OPEN);
|
||||||
|
int faClose = md.indexOf(MarkdownModel.MD_FA_CLOSE);
|
||||||
|
|
||||||
|
if(faClose > faOpen) { /* faName exists */
|
||||||
|
|
||||||
|
mdLeft = md.substring(0, faOpen);
|
||||||
|
faName =
|
||||||
|
md.substring(faOpen + MarkdownModel.MD_FA_OPEN.length(),
|
||||||
|
faClose);
|
||||||
|
|
||||||
|
String rmd = md.substring(faClose + 1);
|
||||||
|
|
||||||
|
int faNoteOpen = rmd.indexOf(MarkdownModel.MD_FA_NOTE_OPEN);
|
||||||
|
int faNoteClose = rmd.indexOf(MarkdownModel.MD_FA_NOTE_CLOSE);
|
||||||
|
|
||||||
|
if(faNoteOpen == 0) { /* faNote immediately follows faName */
|
||||||
|
|
||||||
|
faNote =
|
||||||
|
rmd.substring(MarkdownModel.MD_FA_NOTE_OPEN.length(),
|
||||||
|
faNoteClose);
|
||||||
|
mdRight = rmd.substring(faNoteClose + 1);
|
||||||
|
} else {
|
||||||
|
mdRight = rmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
expandedFA = buildFontAwesome(faName, faNote);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch(Exception ex) {
|
||||||
|
} finally {
|
||||||
|
return mdLeft + expandedFA + mdRight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Construct a HTML fragment for a code fragment based on the
|
* Construct a HTML fragment for a code fragment based on the
|
||||||
* reveal-code-focus plugin syntax:
|
* reveal-code-focus plugin syntax:
|
||||||
|
@ -164,6 +237,19 @@ public class ShortcutsService {
|
||||||
.toString();
|
.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Construct a HTML fragment for an FA icon.
|
||||||
|
*/
|
||||||
|
private String buildFontAwesome(String font, String text) {
|
||||||
|
if(text == null) text = "";
|
||||||
|
return new StringBuffer(HTML_FONT_FRAG_OPEN)
|
||||||
|
.append(font)
|
||||||
|
.append(HTML_FONT_FRAG_CLOSE)
|
||||||
|
.append(text)
|
||||||
|
.append(HTML_FONT_FRAG_TEXT_CLOSE)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Note, the space before opening bracket is intentional
|
* Note, the space before opening bracket is intentional
|
||||||
* so tag injection can happen directly alongside other
|
* so tag injection can happen directly alongside other
|
||||||
|
@ -178,4 +264,8 @@ public class ShortcutsService {
|
||||||
private static final String TITLE_HINT_SPAN_OPEN =
|
private static final String TITLE_HINT_SPAN_OPEN =
|
||||||
"<span class=\"menu-title\" style=\"display: none\">";
|
"<span class=\"menu-title\" style=\"display: none\">";
|
||||||
private static final String TITLE_HINT_SPAN_CLOSE = "</span>";
|
private static final String TITLE_HINT_SPAN_CLOSE = "</span>";
|
||||||
|
private static final String HTML_FONT_FRAG_OPEN = "<i class=\"fa fa-";
|
||||||
|
private static final String HTML_FONT_FRAG_CLOSE = "\" aria-hidden=\"true\"> ";
|
||||||
|
private static final String HTML_FONT_FRAG_TEXT_CLOSE = "</i>";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user