/* Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class MDFileContent {

  public String pathFromRootDir;
  public String fileName;
  public String imgPathFromRootDir;

//  public MDFileHeader header;

  public String title;
  public String body;

  public void computePathFromRootDir(String rootPath, String filePath) {
    String pathDiff = computePathDiff(rootPath, filePath);
    if(pathDiff.endsWith("index.md")){
      pathDiff = pathDiff.replaceAll("index.md", "");
    }else{
      pathDiff = pathDiff.replaceAll(".md", "/");
    }
    this.pathFromRootDir = pathDiff;
  }

  private String computePathDiff(String rootPath, String filePath) {
    String pathDiff = "";
    if (rootPath.length() > filePath.length()) {
      pathDiff =  rootPath.substring(filePath.length() - 1);
    } else if (filePath.length() > rootPath.length()) {
      pathDiff = filePath.substring(rootPath.length() - 1);
    }
    return pathDiff;
  }

  public void computeImgPathFromRootDir(String imgPath) {
    String imgPathFromRootDir = "";
    if(imgPath.startsWith("../")){
      int idxFromLastPath = pathFromRootDir.lastIndexOf("/");
      String relativeStart = pathFromRootDir.substring(0, idxFromLastPath);
      String imgPathReturnSkipped = imgPath.substring(2);
      imgPathFromRootDir = relativeStart + imgPathReturnSkipped;
    }
    this.imgPathFromRootDir = imgPathFromRootDir;
  }
}

@@ -1093,16 +1093,113 @@
 f;%0A  %7D%0A%0A
+//  public String ensureValidRootPath(String rootPath) %7B%0A//    if(rootPath.endsWith(%22/%22))%0A//  %7D%0A%0A
   privat
@@ -1682,45 +1682,160 @@
     
-int idxFromLastPath = pathFromRootDir
+String relativePathWithoutLastSlash = pathFromRootDir.substring(0, pathFromRootDir.length()-1);%0A      int idxFromLastPath = relativePathWithoutLastSlash
 .las

correct relative path