Skip to content

Commit

Permalink
[fix] image path problem on Windows system
Browse files Browse the repository at this point in the history
  • Loading branch information
awmleer committed Jul 8, 2017
1 parent 5880322 commit 19c8cc4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/tasks/*/*.js
/morph-darwin-x64/
/morph-win32-x64/
/build/

# dependencies
/node_modules
Expand Down
17 changes: 15 additions & 2 deletions src/app/pages/presentation-page/presentation-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,13 @@ export class PresentationPageComponent implements OnInit {

parseFile(){
let text = this.electronService.readFile(this.filePath);
let fileDir = this.filePath.replace(/(?:.(?!\/))+$/,'/');
let fileDir;
let isWindows=navigator.appVersion.indexOf('Win')!=-1;
if(isWindows){//for windows
fileDir = this.filePath.replace(/(?:.(?!\\))+$/,'\\');
}else{
fileDir = this.filePath.replace(/(?:.(?!\/))+$/,'/');
}
let lines = text.split('\n');
let inCodeBlock:boolean = false;
let temp:string='';
Expand All @@ -116,7 +122,14 @@ export class PresentationPageComponent implements OnInit {
continue;
}
//fix image file paths
temp=temp.replace(/!\[(.*)\]\(\.\/(.+)\)/g,`![$1](${fileDir}$2)`);
if (temp.match(/!\[.*\]\(.+\)/)) {
if (isWindows) {
temp=temp.replace(/\//g,'\\');
temp=temp.replace(/!\[(.*)\]\(\.\\(.+)\)/g,`![$1](${fileDir}$2)`);
}else{
temp=temp.replace(/!\[(.*)\]\(\.\/(.+)\)/g,`![$1](${fileDir}$2)`);
}
}
//handle headings
if (lines[k].match(/^ *##?#? /)) {
if (temp != '') {
Expand Down
10 changes: 5 additions & 5 deletions src/electron/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ function initMainListener() {
function createWindow() {
applicationRef = new BrowserWindow(mainWindowSettings);
applicationRef.loadURL(`file:///${__dirname}/../index.html`);
applicationRef.webContents.openDevTools();
if (debugMode) {
// Open the DevTools.
applicationRef.webContents.openDevTools();
}
// applicationRef.webContents.openDevTools();
// if (debugMode) {
// // Open the DevTools.
// applicationRef.webContents.openDevTools();
// }
applicationRef.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
Expand Down

0 comments on commit 19c8cc4

Please sign in to comment.