Skip to content

Commit

Permalink
version 2.0.3 Fixes #33 #32 #31 #28 #27
Browse files Browse the repository at this point in the history
  • Loading branch information
evilz committed Mar 24, 2018
1 parent 7c6b21d commit 619a03c
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 103 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
### 2.0.3

Fix issues :

- Export html in folder with same name of markdown file suffixed by '-export'
- Export speaker notes
- Find chrome on linux
- Can change chrome path in configuration
- Slide explorer can be hide in configuration

### 2.0.0

- New sidebar !!!!
Expand Down
15 changes: 13 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-reveal",
"displayName": "vscode-reveal",
"description": "Show markdown as revealJs presentation",
"version": "2.0.2",
"version": "2.0.3",
"publisher": "evilz",
"author": "Vincent Bourdon",
"license": "MIT",
Expand Down Expand Up @@ -240,13 +240,24 @@
"type": "number",
"default": null,
"description": "Number of pixels to move the parallax background per slide"
},
"revealjs.slideExplorerEnabled": {
"type": "boolean",
"default": true,
"description": "Hide or show slides explorer"
},
"revealjs.browserPath": {
"type": "string",
"default": null,
"description": "Full path of browser to use"
}
}
},
"views": {
"explorer": [{
"id": "slidesExplorer",
"name": "Slides"
"name": "Slides",
"when": "slideExplorerEnabled"
}]
},
"menus": {
Expand Down
79 changes: 79 additions & 0 deletions src/BrowserHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import * as path from 'path'
import * as os from 'os'
import * as fs from 'fs'
import * as opn from 'opn'
import { window } from 'vscode'
import { IExtensionOptions } from './Models';

const WIN_APPDATA = process.env.LOCALAPPDATA || '/'

const DEFAULT_CHROME_PATH = {
LINUX: '/usr/bin/google-chrome',
OSX: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
WIN: 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
WIN_LOCALAPPDATA: path.join(WIN_APPDATA, 'Google\\Chrome\\Application\\chrome.exe'),
WINx86: 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',

CHROMIUM_BROWSER: '/usr/bin/chromium-browser',
}

export const enum Platform {
Windows,
OSX,
Linux
}

export function getPlatform(): Platform {
const platform = os.platform()
return platform === 'darwin' ? Platform.OSX : platform === 'win32' ? Platform.Windows : Platform.Linux
}

export function existsSync(filepath: string): boolean {
try {
fs.statSync(filepath)
return true
} catch (e) {
// doesn't exist
return false
}
}

export function getBrowserPath(extensionOptions: IExtensionOptions): string {

if (extensionOptions.browserPath !== null) {
return extensionOptions.browserPath
}


const platform = getPlatform()
if (platform === Platform.OSX) {
return existsSync(DEFAULT_CHROME_PATH.OSX) ? DEFAULT_CHROME_PATH.OSX : null
} else if (platform === Platform.Windows) {
if (existsSync(DEFAULT_CHROME_PATH.WINx86)) {
return DEFAULT_CHROME_PATH.WINx86
} else if (existsSync(DEFAULT_CHROME_PATH.WIN)) {
return DEFAULT_CHROME_PATH.WIN
} else if (existsSync(DEFAULT_CHROME_PATH.WIN_LOCALAPPDATA)) {
return DEFAULT_CHROME_PATH.WIN_LOCALAPPDATA
} else {
return null
}
} else {
return existsSync(DEFAULT_CHROME_PATH.LINUX) ? DEFAULT_CHROME_PATH.LINUX :
existsSync(DEFAULT_CHROME_PATH.CHROMIUM_BROWSER) ? DEFAULT_CHROME_PATH.CHROMIUM_BROWSER :
null
}
}

export const openInBrowser = async (extensionOptions: IExtensionOptions, url: string, headless?: boolean) => {
try {
const browserApp = getBrowserPath(extensionOptions);
if (headless) {
return await opn(url, { app: [browserApp, '--headless'] })
}
return await opn(url, { app: browserApp })
} catch (error) {
window.showWarningMessage('Can find Chrome on your computer, try with default browser...')
await opn(url)
}
}
73 changes: 0 additions & 73 deletions src/ChromeHelper.ts

This file was deleted.

10 changes: 7 additions & 3 deletions src/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@

'use strict'
import * as vscode from 'vscode'
import { ExtensionOptions, IRevealJsOptions, ISlidifyOptions } from './Models'
import { ExtensionOptions, IRevealJsOptions, ISlidifyOptions, IExtensionOptions } from './Models'

export const getRevealJsOptions = () => {
return getExtensionOptions() as IRevealJsOptions
return loadExtensionOptions() as IRevealJsOptions
}

export const getSlidifyOptions = () => {
return getExtensionOptions() as ISlidifyOptions
return loadExtensionOptions() as ISlidifyOptions
}

export const getExtensionOptions = () => {
return loadExtensionOptions() as IExtensionOptions
}

export const loadExtensionOptions = () => {
return (vscode.workspace.getConfiguration('revealjs') as any) as ExtensionOptions
}
22 changes: 12 additions & 10 deletions src/ExportHTML.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ import * as path from 'path'
import * as vscode from 'vscode'
import { VSCodeRevealContext } from './VSCodeRevealContext'

const exportFolderName = 'export'


export const getExportFolderPath = (context: VSCodeRevealContext) => {
const rootDir = path.dirname(context.editor.document.fileName)
const exportFolderName = path.basename(context.editor.document.fileName, '.md') + "-export"
return path.join(rootDir, exportFolderName)
}

export const saveIndex = (rootdir, data) => {
const destDir = path.join(rootdir, exportFolderName)
const destFile = path.join(destDir, 'index.html')
if (!fs.existsSync(destDir)) {
fs.mkdirSync(destDir)
export const saveIndex = (context, rootdir, data) => {
const exportFolderName = getExportFolderPath(context)
const destFile = path.join(exportFolderName, 'index.html')
if (!fs.existsSync(exportFolderName)) {
fs.mkdirSync(exportFolderName)
}

fs.writeFile(destFile, data, err => {
Expand All @@ -36,24 +37,25 @@ const copy = async (file, dest) => {
}
}

export const saveContent = async (rootdir, revealjsDir, req) => {
export const saveContent = async (context, rootdir, revealjsDir, req) => {
const exportFolderName = getExportFolderPath(context)
const staticDirs = ['/css', '/js', '/images', '/plugin', '/lib']

// highlight JS Module
if (req.url.indexOf(`/lib/css/`) === 0) {
const highlightPath = path.resolve(require.resolve('highlight.js'), '..', '..')
// save
const file = path.join(highlightPath, 'styles', req.url.replace(`/lib/css/`, ''))
const dest = path.join(rootdir, 'export', req.url)
const dest = path.join(exportFolderName, req.url)
await copy(file, dest)
} else if (staticDirs.find(dir => req.url.indexOf(dir) === 0)) {
// RevealJS Module or relative files
const file = path.join(revealjsDir, req.url)
const dest = path.join(rootdir, 'export', req.url)
const dest = path.join(exportFolderName, req.url)
await copy(file, dest)
} else if (req.url !== '/') {
const file = path.join(rootdir, req.url)
const dest = path.join(rootdir, 'export', req.url)
const dest = path.join(exportFolderName, req.url)
await copy(file, dest)
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/ExportPDF.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as fs from 'fs'
import * as path from 'path'
import * as vscode from 'vscode'
import { getBrowserPath } from './ChromeHelper'
import { getBrowserPath } from './BrowserHelper'
import { spawn } from 'child_process'
import { getExtensionOptions } from './Configuration';

/*
* export a html to a pdf file (html-pdf)
Expand All @@ -11,7 +12,7 @@ import { spawn } from 'child_process'
export const savePdf = async (url, filename): Promise<string> => {
vscode.window.setStatusBarMessage('$(markdown) export to pdf...')
const promise = new Promise<string>((resolve, reject) => {
const chromePath = getBrowserPath()
const chromePath = getBrowserPath(getExtensionOptions())
const chromeFlags = ['--headless', '--disable-gpu', '--no-margins', '--remote-debugging-port=9222', url]
// const chromeFlags = ['--headless', '--disable-gpu', '--print-to-pdf=' + filename, '--no-margins', '--remote-debugging-port=9222', url]
const chromeProc = spawn(chromePath, chromeFlags, {})
Expand Down
8 changes: 7 additions & 1 deletion src/Models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export enum RevealServerState {
Started
}

export type ExtensionOptions = ISlidifyOptions & IRevealJsOptions
export type ExtensionOptions = ISlidifyOptions & IRevealJsOptions & IExtensionOptions

export interface ISlidifyOptions {
separator: string
Expand Down Expand Up @@ -49,9 +49,15 @@ export interface IRevealJsOptions {
parallaxBackgroundVertical?: number
}

export interface IExtensionOptions {
slideExplorerEnabled: boolean
browserPath: string
}

export interface ISlide {
title: string
index: number
text: string
verticalChildren?: ISlide[] // Rem : child can't have child
}

8 changes: 4 additions & 4 deletions src/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ export class RevealServer {
if (this.context.IsInExportMode) {
const send = res.send
// tslint:disable-next-line:no-this-assignment
const { rootDir, revealBasePath } = this
res.send = function(data) {
saveIndex(rootDir, data)
const { rootDir, revealBasePath, context } = this
res.send = function (data) {
saveIndex(context, rootDir, data)
send.apply(res, arguments)
}
saveContent(rootDir, revealBasePath, req)
saveContent(context, rootDir, revealBasePath, req)
}
next()
}
Expand Down
8 changes: 5 additions & 3 deletions src/commands/exportHTML.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import * as vscode from 'vscode'
import { SHOW_REVEALJS_IN_BROWSER } from './showRevealJSInBrowser'
import * as opn from 'opn'
import { getExportFolderPath } from '../ExportHTML'
import { openInChrome } from '../ChromeHelper'
import { openInBrowser } from '../BrowserHelper'
import { getExtensionOptions } from '../Configuration';

export const EXPORT_HTML = 'vscode-revealjs.exportHTML'
export type EXPORT_HTML = typeof EXPORT_HTML

export const exportHTML = (getContext: (() => VSCodeRevealContext)) => async (topindex: number, verticalIndex: number) => {
export const exportHTML = (getContext: (() => VSCodeRevealContext)) => async () => {
vscode.window.withProgress({ location: vscode.ProgressLocation.Window, title: 'hello' }, p => {
return new Promise((resolve, reject) => {
p.report({ message: 'Start exporting html...' })
Expand All @@ -28,5 +29,6 @@ export const exportHTML = (getContext: (() => VSCodeRevealContext)) => async (to
currentContext.SetInExportMode(() => {
opn(getExportFolderPath(currentContext))
})
openInChrome(currentContext.uri, true)
openInBrowser(getExtensionOptions(), currentContext.uri, true)
openInBrowser(getExtensionOptions(), `${currentContext.server.uri}plugin/notes/notes.html`, true)
}
5 changes: 3 additions & 2 deletions src/commands/exportPDF.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { VSCodeRevealContext } from '../VSCodeRevealContext'
import { openInChrome } from '../ChromeHelper'
import { openInBrowser } from '../BrowserHelper'
import * as vscode from 'vscode'
import { getExtensionOptions } from '../Configuration';

export const EXPORT_PDF = 'vscode-revealjs.exportPDF'
export type EXPORT_PDF = typeof EXPORT_PDF
Expand All @@ -12,7 +13,7 @@ export const exportPDF = (getContext: (() => VSCodeRevealContext)) => (topindex:
return
}
const url = currentContext.server.uri.toString() + '?print-pdf-now'
openInChrome(url)
openInBrowser(getExtensionOptions(), url)
} catch (err) {
vscode.window.showErrorMessage(err)
}
Expand Down
Loading

0 comments on commit 619a03c

Please sign in to comment.