From 894757e33ca2bc4d5a199b5df879f392d0f697c0 Mon Sep 17 00:00:00 2001 From: David Russell Date: Wed, 7 Jun 2017 11:15:53 +0700 Subject: [PATCH] Image delimiter support for custom scaling and sizing. --- app/com/gitpitch/services/ImageService.java | 35 +++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/app/com/gitpitch/services/ImageService.java b/app/com/gitpitch/services/ImageService.java index 43eec07..31b0659 100644 --- a/app/com/gitpitch/services/ImageService.java +++ b/app/com/gitpitch/services/ImageService.java @@ -49,11 +49,14 @@ public class ImageService { public String buildBackground(PitchParams pp, String imageBgUrl, String imageBgSize) { + String bgSize = getSizeOptionFromUrl(imageBgUrl, imageBgSize); + String bgUrl = cleanOptionsFromUrl(imageBgUrl); + return new StringBuffer(MarkdownModel.MD_SPACER) .append(MarkdownModel.MD_IMAGE_OPEN) - .append(imageBgUrl) + .append(bgUrl) .append(MarkdownModel.MD_IMAGE_SIZE) - .append(imageBgSize) + .append(bgSize) .append(MarkdownModel.MD_CLOSER) .append(MarkdownModel.MD_SPACER) .toString(); @@ -151,6 +154,33 @@ public class ImageService { 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_INLINE_OPEN = "![Image](" + IMG_OFFLINE_DIR; private static final String IMG_INLINE_CLOSE = ")"; @@ -158,4 +188,5 @@ public class ImageService { private static final String IMG_TAG_SRC_OPEN = "src=\""; private static final String IMG_TAG_SRC_CLOSE = "\""; private static final String IMG_TAG_LINK_UNKNOWN = "#"; + private static final String IMG_CUSTOM_SIZE_OPTION = "&size="; }