mirror of
https://github.com/gitpitch/gitpitch.git
synced 2024-04-18 07:30:55 +08:00
Added delimiter parameter processor.
This commit is contained in:
parent
134dcb7f15
commit
9615356d40
|
@ -30,6 +30,7 @@ import com.gitpitch.services.VideoService;
|
||||||
import com.gitpitch.services.GISTService;
|
import com.gitpitch.services.GISTService;
|
||||||
import com.gitpitch.services.CodeService;
|
import com.gitpitch.services.CodeService;
|
||||||
import com.gitpitch.services.ShortcutsService;
|
import com.gitpitch.services.ShortcutsService;
|
||||||
|
import com.gitpitch.git.GRSManager;
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
import com.google.inject.assistedinject.Assisted;
|
import com.google.inject.assistedinject.Assisted;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
@ -56,6 +57,7 @@ public class MarkdownModel implements Markdown {
|
||||||
private final GISTService gistService;
|
private final GISTService gistService;
|
||||||
private final CodeService codeService;
|
private final CodeService codeService;
|
||||||
private final ShortcutsService shortcutsService;
|
private final ShortcutsService shortcutsService;
|
||||||
|
private final GRSManager grsManager;
|
||||||
private final MarkdownRenderer mrndr;
|
private final MarkdownRenderer mrndr;
|
||||||
private final String markdown;
|
private final String markdown;
|
||||||
private String hSlideDelim = HSLIDE_DELIM_DEFAULT;
|
private String hSlideDelim = HSLIDE_DELIM_DEFAULT;
|
||||||
|
@ -67,6 +69,7 @@ public class MarkdownModel implements Markdown {
|
||||||
GISTService gistService,
|
GISTService gistService,
|
||||||
CodeService codeService,
|
CodeService codeService,
|
||||||
ShortcutsService shortcutsService,
|
ShortcutsService shortcutsService,
|
||||||
|
GRSManager grsManager,
|
||||||
@Nullable @Assisted MarkdownRenderer mrndr) {
|
@Nullable @Assisted MarkdownRenderer mrndr) {
|
||||||
|
|
||||||
this.imageService = imageService;
|
this.imageService = imageService;
|
||||||
|
@ -74,6 +77,7 @@ public class MarkdownModel implements Markdown {
|
||||||
this.gistService = gistService;
|
this.gistService = gistService;
|
||||||
this.codeService = codeService;
|
this.codeService = codeService;
|
||||||
this.shortcutsService = shortcutsService;
|
this.shortcutsService = shortcutsService;
|
||||||
|
this.grsManager = grsManager;
|
||||||
this.mrndr = mrndr;
|
this.mrndr = mrndr;
|
||||||
|
|
||||||
String consumed = null;
|
String consumed = null;
|
||||||
|
@ -144,8 +148,9 @@ public class MarkdownModel implements Markdown {
|
||||||
* characters on all non-delimiter fragments.
|
* characters on all non-delimiter fragments.
|
||||||
*/
|
*/
|
||||||
md = md.trim();
|
md = md.trim();
|
||||||
|
DelimParams dp = DelimParams.build(md);
|
||||||
|
|
||||||
if (videoDelimFound(md)) {
|
if (videoDelimFound(dp)) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Inject slide specific video background:
|
* Inject slide specific video background:
|
||||||
|
@ -153,13 +158,12 @@ public class MarkdownModel implements Markdown {
|
||||||
* <!-- .slide: data-background-video="vidUrl" -->
|
* <!-- .slide: data-background-video="vidUrl" -->
|
||||||
*/
|
*/
|
||||||
|
|
||||||
String videoBgUrl =
|
|
||||||
videoService.extractBgUrl(md, gitRawBase, this);
|
|
||||||
return new StringBuffer(delimiter(md))
|
return new StringBuffer(delimiter(md))
|
||||||
.append(videoService.buildBackground(videoBgUrl))
|
.append(videoService.buildBackground(md,
|
||||||
|
dp, pp, this))
|
||||||
.toString();
|
.toString();
|
||||||
|
|
||||||
} else if (imageDelimFound(md)) {
|
} else if (imageDelimFound(dp)) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Inject slide specific image background:
|
* Inject slide specific image background:
|
||||||
|
@ -167,21 +171,18 @@ public class MarkdownModel implements Markdown {
|
||||||
* <!-- .slide: data-background-image="imgUrl" -->
|
* <!-- .slide: data-background-image="imgUrl" -->
|
||||||
*/
|
*/
|
||||||
|
|
||||||
String imageBgUrl =
|
String defaultBgSize = (yOpts != null) ?
|
||||||
imageService.extractBgUrl(md, gitRawBase, this);
|
|
||||||
|
|
||||||
String bgSize = (yOpts != null) ?
|
|
||||||
yOpts.fetchImageBgSize(pp) : YAMLOptions.DEFAULT_BG_SIZE;
|
yOpts.fetchImageBgSize(pp) : YAMLOptions.DEFAULT_BG_SIZE;
|
||||||
|
|
||||||
return new StringBuffer(delimiter(md))
|
return new StringBuffer(delimiter(md))
|
||||||
.append(imageService.buildBackground(pp,
|
.append(imageService.buildBackground(md,
|
||||||
imageBgUrl, bgSize))
|
dp, pp, defaultBgSize, this))
|
||||||
.toString();
|
.toString();
|
||||||
|
|
||||||
} else if (gistDelimFound(md)) {
|
} else if (gistDelimFound(dp)) {
|
||||||
return gistService.build(md, pp, yOpts, this);
|
return gistService.build(md, dp, pp, yOpts, this);
|
||||||
} else if(codeDelimFound(md)) {
|
} else if(codeDelimFound(dp)) {
|
||||||
return codeService.build(md, pp, yOpts, gitRawBase, this);
|
return codeService.build(md, dp, pp, yOpts, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (yOpts != null && yOpts.hasImageBg()) {
|
if (yOpts != null && yOpts.hasImageBg()) {
|
||||||
|
@ -394,20 +395,20 @@ public class MarkdownModel implements Markdown {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean imageDelimFound(String md) {
|
private boolean imageDelimFound(DelimParams dp) {
|
||||||
return md.startsWith(horizImageDelim()) || md.startsWith(vertImageDelim());
|
return dp.get(DELIM_QUERY_IMAGE) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean videoDelimFound(String md) {
|
private boolean videoDelimFound(DelimParams dp) {
|
||||||
return md.startsWith(horizVideoDelim()) || md.startsWith(vertVideoDelim());
|
return dp.get(DELIM_QUERY_VIDEO) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean gistDelimFound(String md) {
|
private boolean gistDelimFound(DelimParams dp) {
|
||||||
return md.startsWith(horizGISTDelim()) || md.startsWith(vertGISTDelim());
|
return dp.get(DELIM_QUERY_GIST) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean codeDelimFound(String md) {
|
private boolean codeDelimFound(DelimParams dp) {
|
||||||
return md.startsWith(horizCodeDelim()) || md.startsWith(vertCodeDelim());
|
return dp.get(DELIM_QUERY_CODE) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String delimiter(String md) {
|
private String delimiter(String md) {
|
||||||
|
@ -575,6 +576,22 @@ public class MarkdownModel implements Markdown {
|
||||||
return link.startsWith(MD_LINK_ABS);
|
return link.startsWith(MD_LINK_ABS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String linkLive(PitchParams pp, String linkBase) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
if (linkAbsolute(linkBase)) {
|
||||||
|
return linkBase;
|
||||||
|
} else {
|
||||||
|
return grsManager.getService(grsManager.get(pp))
|
||||||
|
.raw(pp, linkBase);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception lex) {
|
||||||
|
log.warn("linkLive: ex={}", lex);
|
||||||
|
return "#";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String extractImageDelim(String md) {
|
public String extractImageDelim(String md) {
|
||||||
return isHorizontal(md) ? horizImageDelim() : vertImageDelim();
|
return isHorizontal(md) ? horizImageDelim() : vertImageDelim();
|
||||||
}
|
}
|
||||||
|
@ -684,6 +701,13 @@ public class MarkdownModel implements Markdown {
|
||||||
public static final String HSLIDE_DELIM_BACK_COMPAT = "#HSLIDE";
|
public static final String HSLIDE_DELIM_BACK_COMPAT = "#HSLIDE";
|
||||||
public static final String VSLIDE_DELIM_BACK_COMPAT = "#VSLIDE";
|
public static final String VSLIDE_DELIM_BACK_COMPAT = "#VSLIDE";
|
||||||
|
|
||||||
|
public static final String DELIM_QUERY_IMAGE = "image";
|
||||||
|
public static final String DELIM_QUERY_VIDEO = "video";
|
||||||
|
public static final String DELIM_QUERY_GIST = "gist";
|
||||||
|
public static final String DELIM_QUERY_CODE = "code";
|
||||||
|
public static final String DELIM_QUERY_LANG = "lang";
|
||||||
|
public static final String DELIM_QUERY_SIZE = "size";
|
||||||
|
|
||||||
public static final String MD_LINK_OPEN = "![";
|
public static final String MD_LINK_OPEN = "![";
|
||||||
public static final String MD_ANCHOR_OPEN = "[";
|
public static final String MD_ANCHOR_OPEN = "[";
|
||||||
public static final String MD_IMAGE_OPEN =
|
public static final String MD_IMAGE_OPEN =
|
||||||
|
|
|
@ -29,6 +29,7 @@ import com.gitpitch.git.GRSService;
|
||||||
import com.gitpitch.git.GRSManager;
|
import com.gitpitch.git.GRSManager;
|
||||||
import com.gitpitch.services.DiskService;
|
import com.gitpitch.services.DiskService;
|
||||||
import com.gitpitch.utils.PitchParams;
|
import com.gitpitch.utils.PitchParams;
|
||||||
|
import com.gitpitch.utils.DelimParams;
|
||||||
import com.gitpitch.utils.YAMLOptions;
|
import com.gitpitch.utils.YAMLOptions;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.nio.file.*;
|
import java.nio.file.*;
|
||||||
|
@ -56,19 +57,17 @@ public class CodeService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String build(String md,
|
public String build(String md,
|
||||||
|
DelimParams dp,
|
||||||
PitchParams pp,
|
PitchParams pp,
|
||||||
YAMLOptions yOpts,
|
YAMLOptions yOpts,
|
||||||
String gitRawBase,
|
|
||||||
MarkdownModel mdm) {
|
MarkdownModel mdm) {
|
||||||
|
|
||||||
String codeBlock = mdm.extractCodeDelim(md);
|
String codeBlock = mdm.extractCodeDelim(md);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String codePath = extractCodePath(md, gitRawBase, mdm);
|
String codePath = dp.get(MarkdownModel.DELIM_QUERY_CODE);
|
||||||
|
String langHint = dp.get(MarkdownModel.DELIM_QUERY_LANG);
|
||||||
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);
|
||||||
|
@ -88,23 +87,6 @@ public class CodeService {
|
||||||
return codeBlock;
|
return codeBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String extractCodePath(String md,
|
|
||||||
String gitRawBase,
|
|
||||||
MarkdownModel mdm) {
|
|
||||||
|
|
||||||
String codePath = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
String delim = mdm.extractCodeDelim(md);
|
|
||||||
codePath = md.substring(delim.length());
|
|
||||||
|
|
||||||
} catch (Exception pex) {
|
|
||||||
log.warn("extractCodePath: ex={}", pex);
|
|
||||||
}
|
|
||||||
return codePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String extractPath(String md, MarkdownModel mdm) {
|
private String extractPath(String md, MarkdownModel mdm) {
|
||||||
String path = null;
|
String path = null;
|
||||||
|
|
||||||
|
@ -142,32 +124,6 @@ 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";
|
||||||
|
|
|
@ -26,6 +26,7 @@ package com.gitpitch.services;
|
||||||
import com.gitpitch.models.MarkdownModel;
|
import com.gitpitch.models.MarkdownModel;
|
||||||
import com.gitpitch.services.ImageService;
|
import com.gitpitch.services.ImageService;
|
||||||
import com.gitpitch.utils.PitchParams;
|
import com.gitpitch.utils.PitchParams;
|
||||||
|
import com.gitpitch.utils.DelimParams;
|
||||||
import com.gitpitch.utils.YAMLOptions;
|
import com.gitpitch.utils.YAMLOptions;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import javax.inject.*;
|
import javax.inject.*;
|
||||||
|
@ -65,14 +66,14 @@ public class GISTService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String build(String md,
|
public String build(String md,
|
||||||
|
DelimParams dp,
|
||||||
PitchParams pp,
|
PitchParams pp,
|
||||||
YAMLOptions yOpts,
|
YAMLOptions yOpts,
|
||||||
MarkdownModel mdm) {
|
MarkdownModel mdm) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String gid =
|
String gid = dp.get(MarkdownModel.DELIM_QUERY_GIST);
|
||||||
md.substring(mdm.horizGISTDelim().length());
|
|
||||||
|
|
||||||
String gistCallback =
|
String gistCallback =
|
||||||
com.gitpitch.controllers.routes.PitchController.gist(gid)
|
com.gitpitch.controllers.routes.PitchController.gist(gid)
|
||||||
|
|
|
@ -25,6 +25,7 @@ package com.gitpitch.services;
|
||||||
|
|
||||||
import com.gitpitch.models.MarkdownModel;
|
import com.gitpitch.models.MarkdownModel;
|
||||||
import com.gitpitch.utils.PitchParams;
|
import com.gitpitch.utils.PitchParams;
|
||||||
|
import com.gitpitch.utils.DelimParams;
|
||||||
import com.gitpitch.utils.YAMLOptions;
|
import com.gitpitch.utils.YAMLOptions;
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -41,16 +42,24 @@ public class ImageService {
|
||||||
private final Logger.ALogger log = Logger.of(this.getClass());
|
private final Logger.ALogger log = Logger.of(this.getClass());
|
||||||
|
|
||||||
public String buildBackground(PitchParams pp,
|
public String buildBackground(PitchParams pp,
|
||||||
YAMLOptions yOpts) {
|
YAMLOptions yOpts) {
|
||||||
|
|
||||||
return buildBackground(pp, yOpts.fetchImageBg(pp), yOpts.fetchImageBgSize(pp));
|
return buildBackground(yOpts.fetchImageBg(pp), yOpts.fetchImageBgSize(pp));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String buildBackground(PitchParams pp,
|
public String buildBackground(String md,
|
||||||
String imageBgUrl, String imageBgSize) {
|
DelimParams dp,
|
||||||
|
PitchParams pp,
|
||||||
|
String defaultSize,
|
||||||
|
MarkdownModel mdm) {
|
||||||
|
|
||||||
String bgSize = getSizeOptionFromUrl(imageBgUrl, imageBgSize);
|
String bgUrl = dp.get(MarkdownModel.DELIM_QUERY_IMAGE);
|
||||||
String bgUrl = cleanOptionsFromUrl(imageBgUrl);
|
bgUrl = mdm.linkLive(pp, bgUrl);
|
||||||
|
String bgSize = dp.get(MarkdownModel.DELIM_QUERY_SIZE, defaultSize);
|
||||||
|
return buildBackground(bgUrl, bgSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildBackground(String bgUrl, String bgSize) {
|
||||||
|
|
||||||
return new StringBuffer(MarkdownModel.MD_SPACER)
|
return new StringBuffer(MarkdownModel.MD_SPACER)
|
||||||
.append(MarkdownModel.MD_IMAGE_OPEN)
|
.append(MarkdownModel.MD_IMAGE_OPEN)
|
||||||
|
@ -107,31 +116,6 @@ public class ImageService {
|
||||||
return md.contains(MarkdownModel.DATA_IMAGE_ATTR);
|
return md.contains(MarkdownModel.DATA_IMAGE_ATTR);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String extractBgUrl(String md,
|
|
||||||
String gitRawBase,
|
|
||||||
MarkdownModel mdm) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
String delim = mdm.extractImageDelim(md);
|
|
||||||
String imageBgUrl = md.substring(delim.length());
|
|
||||||
|
|
||||||
if (mdm.linkAbsolute(imageBgUrl)) {
|
|
||||||
return imageBgUrl;
|
|
||||||
} else {
|
|
||||||
return new StringBuffer(gitRawBase).append(imageBgUrl)
|
|
||||||
.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception pex) {
|
|
||||||
log.warn("extractImageBgUrl: ex={}", pex);
|
|
||||||
/*
|
|
||||||
* Invalid bg syntax, return clean slide delimiter.
|
|
||||||
*/
|
|
||||||
return mdm.isHorizontal(md) ? mdm.horizDelim() : mdm.vertDelim();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return true is HTML image tag found.
|
* Return true is HTML image tag found.
|
||||||
*/
|
*/
|
||||||
|
@ -154,33 +138,6 @@ public class ImageService {
|
||||||
return tagLink;
|
return tagLink;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getSizeOptionFromUrl(String url, String defaultSize) {
|
|
||||||
String extractedSize = defaultSize;
|
|
||||||
try {
|
|
||||||
int sizeOptIdx = url.indexOf(IMG_CUSTOM_SIZE_OPTION);
|
|
||||||
if(sizeOptIdx != -1) {
|
|
||||||
int sizeOffset = sizeOptIdx + IMG_CUSTOM_SIZE_OPTION.length();
|
|
||||||
extractedSize = url.substring(sizeOffset);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch(Exception ex) {}
|
|
||||||
return extractedSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String cleanOptionsFromUrl(String url) {
|
|
||||||
|
|
||||||
String cleanedUrl = url;
|
|
||||||
try {
|
|
||||||
int sizeOptIdx = url.indexOf(IMG_CUSTOM_SIZE_OPTION);
|
|
||||||
if(sizeOptIdx != -1) {
|
|
||||||
cleanedUrl = url.substring(0, sizeOptIdx);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} catch(Exception cex) {}
|
|
||||||
return cleanedUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final String IMG_OFFLINE_DIR = "./assets/md/assets/";
|
private static final String IMG_OFFLINE_DIR = "./assets/md/assets/";
|
||||||
private static final String IMG_INLINE_OPEN = "![Image](" + IMG_OFFLINE_DIR;
|
private static final String IMG_INLINE_OPEN = "![Image](" + IMG_OFFLINE_DIR;
|
||||||
private static final String IMG_INLINE_CLOSE = ")";
|
private static final String IMG_INLINE_CLOSE = ")";
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
package com.gitpitch.services;
|
package com.gitpitch.services;
|
||||||
|
|
||||||
import com.gitpitch.models.MarkdownModel;
|
import com.gitpitch.models.MarkdownModel;
|
||||||
|
import com.gitpitch.utils.PitchParams;
|
||||||
|
import com.gitpitch.utils.DelimParams;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import javax.inject.*;
|
import javax.inject.*;
|
||||||
import play.Logger;
|
import play.Logger;
|
||||||
|
@ -118,32 +120,13 @@ public class VideoService {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String extractBgUrl(String md,
|
public String buildBackground(String md,
|
||||||
String gitRawBase,
|
DelimParams dp,
|
||||||
MarkdownModel mdm) {
|
PitchParams pp,
|
||||||
|
MarkdownModel mdm) {
|
||||||
|
|
||||||
try {
|
String bgUrl = dp.get(MarkdownModel.DELIM_QUERY_VIDEO, "#");
|
||||||
|
bgUrl = mdm.linkLive(pp, bgUrl);
|
||||||
String delim = mdm.extractVideoDelim(md);
|
|
||||||
String videoBgUrl = md.substring(delim.length());
|
|
||||||
|
|
||||||
if (mdm.linkAbsolute(videoBgUrl)) {
|
|
||||||
return videoBgUrl;
|
|
||||||
} else {
|
|
||||||
return new StringBuffer(gitRawBase).append(videoBgUrl)
|
|
||||||
.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception pex) {
|
|
||||||
log.warn("processVideoBg: ex={}", pex);
|
|
||||||
/*
|
|
||||||
* Invalid bg syntax, return clean slide delimiter.
|
|
||||||
*/
|
|
||||||
return mdm.isHorizontal(md) ? mdm.horizDelim() : mdm.vertDelim();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String buildBackground(String bgUrl) {
|
|
||||||
|
|
||||||
return new StringBuffer(MarkdownModel.MD_SPACER)
|
return new StringBuffer(MarkdownModel.MD_SPACER)
|
||||||
.append(MarkdownModel.MD_SPACER)
|
.append(MarkdownModel.MD_SPACER)
|
||||||
|
|
72
app/com/gitpitch/utils/DelimParams.java
Normal file
72
app/com/gitpitch/utils/DelimParams.java
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
/*
|
||||||
|
* MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2017 David Russell
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.gitpitch.utils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Optional;
|
||||||
|
import org.apache.http.NameValuePair;
|
||||||
|
import org.apache.http.client.utils.URLEncodedUtils;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Markdown Delimiter Parameter Parser.
|
||||||
|
*/
|
||||||
|
public class DelimParams {
|
||||||
|
|
||||||
|
private String delimiter;
|
||||||
|
private List<NameValuePair> params = Collections.emptyList();
|
||||||
|
|
||||||
|
private DelimParams(String delimiter) {
|
||||||
|
|
||||||
|
this.delimiter = delimiter;
|
||||||
|
if(delimiter != null && delimiter.contains(QUERY_ON_DELIM)) {
|
||||||
|
int queryIndex = delimiter.indexOf(QUERY_ON_DELIM) + 1;
|
||||||
|
String delimQuery = delimiter.substring(queryIndex);
|
||||||
|
this.params =
|
||||||
|
URLEncodedUtils.parse(delimQuery, StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DelimParams build(String delimiter) {
|
||||||
|
return new DelimParams(delimiter);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String get(String param) {
|
||||||
|
return get(param, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String get(String param, String defaultValue) {
|
||||||
|
|
||||||
|
Optional<NameValuePair> match =
|
||||||
|
params.stream()
|
||||||
|
.filter(nvp -> nvp.getName().equals(param))
|
||||||
|
.findFirst();
|
||||||
|
|
||||||
|
return match.isPresent() ? match.get().getValue() : defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final String QUERY_ON_DELIM = "?";
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user