Skip to content

TagSpaces is an offline, open source, document manager with tagging support

fixing handling of relative paths

uggrockc7b21e1d7977
diff --git a/data/ext/editorHTML/editor.js b/data/ext/editorHTML/editor.js
index 55a42af15..b87c9034b 100644
--- a/data/ext/editorHTML/editor.js
+++ b/data/ext/editorHTML/editor.js
@@ -55,8 +55,12 @@ function getContentVersion() {
return contentVersion;
}
-function setContent(content) {
+function setContent(content, currentFilePath) {
resetContentVersion();
+
+ // adjusting releative paths
+ $("base").attr("href", currentFilePath);
+
$htmlEditor = $('#htmlEditor');
$htmlEditor.append(content);
// Check if summernote is loaded
diff --git a/data/ext/editorHTML/extension.js b/data/ext/editorHTML/extension.js
index b1c1a2289..048f5b279 100644
--- a/data/ext/editorHTML/extension.js
+++ b/data/ext/editorHTML/extension.js
@@ -22,6 +22,8 @@ define(function(require, exports, module) {
var extensionDirectory = extensionsPath + "/" + extensionID;
+ var fileDirectory;
+
var currentContent,
currentFilePath,
$containerElement;
@@ -29,6 +31,8 @@ define(function(require, exports, module) {
exports.init = function(filePath, containerElementID) {
console.log("Initalization HTML Editor...");
+ fileDirectory = TSCORE.TagUtils.extractContainingDirectoryPath(filePath);
+
$containerElement = $('#' + containerElementID);
currentFilePath = filePath;
@@ -89,11 +93,11 @@ define(function(require, exports, module) {
var contentWindow = document.getElementById("iframeViewer").contentWindow;
if (typeof contentWindow.setContent === "function") {
- contentWindow.setContent(cleanedBodyContent);
+ contentWindow.setContent(cleanedBodyContent, currentFilePath);
} else {
// TODO optimize setTimeout
window.setTimeout(function() {
- contentWindow.setContent(cleanedBodyContent);
+ contentWindow.setContent(cleanedBodyContent, currentFilePath);
}, 500);
}
};
diff --git a/data/ext/editorHTML/index.html b/data/ext/editorHTML/index.html
index 4022d31c7..8764fa468 100644
--- a/data/ext/editorHTML/index.html
+++ b/data/ext/editorHTML/index.html
@@ -10,6 +10,7 @@
<link rel="stylesheet" href="../../assets/tagspaces.css" />
<link rel="stylesheet" href="summernote/summernote.css" />
<link rel="stylesheet" href="extension.css" />
+ <base>
</head>
<body>
<div id="htmlEditor"></div>
diff --git a/data/ext/viewerBrowser/extension.js b/data/ext/viewerBrowser/extension.js
index 569ea6d5b..d592450a4 100644
--- a/data/ext/viewerBrowser/extension.js
+++ b/data/ext/viewerBrowser/extension.js
@@ -89,12 +89,29 @@ define(function(require, exports, module) {
// fixing embedding of local images
$(viewerIframe.contentWindow.document).find("img[src]").each(function() {
var currentSrc = $(this).attr("src");
- if (currentSrc.indexOf("http://") === 0 || currentSrc.indexOf("https://") === 0 || currentSrc.indexOf("data:") === 0) {
+ if (currentSrc.indexOf("http://") === 0 ||
+ currentSrc.indexOf("https://") === 0 ||
+ currentSrc.indexOf("file://") === 0 ||
+ currentSrc.indexOf("data:") === 0) {
// do nothing if src begins with http(s):// or data:
} else {
- $(this).attr("src", "file://" + fileDirectory + TSCORE.dirSeparator + currentSrc);
+ $(this).attr("src", "file://" + fileDirectory + "/" + currentSrc);
}
});
+
+ $(viewerIframe.contentWindow.document).find("a[href]").each(function() {
+ var currentSrc = $(this).attr("href");
+ if (currentSrc.indexOf("http://") === 0 ||
+ currentSrc.indexOf("https://") === 0 ||
+ currentSrc.indexOf("file://") === 0 ||
+ currentSrc.indexOf("data:") === 0) {
+ // do nothing if src begins with http(s):// or data:
+ } else {
+ var path = "file://" + fileDirectory + "/" + currentSrc;
+ $(this).attr("href", path);
+ }
+ });
+
}
};
diff --git a/data/ext/viewerMD/index.html b/data/ext/viewerMD/index.html
index b0a6cdc55..9795d40d0 100644
--- a/data/ext/viewerMD/index.html
+++ b/data/ext/viewerMD/index.html
@@ -15,6 +15,7 @@
<link rel="stylesheet" href="css/solarized-dark.css"/>
<link rel="stylesheet" href="css/clearness.css"/>
<link rel="stylesheet" href="css/clearness-dark.css"/>
+ <base>
</head>
<body>
<div id="htmlContent"></div>
diff --git a/data/ext/viewerMD/main.js b/data/ext/viewerMD/main.js
index 41d914e98..acf3f5cb4 100644
--- a/data/ext/viewerMD/main.js
+++ b/data/ext/viewerMD/main.js
@@ -113,6 +113,8 @@ function setContent(content, fileDirectory) {
var $htmlContent = $('#htmlContent');
$htmlContent.append(content);
+ $("base").attr("href", fileDirectory + "//");
+
// fixing embedding of local images
$htmlContent.find("img[src]").each(function() {
var currentSrc = $(this).attr("src");