commit
0cfcacce75
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"root": true,
|
||||||
|
"parser": "@typescript-eslint/parser",
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaVersion": 6,
|
||||||
|
"sourceType": "module"
|
||||||
|
},
|
||||||
|
"plugins": [
|
||||||
|
"@typescript-eslint"
|
||||||
|
],
|
||||||
|
"rules": {
|
||||||
|
"@typescript-eslint/naming-convention": "warn",
|
||||||
|
"@typescript-eslint/semi": "warn",
|
||||||
|
"curly": "warn",
|
||||||
|
"eqeqeq": "warn",
|
||||||
|
"no-throw-literal": "warn",
|
||||||
|
"semi": "off"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
out
|
||||||
|
dist
|
||||||
|
node_modules
|
||||||
|
.vscode-test/
|
||||||
|
*.vsix
|
||||||
|
build
|
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||||
|
// for the documentation about the extensions.json format
|
||||||
|
"recommendations": [
|
||||||
|
"dbaeumer.vscode-eslint",
|
||||||
|
"eamodio.tsl-problem-matcher"
|
||||||
|
]
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
// A launch configuration that compiles the extension and then opens it inside a new window
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Run Extension",
|
||||||
|
"type": "extensionHost",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [
|
||||||
|
"--extensionDevelopmentPath=${workspaceFolder}"
|
||||||
|
],
|
||||||
|
"outFiles": [
|
||||||
|
"${workspaceFolder}/dist/**/*.js"
|
||||||
|
],
|
||||||
|
"preLaunchTask": "${defaultBuildTask}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Extension Tests",
|
||||||
|
"type": "extensionHost",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [
|
||||||
|
"--extensionDevelopmentPath=${workspaceFolder}",
|
||||||
|
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
|
||||||
|
],
|
||||||
|
"outFiles": [
|
||||||
|
"${workspaceFolder}/out/test/**/*.js"
|
||||||
|
],
|
||||||
|
"preLaunchTask": "npm: test-watch"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
// Place your settings in this file to overwrite default and user settings.
|
||||||
|
{
|
||||||
|
"files.exclude": {
|
||||||
|
"out": false // set this to true to hide the "out" folder with the compiled JS files
|
||||||
|
},
|
||||||
|
"search.exclude": {
|
||||||
|
"out": true // set this to false to include "out" folder in search results
|
||||||
|
},
|
||||||
|
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
|
||||||
|
"typescript.tsc.autoDetect": "off",
|
||||||
|
"cSpell.words": [
|
||||||
|
"Disposes",
|
||||||
|
"Executes"
|
||||||
|
],
|
||||||
|
"cSpell.language": "de,en-GB,en"
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||||
|
// for the documentation about the tasks.json format
|
||||||
|
{
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"type": "npm",
|
||||||
|
"script": "watch",
|
||||||
|
"problemMatcher": [
|
||||||
|
"$ts-webpack-watch",
|
||||||
|
"$tslint-webpack-watch"
|
||||||
|
],
|
||||||
|
"isBackground": true,
|
||||||
|
"presentation": {
|
||||||
|
"reveal": "never"
|
||||||
|
},
|
||||||
|
"group": {
|
||||||
|
"kind": "build",
|
||||||
|
"isDefault": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "npm",
|
||||||
|
"script": "test-watch",
|
||||||
|
"problemMatcher": "$tsc-watch",
|
||||||
|
"isBackground": true,
|
||||||
|
"presentation": {
|
||||||
|
"reveal": "never"
|
||||||
|
},
|
||||||
|
"group": "build"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
.vscode/**
|
||||||
|
.vscode-test/**
|
||||||
|
out/**
|
||||||
|
src/**
|
||||||
|
.gitignore
|
||||||
|
.yarnrc
|
||||||
|
vsc-extension-quickstart.md
|
||||||
|
**/tsconfig.json
|
||||||
|
**/.eslintrc.json
|
||||||
|
**/*.map
|
||||||
|
**/*.ts
|
@ -0,0 +1,9 @@
|
|||||||
|
# Change Log
|
||||||
|
|
||||||
|
All notable changes to the "snekdown-preview" extension will be documented in this file.
|
||||||
|
|
||||||
|
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
|
||||||
|
- Initial release
|
@ -0,0 +1,23 @@
|
|||||||
|
# Snekdown for vscode
|
||||||
|
|
||||||
|
This extension adds snekdown commands and a snekdown file preview to vscode.
|
||||||
|
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- Preview of snekdown files
|
||||||
|
- Rendering to HTML and PDF
|
||||||
|
- Intialization of a new snekdown project
|
||||||
|
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
This extension is currently only supported on windows and linux. It uses the preinstalled snekdown version if one can be found or
|
||||||
|
downloads the latest one.
|
||||||
|
|
||||||
|
|
||||||
|
## Release Notes
|
||||||
|
|
||||||
|
### 1.0.0
|
||||||
|
|
||||||
|
Initial release of the snekdown extension
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,121 @@
|
|||||||
|
{
|
||||||
|
"name": "snekdown",
|
||||||
|
"displayName": "Snekdown",
|
||||||
|
"description": "Preview and commands for the snekdown markdown flavour",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"engines": {
|
||||||
|
"vscode": "^1.52.0"
|
||||||
|
},
|
||||||
|
"categories": [
|
||||||
|
"Other"
|
||||||
|
],
|
||||||
|
"activationEvents": [
|
||||||
|
"onCommand:snekdown.init",
|
||||||
|
"onCommand:snekdown.preview",
|
||||||
|
"onCommand:snekdown.preview-side",
|
||||||
|
"onCommand:snekdown.clear-cache",
|
||||||
|
"onLanguage:snekdown",
|
||||||
|
"onLanguage:markdown"
|
||||||
|
],
|
||||||
|
"main": "./dist/extension.js",
|
||||||
|
"contributes": {
|
||||||
|
"commands": [
|
||||||
|
{
|
||||||
|
"command": "snekdown.init",
|
||||||
|
"title": "Snekdown: Init Project"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "snekdown.clear-cache",
|
||||||
|
"title": "Snekdown: Clear Cache"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "snekdown.preview",
|
||||||
|
"title": "Snekdown: Open Preview"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "snekdown.preview-side",
|
||||||
|
"title": "Snekdown: Open Preview to the Side"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "snekdown.export-html",
|
||||||
|
"title": "Snekdown: Export as HTML"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "snekdown.export-pdf",
|
||||||
|
"title": "Snekdown: Export as PDF"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"menus": {
|
||||||
|
"commandPalette": [
|
||||||
|
{
|
||||||
|
"command": "snekdown.preview",
|
||||||
|
"when": "editorLangId == markdown || editorLangId == snekdown"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "snekdown.preview-side",
|
||||||
|
"when": "editorLangId == markdown || editorLangId == snekdown"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "snekdown.export-html",
|
||||||
|
"when": "editorLangId == markdown || editorLangId == snekdown"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "snekdown.export-pdf",
|
||||||
|
"when": "editorLangId == markdown || editorLangId == snekdown"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"languages": [{
|
||||||
|
"id": "snekdown",
|
||||||
|
"aliases": ["Snekdown"],
|
||||||
|
"extensions": [
|
||||||
|
".sd.md",
|
||||||
|
".snekdown",
|
||||||
|
".sd",
|
||||||
|
".sdown"
|
||||||
|
]
|
||||||
|
}],
|
||||||
|
"grammars": [
|
||||||
|
{
|
||||||
|
"language": "snekdown",
|
||||||
|
"scopeName": "text.html.snekdown",
|
||||||
|
"path": "./syntaxes/snekdown.tmLanguage"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"vscode:prepublish": "npm run package",
|
||||||
|
"compile": "webpack --config ./build/node-extension.webpack.config.js",
|
||||||
|
"watch": "webpack --watch --config ./build/node-extension.webpack.config.js",
|
||||||
|
"package": "webpack --mode production --devtool hidden-source-map --config ./build/node-extension.webpack.config.js",
|
||||||
|
"test-compile": "tsc -p ./",
|
||||||
|
"test-watch": "tsc -watch -p ./",
|
||||||
|
"pretest": "npm run test-compile && npm run lint",
|
||||||
|
"lint": "eslint src --ext ts",
|
||||||
|
"test": "node ./out/test/runTest.js"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/vscode": "^1.52.0",
|
||||||
|
"@types/glob": "^7.1.3",
|
||||||
|
"@types/mocha": "^8.0.4",
|
||||||
|
"@types/node": "^12.11.7",
|
||||||
|
"eslint": "^7.15.0",
|
||||||
|
"@typescript-eslint/eslint-plugin": "^4.9.0",
|
||||||
|
"@typescript-eslint/parser": "^4.9.0",
|
||||||
|
"glob": "^7.1.6",
|
||||||
|
"mocha": "^8.1.3",
|
||||||
|
"typescript": "^4.1.2",
|
||||||
|
"vscode-test": "^1.4.1",
|
||||||
|
"ts-loader": "^8.0.11",
|
||||||
|
"webpack": "^5.10.0",
|
||||||
|
"webpack-cli": "^4.2.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@microsoft/vscode-file-downloader-api": "^1.0.1",
|
||||||
|
"@types/node-fetch": "^2.5.8",
|
||||||
|
"node-fetch": "^2.6.1"
|
||||||
|
},
|
||||||
|
"extensionDependencies": [
|
||||||
|
"mindaro-dev.file-downloader"
|
||||||
|
]
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
import { pathToFileURL } from 'url';
|
||||||
|
import * as vscode from 'vscode';
|
||||||
|
import * as path from "path";
|
||||||
|
import { SnekdownWrapper, RenderingFormat } from './snekdown-wrapper';
|
||||||
|
import { getActiveFilePath } from './utils';
|
||||||
|
import { SnekdownWebView } from './webview';
|
||||||
|
|
||||||
|
let snekdownWebview: SnekdownWebView;
|
||||||
|
|
||||||
|
export async function activate(context: vscode.ExtensionContext) {
|
||||||
|
const snekdownWrapper = new SnekdownWrapper(context);
|
||||||
|
await snekdownWrapper.download();
|
||||||
|
|
||||||
|
context.subscriptions.push(vscode.commands.registerCommand('snekdown.init', async () => {
|
||||||
|
await snekdownWrapper.init();
|
||||||
|
vscode.window.showInformationMessage("Snekdown Project initialized.");
|
||||||
|
}));
|
||||||
|
|
||||||
|
context.subscriptions.push(vscode.commands.registerCommand('snekdown.clear-ache', async () => {
|
||||||
|
await snekdownWrapper.clearCache();
|
||||||
|
vscode.window.showInformationMessage("Snekdown cache cleared.");
|
||||||
|
}))
|
||||||
|
|
||||||
|
context.subscriptions.push(vscode.commands.registerTextEditorCommand('snekdown.preview', async () => {
|
||||||
|
if (!snekdownWebview || snekdownWebview.isDisposed) {
|
||||||
|
snekdownWebview = new SnekdownWebView(context, snekdownWrapper, vscode.ViewColumn.One);
|
||||||
|
}
|
||||||
|
await snekdownWebview.update();
|
||||||
|
}));
|
||||||
|
|
||||||
|
context.subscriptions.push(vscode.commands.registerTextEditorCommand('snekdown.preview-side', async () => {
|
||||||
|
if (!snekdownWebview || snekdownWebview.isDisposed) {
|
||||||
|
snekdownWebview = new SnekdownWebView(context, snekdownWrapper, vscode.ViewColumn.Two);
|
||||||
|
}
|
||||||
|
await snekdownWebview.update();
|
||||||
|
}));
|
||||||
|
|
||||||
|
context.subscriptions.push(vscode.commands.registerTextEditorCommand('snekdown.export-html', async () => {
|
||||||
|
let inputFile = getActiveFilePath();
|
||||||
|
let placeholderOutput = inputFile.replace(/\.\w+$/, ".html");
|
||||||
|
let outputFile = await vscode.window.showInputBox({
|
||||||
|
prompt: "Output File",
|
||||||
|
value: placeholderOutput,
|
||||||
|
});
|
||||||
|
if (outputFile) {
|
||||||
|
await vscode.window.withProgress({ location: vscode.ProgressLocation.Window, title: "Rendering HTML" }, async () => {
|
||||||
|
await snekdownWrapper.renderToFile(inputFile, outputFile as string, RenderingFormat.html);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
context.subscriptions.push(vscode.commands.registerTextEditorCommand('snekdown.export-pdf', async () => {
|
||||||
|
let inputFile = getActiveFilePath();
|
||||||
|
let placeholderOutput = inputFile.replace(/\.\w+$/, ".pdf");
|
||||||
|
let outputFile = await vscode.window.showInputBox({
|
||||||
|
prompt: "Output File",
|
||||||
|
value: placeholderOutput,
|
||||||
|
});
|
||||||
|
if (outputFile) {
|
||||||
|
await vscode.window.withProgress({ location: vscode.ProgressLocation.Window, title: "Rendering PDF" }, async () => {
|
||||||
|
await snekdownWrapper.renderToFile(inputFile, outputFile as string, RenderingFormat.pdf);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function deactivate() {
|
||||||
|
if (snekdownWebview && !snekdownWebview.isDisposed) {
|
||||||
|
snekdownWebview.close();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,132 @@
|
|||||||
|
import {getApi, FileDownloader} from "@microsoft/vscode-file-downloader-api";
|
||||||
|
import { exec, execFile } from "child_process";
|
||||||
|
import { chmodSync } from "fs";
|
||||||
|
import * as os from "os";
|
||||||
|
import * as path from "path";
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { pathToFileURL } from "url";
|
||||||
|
import { setFlagsFromString } from "v8";
|
||||||
|
import { ExtensionContext, Uri } from "vscode";
|
||||||
|
import * as vscode from "vscode";
|
||||||
|
import fetch from "node-fetch";
|
||||||
|
|
||||||
|
const SNEKDOWN_FILE_LINUX = "snekdown-linux-x86_64";
|
||||||
|
const SNEKDOWN_FILE_WINDOWS = "snekdown-windows-x86_64.exe";
|
||||||
|
const SNEKDOWN_URL_LINUX = "https://github.com/Trivernis/snekdown/releases/latest/download/" + SNEKDOWN_FILE_LINUX;
|
||||||
|
const SNEKDOWN_URL_WINDOWS = "https://github.com/Trivernis/snekdown/releases/latest/download/" + SNEKDOWN_FILE_WINDOWS;
|
||||||
|
|
||||||
|
|
||||||
|
enum SnekdownCommand {
|
||||||
|
render = "render",
|
||||||
|
watch = "watch",
|
||||||
|
init = "init",
|
||||||
|
clearCache = "clear-cache",
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum RenderingFormat {
|
||||||
|
html = "html",
|
||||||
|
pdf = "pdf",
|
||||||
|
}
|
||||||
|
|
||||||
|
export class SnekdownWrapper {
|
||||||
|
private executable: string = "snekdown";
|
||||||
|
|
||||||
|
constructor(private context: ExtensionContext) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes a snekdown project
|
||||||
|
*/
|
||||||
|
public async init() {
|
||||||
|
await this.execute(SnekdownCommand.init, []);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders a file to html and returns the html string
|
||||||
|
* @param inputFile
|
||||||
|
*/
|
||||||
|
public async renderHTML(inputFile: string): Promise<string> {
|
||||||
|
return this.execute(SnekdownCommand.render, [inputFile, "--stdout"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the image and rendering cache
|
||||||
|
*/
|
||||||
|
public async clearCache() {
|
||||||
|
await this.execute(SnekdownCommand.clearCache, []);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the document to a file
|
||||||
|
* @param inputFile
|
||||||
|
* @param outputFile
|
||||||
|
* @param format
|
||||||
|
*/
|
||||||
|
public async renderToFile(inputFile: string, outputFile: string, format: RenderingFormat) {
|
||||||
|
await this.execute(SnekdownCommand.render, [inputFile, outputFile, "--format", format]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detects or downloads the snekdown executable
|
||||||
|
*/
|
||||||
|
public async download () {
|
||||||
|
const fileDownloader: FileDownloader = await getApi();
|
||||||
|
|
||||||
|
let execPath: string;
|
||||||
|
|
||||||
|
switch (os.platform()) {
|
||||||
|
case 'win32':
|
||||||
|
execPath = this.buildExecutablePath(SNEKDOWN_FILE_WINDOWS);
|
||||||
|
await fetch(SNEKDOWN_FILE_WINDOWS).then(res => {
|
||||||
|
fs.writeFileSync(execPath, res.buffer);
|
||||||
|
});
|
||||||
|
this.executable = execPath;
|
||||||
|
break;
|
||||||
|
case 'linux':
|
||||||
|
if (fs.existsSync("/usr/bin/snekdown")) {
|
||||||
|
this.executable = "/usr/bin/snekdown";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
execPath = this.buildExecutablePath(SNEKDOWN_FILE_LINUX);
|
||||||
|
await fetch(SNEKDOWN_URL_LINUX).then(res => {
|
||||||
|
fs.writeFileSync(execPath, res.buffer);
|
||||||
|
});
|
||||||
|
this.executable = execPath;
|
||||||
|
chmodSync(execPath, "555");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Error("OS Platform not supported.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the path in the extension folder for a given file
|
||||||
|
*/
|
||||||
|
private buildExecutablePath(filename: string): string {
|
||||||
|
return path.join(this.context.extensionPath, filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes a snekdown command and returns the stdout value
|
||||||
|
* @param command
|
||||||
|
* @param args
|
||||||
|
*/
|
||||||
|
private async execute(command: SnekdownCommand, args: string[]): Promise<string> {
|
||||||
|
let cwd: string;
|
||||||
|
if (vscode.workspace.workspaceFolders) {
|
||||||
|
cwd = vscode.workspace.workspaceFolders[0].uri.fsPath;
|
||||||
|
}
|
||||||
|
return new Promise((res, rej) => {
|
||||||
|
let process = execFile(this.executable, [command, ...args], {cwd}, (err, stdout, stderr) => {
|
||||||
|
if (err) {
|
||||||
|
rej(err);
|
||||||
|
}
|
||||||
|
if (process.exitCode !== 0) {
|
||||||
|
rej(stderr);
|
||||||
|
}
|
||||||
|
console.log(stderr);
|
||||||
|
res(stdout);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
import * as path from 'path';
|
||||||
|
|
||||||
|
import { runTests } from 'vscode-test';
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
try {
|
||||||
|
// The folder containing the Extension Manifest package.json
|
||||||
|
// Passed to `--extensionDevelopmentPath`
|
||||||
|
const extensionDevelopmentPath = path.resolve(__dirname, '../../');
|
||||||
|
|
||||||
|
// The path to test runner
|
||||||
|
// Passed to --extensionTestsPath
|
||||||
|
const extensionTestsPath = path.resolve(__dirname, './suite/index');
|
||||||
|
|
||||||
|
// Download VS Code, unzip it and run the integration test
|
||||||
|
await runTests({ extensionDevelopmentPath, extensionTestsPath });
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Failed to run tests');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
@ -0,0 +1,15 @@
|
|||||||
|
import * as assert from 'assert';
|
||||||
|
|
||||||
|
// You can import and use all API from the 'vscode' module
|
||||||
|
// as well as import your extension to test it
|
||||||
|
import * as vscode from 'vscode';
|
||||||
|
// import * as myExtension from '../../extension';
|
||||||
|
|
||||||
|
suite('Extension Test Suite', () => {
|
||||||
|
vscode.window.showInformationMessage('Start all tests.');
|
||||||
|
|
||||||
|
test('Sample test', () => {
|
||||||
|
assert.strictEqual(-1, [1, 2, 3].indexOf(5));
|
||||||
|
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,38 @@
|
|||||||
|
import * as path from 'path';
|
||||||
|
import * as Mocha from 'mocha';
|
||||||
|
import * as glob from 'glob';
|
||||||
|
|
||||||
|
export function run(): Promise<void> {
|
||||||
|
// Create the mocha test
|
||||||
|
const mocha = new Mocha({
|
||||||
|
ui: 'tdd',
|
||||||
|
color: true
|
||||||
|
});
|
||||||
|
|
||||||
|
const testsRoot = path.resolve(__dirname, '..');
|
||||||
|
|
||||||
|
return new Promise((c, e) => {
|
||||||
|
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
|
||||||
|
if (err) {
|
||||||
|
return e(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add files to the test suite
|
||||||
|
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Run the mocha test
|
||||||
|
mocha.run(failures => {
|
||||||
|
if (failures > 0) {
|
||||||
|
e(new Error(`${failures} tests failed.`));
|
||||||
|
} else {
|
||||||
|
c();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
e(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
import * as vscode from "vscode";
|
||||||
|
|
||||||
|
|
||||||
|
export function getActiveFilePath(): string {
|
||||||
|
return vscode.window.activeTextEditor?.document.fileName as unknown as string;
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
import { ExtensionContext, ViewColumn, WebviewPanel, window } from "vscode";
|
||||||
|
import { SnekdownWrapper } from "./snekdown-wrapper";
|
||||||
|
import * as vscode from "vscode";
|
||||||
|
|
||||||
|
export class SnekdownWebView {
|
||||||
|
|
||||||
|
private view: WebviewPanel;
|
||||||
|
private editor = vscode.window.activeTextEditor;
|
||||||
|
public isDisposed = false;
|
||||||
|
|
||||||
|
constructor(private context: ExtensionContext, private wrapper: SnekdownWrapper, columns: ViewColumn, ) {
|
||||||
|
this.view = window.createWebviewPanel("snekdownPreview", "Snekdown Preview", columns);
|
||||||
|
this.view.webview.options = {
|
||||||
|
enableScripts: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
const changeListener = vscode.workspace.onDidSaveTextDocument(async () => {
|
||||||
|
await this.update();
|
||||||
|
});
|
||||||
|
this.view.onDidDispose(() => {
|
||||||
|
this.isDisposed = true;
|
||||||
|
changeListener.dispose();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disposes of the view
|
||||||
|
*/
|
||||||
|
public close() {
|
||||||
|
this.view.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the webview
|
||||||
|
*/
|
||||||
|
public async update() {
|
||||||
|
const html = await this.getHTML();
|
||||||
|
this.setHTML(html);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async getHTML(): Promise<string> {
|
||||||
|
return await this.wrapper.renderHTML(this.editor?.document.fileName as unknown as string);
|
||||||
|
}
|
||||||
|
|
||||||
|
private setHTML(html: string) {
|
||||||
|
this.view.webview.html = html;
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "commonjs",
|
||||||
|
"target": "es6",
|
||||||
|
"outDir": "out",
|
||||||
|
"lib": [
|
||||||
|
"es6"
|
||||||
|
],
|
||||||
|
"sourceMap": true,
|
||||||
|
"rootDir": "src",
|
||||||
|
"strict": true /* enable all strict type-checking options */
|
||||||
|
/* Additional Checks */
|
||||||
|
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||||
|
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||||
|
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||||
|
},
|
||||||
|
"exclude": [
|
||||||
|
"node_modules",
|
||||||
|
".vscode-test"
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in New Issue