base version ,but still have some problem--show the last change version because the isuue of tiggle process
diff --git a/media/Preview.svg b/media/Preview.svg
new file mode 100644
index 0000000..000f463
--- /dev/null
+++ b/media/Preview.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0.414 0 16 16" enable-background="new 0.414 0 16 16"><path fill="#F6F6F6" d="M12.363 4c-.252-2.244-2.139-4-4.449-4-2.481 0-4.5 2.019-4.5 4.5 0 .6.12 1.188.35 1.735l-3.764 3.765 2.414 2.414 3-2.999v6.585h11v-12h-4.051z"/><rect x="12.414" y="10" fill="#424242" width="1" height="3"/><rect x="10.414" y="11" fill="#424242" width="1" height="2"/><rect x="8.414" y="12" fill="#424242" width="1" height="1"/><rect x="8.414" y="9" fill="#424242" width="2" height="1"/><path fill="#424242" d="M12.363 5c-.039.347-.112.681-.226 1h2.276v8h-7v-5.05c-.342-.039-.676-.112-1-.228v6.278h9v-10h-3.05z"/><path fill="#424242" d="M10.708 8h1.706v-1h-.762c-.257.384-.585.712-.944 1z"/><path fill="#424242" d="M11.414 4.5c0-1.933-1.567-3.5-3.5-3.5s-3.5 1.567-3.5 3.5c0 .711.215 1.369.579 1.922l-3.579 3.578 1 1 3.579-3.578c.552.363 1.211.578 1.921.578 1.933 0 3.5-1.567 3.5-3.5zm-5.999 0c0-1.381 1.119-2.5 2.5-2.5s2.5 1.119 2.5 2.5-1.12 2.5-2.5 2.5-2.5-1.119-2.5-2.5z"/><path fill="#F0EFF1" d="M12.138 6c-.126.354-.279.693-.485 1h.762v1h-1.706c-.771.616-1.734 1-2.795 1-.169 0-.333-.031-.5-.05v5.05h7v-8h-2.276zm-3.724 3h2v1h-2v-1zm1 4h-1v-1h1v1zm2 0h-1v-2h1v2zm2 0h-1v-3h1v3z"/><circle fill="#F0EFF1" cx="7.914" cy="4.5" r="2.5"/></svg>
\ No newline at end of file
diff --git a/media/PreviewOnRightPane_16x.svg b/media/PreviewOnRightPane_16x.svg
new file mode 100644
index 0000000..eefaadf
--- /dev/null
+++ b/media/PreviewOnRightPane_16x.svg
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Generator: Adobe Illustrator 19.2.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
+<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
+ viewBox="0 0 16 16" style="enable-background:new 0 0 16 16;" xml:space="preserve">
+<style type="text/css">
+ .icon_x002D_vs_x002D_bg{fill:#424242;}
+</style>
+<g id="canvas">
+</g>
+<g id="outline">
+</g>
+<g id="iconFg">
+</g>
+<g id="iconBg">
+ <path class="icon_x002D_vs_x002D_bg" d="M9,5h5v2.4c0.4,0.2,0.7,0.4,1,0.7V2H1v12h5.6L9,11.6V5z M2,13V5h5v8H2z M11.3,12.7
+ c0.4,0.2,0.8,0.3,1.2,0.3c1.4,0,2.5-1.1,2.5-2.5C15,9.1,13.9,8,12.5,8C11.1,8,10,9.1,10,10.5c0,0.4,0.1,0.8,0.3,1.2L8,14l1,1
+ L11.3,12.7z M11,10.5C11,9.7,11.7,9,12.5,9c0.8,0,1.5,0.7,1.5,1.5c0,0.8-0.7,1.5-1.5,1.5C11.7,12,11,11.3,11,10.5z"/>
+</g>
+</svg>
diff --git a/media/PreviewOnRightPane_16x_dark.svg b/media/PreviewOnRightPane_16x_dark.svg
new file mode 100644
index 0000000..c18634b
--- /dev/null
+++ b/media/PreviewOnRightPane_16x_dark.svg
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Generator: Adobe Illustrator 19.2.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
+<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
+ viewBox="0 0 16 16" style="enable-background:new 0 0 16 16;" xml:space="preserve">
+<style type="text/css">
+ .st0{fill:#C5C5C5;}
+</style>
+<g id="canvas">
+</g>
+<g id="outline">
+</g>
+<g id="iconFg">
+</g>
+<g id="iconBg">
+ <path class="st0" d="M9,5h5v2.4c0.4,0.2,0.7,0.4,1,0.7V2H1v12h5.6L9,11.6V5z M2,13V5h5v8H2z M11.3,12.7c0.4,0.2,0.8,0.3,1.2,0.3
+ c1.4,0,2.5-1.1,2.5-2.5C15,9.1,13.9,8,12.5,8C11.1,8,10,9.1,10,10.5c0,0.4,0.1,0.8,0.3,1.2L8,14l1,1L11.3,12.7z M11,10.5
+ C11,9.7,11.7,9,12.5,9c0.8,0,1.5,0.7,1.5,1.5c0,0.8-0.7,1.5-1.5,1.5C11.7,12,11,11.3,11,10.5z"/>
+</g>
+</svg>
diff --git a/media/Preview_inverse.svg b/media/Preview_inverse.svg
new file mode 100644
index 0000000..6b95a3a
--- /dev/null
+++ b/media/Preview_inverse.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0.414 0 16 16" enable-background="new 0.414 0 16 16"><path fill="#252626" d="M12.363 4c-.252-2.244-2.139-4-4.449-4-2.481 0-4.5 2.019-4.5 4.5 0 .6.12 1.188.35 1.735l-3.764 3.765 2.414 2.414 3-2.999v6.585h11v-12h-4.051z"/><rect x="12.414" y="10" fill="#C5C5C5" width="1" height="3"/><rect x="10.414" y="11" fill="#C5C5C5" width="1" height="2"/><rect x="8.414" y="12" fill="#C5C5C5" width="1" height="1"/><rect x="8.414" y="9" fill="#C5C5C5" width="2" height="1"/><path fill="#C5C5C5" d="M12.363 5c-.039.347-.112.681-.226 1h2.276v8h-7v-5.05c-.342-.039-.676-.112-1-.228v6.278h9v-10h-3.05z"/><path fill="#C5C5C5" d="M10.708 8h1.706v-1h-.762c-.257.384-.585.712-.944 1z"/><path fill="#C5C5C5" d="M11.414 4.5c0-1.933-1.567-3.5-3.5-3.5s-3.5 1.567-3.5 3.5c0 .711.215 1.369.579 1.922l-3.579 3.578 1 1 3.579-3.578c.552.363 1.211.578 1.921.578 1.933 0 3.5-1.567 3.5-3.5zm-5.999 0c0-1.381 1.119-2.5 2.5-2.5s2.5 1.119 2.5 2.5-1.12 2.5-2.5 2.5-2.5-1.119-2.5-2.5z"/><path fill="#2B282E" d="M12.138 6c-.126.354-.279.693-.485 1h.762v1h-1.706c-.771.616-1.734 1-2.795 1-.169 0-.333-.031-.5-.05v5.05h7v-8h-2.276zm-3.724 3h2v1h-2v-1zm1 4h-1v-1h1v1zm2 0h-1v-2h1v2zm2 0h-1v-3h1v3z"/><circle fill="#2B282E" cx="7.914" cy="4.5" r="2.5"/></svg>
\ No newline at end of file
diff --git a/media/ViewSource.svg b/media/ViewSource.svg
new file mode 100644
index 0000000..fccdf83
--- /dev/null
+++ b/media/ViewSource.svg
@@ -0,0 +1,3 @@
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [
+ <!ENTITY ns_flows "http://ns.adobe.com/Flows/1.0/">
+]><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><polygon fill="#656565" points="10,2 7.414,2 8.414,3 9,3 9,3.586 9,4 9,4.414 9,6 12,6 12,13 4,13 4,8 3,8 3,14 13,14 13,5"/><polygon fill="#00539C" points="5,1 3,1 5,3 1,3 1,5 5,5 3,7 5,7 8,4"/></svg>
\ No newline at end of file
diff --git a/media/ViewSource_inverse.svg b/media/ViewSource_inverse.svg
new file mode 100644
index 0000000..f630218
--- /dev/null
+++ b/media/ViewSource_inverse.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><polygon fill="#C5C5C5" points="10,2 7.414,2 8.414,3 9,3 9,3.586 9,4 9,4.414 9,6 12,6 12,13 4,13 4,8 3,8 3,14 13,14 13,5"/><polygon fill="#75BEFF" points="5,1 3,1 5,3 1,3 1,5 5,5 3,7 5,7 8,4"/></svg>
\ No newline at end of file
diff --git a/media/markdown.css b/media/markdown.css
new file mode 100644
index 0000000..91c557c
--- /dev/null
+++ b/media/markdown.css
@@ -0,0 +1,163 @@
+/*---------------------------------------------------------------------------------------------
+ * Copyright (c) Microsoft Corporation. All rights reserved.
+ * Licensed under the MIT License. See License.txt in the project root for license information.
+ *--------------------------------------------------------------------------------------------*/
+
+body {
+ font-family: "Segoe WPC", "Segoe UI", "SFUIText-Light", "HelveticaNeue-Light", sans-serif, "Droid Sans Fallback";
+ font-size: 14px;
+ padding-left: 12px;
+ line-height: 22px;
+}
+
+img {
+ max-width: 100%;
+ max-height: 100%;
+}
+
+a {
+ color: #4080D0;
+ text-decoration: none;
+}
+
+a:focus,
+input:focus,
+select:focus,
+textarea:focus {
+ outline: 1px solid -webkit-focus-ring-color;
+ outline-offset: -1px;
+}
+
+hr {
+ border: 0;
+ height: 2px;
+ border-bottom: 2px solid;
+}
+
+h1 {
+ padding-bottom: 0.3em;
+ line-height: 1.2;
+ border-bottom-width: 1px;
+ border-bottom-style: solid;
+}
+
+h1, h2, h3 {
+ font-weight: normal;
+}
+
+a:hover {
+ color: #4080D0;
+ text-decoration: underline;
+}
+
+table {
+ border-collapse: collapse;
+}
+
+table > thead > tr > th {
+ text-align: left;
+ border-bottom: 1px solid;
+}
+
+table > thead > tr > th,
+table > thead > tr > td,
+table > tbody > tr > th,
+table > tbody > tr > td {
+ padding: 5px 10px;
+}
+
+table > tbody > tr + tr > td {
+ border-top: 1px solid;
+}
+
+blockquote {
+ margin: 0 7px 0 5px;
+ padding: 0 16px 0 10px;
+ border-left: 5px solid;
+}
+
+code {
+ font-family: Menlo, Monaco, Consolas, "Droid Sans Mono", "Courier New", monospace, "Droid Sans Fallback";
+ font-size: 14px;
+ line-height: 19px;
+}
+
+.mac code {
+ font-size: 12px;
+ line-height: 18px;
+}
+
+code > div {
+ padding: 16px;
+ border-radius: 3px;
+ overflow: auto;
+}
+
+/** Theming */
+
+.vscode-light {
+ color: rgb(30, 30, 30);
+}
+
+.vscode-dark {
+ color: #DDD;
+}
+
+.vscode-high-contrast {
+ color: white;
+}
+
+.vscode-light code {
+ color: #A31515;
+}
+
+.vscode-dark code {
+ color: #D7BA7D;
+}
+
+.vscode-light code > div {
+ background-color: rgba(220, 220, 220, 0.4);
+}
+
+.vscode-dark code > div {
+ background-color: rgba(10, 10, 10, 0.4);
+}
+
+.vscode-high-contrast code > div {
+ background-color: rgb(0, 0, 0);
+}
+
+.vscode-high-contrast h1 {
+ border-color: rgb(0, 0, 0);
+}
+
+.vscode-light table > thead > tr > th {
+ border-color: rgba(0, 0, 0, 0.69);
+}
+
+.vscode-dark table > thead > tr > th {
+ border-color: rgba(255, 255, 255, 0.69);
+}
+
+.vscode-light h1,
+.vscode-light hr,
+.vscode-light table > tbody > tr + tr > td {
+ border-color: rgba(0, 0, 0, 0.18);
+}
+
+.vscode-dark h1,
+.vscode-dark hr,
+.vscode-dark table > tbody > tr + tr > td {
+ border-color: rgba(255, 255, 255, 0.18);
+}
+
+.vscode-light blockquote,
+.vscode-dark blockquote {
+ background: rgba(127, 127, 127, 0.1);
+ border-color: rgba(0, 122, 204, 0.5);
+}
+
+.vscode-high-contrast blockquote {
+ background: transparent;
+ border-color: #fff;
+}
\ No newline at end of file
diff --git a/media/tomorrow.css b/media/tomorrow.css
new file mode 100644
index 0000000..96edd12
--- /dev/null
+++ b/media/tomorrow.css
@@ -0,0 +1,73 @@
+/* Tomorrow Theme */
+/* http://jmblog.github.com/color-themes-for-google-code-highlightjs */
+/* Original theme - https://github.com/chriskempson/tomorrow-theme */
+
+/* Tomorrow Comment */
+.hljs-comment,
+.hljs-quote {
+ color: #8e908c;
+}
+
+/* Tomorrow Red */
+.hljs-variable,
+.hljs-template-variable,
+.hljs-tag,
+.hljs-name,
+.hljs-selector-id,
+.hljs-selector-class,
+.hljs-regexp,
+.hljs-deletion {
+ color: #c82829;
+}
+
+/* Tomorrow Orange */
+.hljs-number,
+.hljs-built_in,
+.hljs-builtin-name,
+.hljs-literal,
+.hljs-type,
+.hljs-params,
+.hljs-meta,
+.hljs-link {
+ color: #f5871f;
+}
+
+/* Tomorrow Yellow */
+.hljs-attribute {
+ color: #eab700;
+}
+
+/* Tomorrow Green */
+.hljs-string,
+.hljs-symbol,
+.hljs-bullet,
+.hljs-addition {
+ color: #718c00;
+}
+
+/* Tomorrow Blue */
+.hljs-title,
+.hljs-section {
+ color: #4271ae;
+}
+
+/* Tomorrow Purple */
+.hljs-keyword,
+.hljs-selector-tag {
+ color: #8959a8;
+}
+
+.hljs {
+ display: block;
+ overflow-x: auto;
+ color: #4d4d4c;
+ padding: 0.5em;
+}
+
+.hljs-emphasis {
+ font-style: italic;
+}
+
+.hljs-strong {
+ font-weight: bold;
+}
\ No newline at end of file
diff --git a/out/src/extension.js b/out/src/extension.js
index 1a56c19..12402d0 100644
--- a/out/src/extension.js
+++ b/out/src/extension.js
@@ -1,39 +1,146 @@
'use strict';
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
+var vscode = require('vscode');
+var path = require('path');
var vscode_1 = require('vscode');
var child_process = require('child_process');
+var previewresult = "";
+var Is_waiting = false;
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
function activate(context) {
// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
console.log('Congratulations, your extension "previewtest-ts" is now active!');
- var preview = new Mypreview();
+ var previewUri = vscode_1.Uri.parse('css-preview://authority/css-preview');
+ var packageInfo = getPackageInfo(context);
+ //telemetryReporter = packageInfo && new TelemetryReporter(packageInfo.name, packageInfo.version, packageInfo.aiKey);
+ var provider = new MDDocumentContentProvider(context);
+ var registration = vscode.workspace.registerTextDocumentContentProvider('markdown', provider);
+ //var preview = new Mypreview(context);
// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
var disposable = vscode_1.commands.registerCommand('extension.sayHello', function () {
// The code you place here will be executed every time your command is executed
- preview.sayHello();
+ //preview.sayHello();
//spawn.stdin.write("t-jipe\n");
// Display a message box to the user
vscode_1.window.showInformationMessage('Hello World!');
});
- context.subscriptions.push(disposable);
+ var d1 = vscode_1.commands.registerCommand('extension.showpreview', showPreview);
+ context.subscriptions.push(disposable, d1, registration);
+ vscode.workspace.onDidSaveTextDocument(function (document) {
+ if (isMarkdownFile(document)) {
+ var uri = getMarkdownUri(document.uri);
+ provider.update(uri);
+ }
+ });
+ vscode.workspace.onDidChangeTextDocument(function (event) {
+ if (isMarkdownFile(event.document)) {
+ var uri = getMarkdownUri(event.document.uri);
+ provider.update(uri);
+ }
+ });
+ vscode.workspace.onDidChangeConfiguration(function () {
+ vscode.workspace.textDocuments.forEach(function (document) {
+ if (document.uri.scheme === 'markdown') {
+ // update all generated md documents
+ provider.update(document.uri);
+ }
+ });
+ });
}
exports.activate = activate;
+function isMarkdownFile(document) {
+ return document.languageId === 'markdown'
+ && document.uri.scheme !== 'markdown'; // prevent processing of own documents
+}
+function getMarkdownUri(uri) {
+ return uri.with({ scheme: 'markdown', path: uri.path + '.rendered', query: uri.toString() });
+}
+function showPreview(uri, sideBySide) {
+ if (sideBySide === void 0) { sideBySide = true; }
+ var resource = uri;
+ if (!(resource instanceof vscode_1.Uri)) {
+ if (vscode.window.activeTextEditor) {
+ // we are relaxed and don't check for markdown files
+ resource = vscode.window.activeTextEditor.document.uri;
+ }
+ }
+ if (!(resource instanceof vscode_1.Uri)) {
+ if (!vscode.window.activeTextEditor) {
+ // this is most likely toggling the preview
+ return vscode.commands.executeCommand('markdown.showSource');
+ }
+ // nothing found that could be shown or toggled
+ return;
+ }
+ var thenable = vscode.commands.executeCommand('vscode.previewHtml', getMarkdownUri(resource), getViewColumn(sideBySide), "Preview '" + path.basename(resource.fsPath) + "'");
+ /*telemetryReporter.sendTelemetryEvent('openPreview', {
+ where : sideBySide ? 'sideBySide' : 'inPlace',
+ how : (uri instanceof Uri) ? 'action' : 'pallete'
+ });
+*/
+ return thenable;
+}
+function getViewColumn(sideBySide) {
+ var active = vscode.window.activeTextEditor;
+ if (!active) {
+ return vscode_1.ViewColumn.One;
+ }
+ if (!sideBySide) {
+ return active.viewColumn;
+ }
+ switch (active.viewColumn) {
+ case vscode_1.ViewColumn.One:
+ return vscode_1.ViewColumn.Two;
+ case vscode_1.ViewColumn.Two:
+ return vscode_1.ViewColumn.Three;
+ }
+ return active.viewColumn;
+}
+function showSource(mdUri) {
+ if (!mdUri) {
+ return vscode.commands.executeCommand('workbench.action.navigateBack');
+ }
+ var docUri = vscode_1.Uri.parse(mdUri.query);
+ for (var _i = 0, _a = vscode.window.visibleTextEditors; _i < _a.length; _i++) {
+ var editor = _a[_i];
+ if (editor.document.uri.toString() === docUri.toString()) {
+ return vscode.window.showTextDocument(editor.document, editor.viewColumn);
+ }
+ }
+ return vscode.workspace.openTextDocument(docUri).then(function (doc) {
+ return vscode.window.showTextDocument(doc);
+ });
+}
+function getPackageInfo(context) {
+ var extensionPackage = require(context.asAbsolutePath('./package.json'));
+ if (extensionPackage) {
+ return {
+ name: extensionPackage.name,
+ version: extensionPackage.version,
+ aiKey: extensionPackage.aiKey
+ };
+ }
+ return null;
+}
// this method is called when your extension is deactivated
function deactivate() {
}
exports.deactivate = deactivate;
var Mypreview = (function () {
- function Mypreview() {
- this._spawn = child_process.spawn('E:\\Docfx\\test\\Dfm_test\\Dfm_test\\bin\\Debug\\Dfm_test.exe');
+ //public _preview_result : string;
+ function Mypreview(context) {
+ var extpath = context.asAbsolutePath('./Dfm_test/Dfm_test/bin/Debug/Dfm_test.exe');
+ this._spawn = child_process.spawn(extpath);
//count = 0;
//this._preview_result = "";
this._spawn.stdout.on('data', function (data) {
- console.log("data " + '\n' + data);
+ console.log(data.toString());
+ previewresult = data.toString();
});
this._spawn.stderr.on('data', function (data) {
console.log("error " + data + '\n');
@@ -57,4 +164,96 @@
};
return Mypreview;
}());
+var MDDocumentContentProvider = (function () {
+ function MDDocumentContentProvider(context) {
+ this._onDidChange = new vscode_1.EventEmitter();
+ this._context = context;
+ this._waiting = false;
+ this._dfm_process = new Mypreview(context);
+ }
+ MDDocumentContentProvider.prototype.getMediaPath = function (mediaFile) {
+ return this._context.asAbsolutePath(path.join('media', mediaFile));
+ };
+ /*
+ private isAbsolute(p) : boolean {
+ return path.normalize(p + '/') === path.normalize(path.resolve(p) + '/');
+ }
+
+ private fixHref(resource: Uri, href: string) : string {
+ if (href) {
+ // Use href if it is already an URL
+ if (Uri.parse(href).scheme) {
+ return href;
+ }
+
+ // Use href as file URI if it is absolute
+ if (this.isAbsolute(href)) {
+ return Uri.file(href).toString();
+ }
+
+ // use a workspace relative path if there is a workspace
+ let rootPath = vscode.workspace.rootPath;
+ if (rootPath) {
+ return Uri.file(path.join(rootPath, href)).toString();
+ }
+
+ // otherwise look relative to the markdown file
+ return Uri.file(path.join(path.dirname(resource.fsPath), href)).toString();
+ }
+ return href;
+ }
+
+
+ private computeCustomStyleSheetIncludes(uri: Uri): string[] {
+ const styles = vscode.workspace.getConfiguration('markdown')['styles'];
+ if (styles && Array.isArray(styles) && styles.length > 0) {
+ return styles.map((style) => {
+ return `<link rel="stylesheet" href="${this.fixHref(uri, style)}" type="text/css" media="screen">`;
+ });
+ }
+ return [];
+ }*/
+ MDDocumentContentProvider.prototype.provideTextDocumentContent = function (uri) {
+ var _this = this;
+ this._dfm_process.sayHello();
+ return vscode.workspace.openTextDocument(vscode_1.Uri.parse(uri.query)).then(function (document) {
+ var head = [].concat('<!DOCTYPE html>', '<html>', '<head>', '<meta http-equiv="Content-type" content="text/html;charset=UTF-8">', "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + _this.getMediaPath('markdown.css') + "\" >", "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + _this.getMediaPath('tomorrow.css') + "\" >",
+ //this.computeCustomStyleSheetIncludes(uri),
+ "<base href=\"" + document.uri.toString(true) + "\">", '</head>', '<body>').join('\n');
+ //const body = this._renderer.render(document.getText());
+ /*const body = [
+ '<p> this is a paragraph</p>',
+ '<p> this is another paragraph</p>'
+ ].join('\n');*/
+ //this._dfm_process.sayHello();
+ // Is_waiting = true;
+ //while(Is_waiting)
+ // setTimeout(() => {}, 300);;
+ var body = previewresult;
+ var tail = [
+ '</body>',
+ '</html>'
+ ].join('\n');
+ return head + body + tail;
+ });
+ };
+ Object.defineProperty(MDDocumentContentProvider.prototype, "onDidChange", {
+ get: function () {
+ return this._onDidChange.event;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ MDDocumentContentProvider.prototype.update = function (uri) {
+ var _this = this;
+ if (!this._waiting) {
+ this._waiting = true;
+ setTimeout(function () {
+ _this._waiting = false;
+ _this._onDidChange.fire(uri);
+ }, 300);
+ }
+ };
+ return MDDocumentContentProvider;
+}());
//# sourceMappingURL=extension.js.map
\ No newline at end of file
diff --git a/out/src/extension.js.map b/out/src/extension.js.map
index f6a6aa7..cf85ff2 100644
--- a/out/src/extension.js.map
+++ b/out/src/extension.js.map
@@ -1 +1 @@
-{"version":3,"file":"extension.js","sourceRoot":"","sources":["../../src/extension.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,6DAA6D;AAC7D,8EAA8E;AAC9E,uBAA8G,QAAQ,CAAC,CAAA;AACvH,IAAY,aAAa,WAAM,eAAe,CAAC,CAAA;AAE/C,yDAAyD;AACzD,0EAA0E;AAC1E,kBAAyB,OAAyB;IAE9C,4FAA4F;IAC5F,gFAAgF;IAChF,OAAO,CAAC,GAAG,CAAC,iEAAiE,CAAC,CAAC;IAE/E,IAAI,OAAO,GAAG,IAAI,SAAS,EAAE,CAAC;IAE9B,wDAAwD;IACxD,sEAAsE;IACtE,uEAAuE;IACvE,IAAI,UAAU,GAAG,iBAAQ,CAAC,eAAe,CAAC,oBAAoB,EAAE;QAC5D,+EAA+E;QAE/E,OAAO,CAAC,QAAQ,EAAE,CAAC;QACnB,gCAAgC;QAChC,oCAAoC;QACpC,eAAM,CAAC,sBAAsB,CAAC,cAAc,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AAC3C,CAAC;AArBe,gBAAQ,W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C,CAAC;QACT,CAAC;IACF,CAAC;IACF,gCAAC;AAAD,CAAC,AA3GD,IA2GC"}
\ No newline at end of file
diff --git a/package.json b/package.json
index 79f28ef..5b3b38c 100644
--- a/package.json
+++ b/package.json
@@ -11,14 +11,21 @@
"Other"
],
"activationEvents": [
- "onCommand:extension.sayHello"
+ "onCommand:extension.sayHello",
+ "onCommand:extension.showpreview"
],
"main": "./out/src/extension",
"contributes": {
- "commands": [{
- "command": "extension.sayHello",
- "title": "Hello World"
- }]
+ "commands": [
+ {
+ "command": "extension.sayHello",
+ "title": "Hello World"
+ },
+ {
+ "command": "extension.showpreview",
+ "title": "show_preview"
+ }
+ ]
},
"scripts": {
"vscode:prepublish": "node ./node_modules/vscode/bin/compile",
diff --git a/src/extension.ts b/src/extension.ts
index 1ee0ae3..4a41840 100644
--- a/src/extension.ts
+++ b/src/extension.ts
@@ -1,9 +1,21 @@
'use strict';
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
-import {window, commands, Disposable, ExtensionContext, StatusBarAlignment, StatusBarItem, TextDocument} from 'vscode';
+import * as vscode from'vscode';
+import * as path from 'path';
+import {Extension,window, commands, Disposable, ExtensionContext, StatusBarAlignment, StatusBarItem, TextDocument ,TextDocumentContentProvider, EventEmitter, Event, Uri, ViewColumn} from 'vscode';
import * as child_process from 'child_process';
+
+interface IPackageInfo {
+ name: string;
+ version: string;
+ aiKey: string;
+}
+
+var previewresult = "";
+var Is_waiting = false;
+
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: ExtensionContext) {
@@ -12,21 +24,151 @@
// This line of code will only be executed once when your extension is activated
console.log('Congratulations, your extension "previewtest-ts" is now active!');
- var preview = new Mypreview();
+ let previewUri = Uri.parse('css-preview://authority/css-preview');
+
+ let packageInfo = getPackageInfo(context);
+ //telemetryReporter = packageInfo && new TelemetryReporter(packageInfo.name, packageInfo.version, packageInfo.aiKey);
+
+ let provider = new MDDocumentContentProvider(context);
+ let registration = vscode.workspace.registerTextDocumentContentProvider('markdown', provider);
+
+ //var preview = new Mypreview(context);
// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
let disposable = commands.registerCommand('extension.sayHello', () => {
// The code you place here will be executed every time your command is executed
-
- preview.sayHello();
+ //preview.sayHello();
//spawn.stdin.write("t-jipe\n");
// Display a message box to the user
window.showInformationMessage('Hello World!');
});
- context.subscriptions.push(disposable);
+ let d1 = commands.registerCommand('extension.showpreview',showPreview);
+
+ context.subscriptions.push(disposable , d1,registration);
+
+ vscode.workspace.onDidSaveTextDocument(document => {
+ if (isMarkdownFile(document)) {
+ const uri = getMarkdownUri(document.uri);
+ provider.update(uri);
+ }
+ });
+
+ vscode.workspace.onDidChangeTextDocument(event => {
+ if (isMarkdownFile(event.document)) {
+ const uri = getMarkdownUri(event.document.uri);
+ provider.update(uri);
+
+ }
+ });
+
+ vscode.workspace.onDidChangeConfiguration(() => {
+ vscode.workspace.textDocuments.forEach(document => {
+ if (document.uri.scheme === 'markdown') {
+ // update all generated md documents
+ provider.update(document.uri);
+ }
+ });
+ });
+}
+
+
+function isMarkdownFile(document: vscode.TextDocument) {
+ return document.languageId === 'markdown'
+ && document.uri.scheme !== 'markdown'; // prevent processing of own documents
+}
+
+function getMarkdownUri(uri: Uri) {
+ return uri.with({ scheme: 'markdown', path: uri.path + '.rendered', query: uri.toString() });
+}
+
+function showPreview(uri?: Uri, sideBySide: boolean = true) {
+
+ let resource = uri;
+ if (!(resource instanceof Uri)) {
+ if (vscode.window.activeTextEditor) {
+ // we are relaxed and don't check for markdown files
+ resource = vscode.window.activeTextEditor.document.uri;
+ }
+ }
+
+ if (!(resource instanceof Uri)) {
+ if (!vscode.window.activeTextEditor) {
+ // this is most likely toggling the preview
+ return vscode.commands.executeCommand('markdown.showSource');
+ }
+ // nothing found that could be shown or toggled
+ return;
+ }
+
+ let thenable = vscode.commands.executeCommand('vscode.previewHtml',
+ getMarkdownUri(resource),
+ getViewColumn(sideBySide),
+ `Preview '${path.basename(resource.fsPath)}'`);
+
+ /*telemetryReporter.sendTelemetryEvent('openPreview', {
+ where : sideBySide ? 'sideBySide' : 'inPlace',
+ how : (uri instanceof Uri) ? 'action' : 'pallete'
+ });
+*/
+ return thenable;
+}
+
+function getViewColumn(sideBySide): ViewColumn {
+ const active = vscode.window.activeTextEditor;
+ if (!active) {
+ return ViewColumn.One;
+ }
+
+ if (!sideBySide) {
+ return active.viewColumn;
+ }
+
+ switch (active.viewColumn) {
+ case ViewColumn.One:
+ return ViewColumn.Two;
+ case ViewColumn.Two:
+ return ViewColumn.Three;
+ }
+
+ return active.viewColumn;
+}
+
+function showSource(mdUri: Uri) {
+ if (!mdUri) {
+ return vscode.commands.executeCommand('workbench.action.navigateBack');
+ }
+
+ const docUri = Uri.parse(mdUri.query);
+
+ for (let editor of vscode.window.visibleTextEditors) {
+ if (editor.document.uri.toString() === docUri.toString()) {
+ return vscode.window.showTextDocument(editor.document, editor.viewColumn);
+ }
+ }
+
+ return vscode.workspace.openTextDocument(docUri).then(doc => {
+ return vscode.window.showTextDocument(doc);
+ });
+}
+
+function getPackageInfo(context: ExtensionContext): IPackageInfo {
+ let extensionPackage = require(context.asAbsolutePath('./package.json'));
+ if (extensionPackage) {
+ return {
+ name: extensionPackage.name,
+ version: extensionPackage.version,
+ aiKey: extensionPackage.aiKey
+ };
+ }
+ return null;
+}
+
+
+interface IRenderer {
+ render(text: string) : string;
}
// this method is called when your extension is deactivated
@@ -36,15 +178,17 @@
class Mypreview{
private _spawn : child_process.ChildProcess;
public _row_count : number;
- public _preview_result : string;
+ //public _preview_result : string;
- constructor(){
- this._spawn = child_process.spawn('E:\\Docfx\\test\\Dfm_test\\Dfm_test\\bin\\Debug\\Dfm_test.exe');
+ constructor(context : ExtensionContext){
+ let extpath = context.asAbsolutePath('./Dfm_test/Dfm_test/bin/Debug/Dfm_test.exe');
+ this._spawn = child_process.spawn(extpath);
//count = 0;
//this._preview_result = "";
this._spawn.stdout.on('data' , function(data){
- console.log("data " +'\n' + data);
+ console.log(data.toString());
+ previewresult = data.toString();
});
this._spawn.stderr.on('data' , function(data){
@@ -70,7 +214,115 @@
this._spawn.stdin.write(num_of_row + '\n');
this._spawn.stdin.write(docContent + '\n');
}
- }
+ }
+}
-
+
+class MDDocumentContentProvider implements TextDocumentContentProvider {
+ private _context: ExtensionContext;
+ private _onDidChange = new EventEmitter<Uri>();
+ private _waiting : boolean;
+ private _dfm_process : Mypreview;
+
+ constructor(context: ExtensionContext) {
+ this._context = context;
+ this._waiting = false;
+ this._dfm_process = new Mypreview(context);
+ }
+
+ private getMediaPath(mediaFile) : string {
+ return this._context.asAbsolutePath(path.join('media', mediaFile));
+ }
+
+/*
+ private isAbsolute(p) : boolean {
+ return path.normalize(p + '/') === path.normalize(path.resolve(p) + '/');
+ }
+
+ private fixHref(resource: Uri, href: string) : string {
+ if (href) {
+ // Use href if it is already an URL
+ if (Uri.parse(href).scheme) {
+ return href;
+ }
+
+ // Use href as file URI if it is absolute
+ if (this.isAbsolute(href)) {
+ return Uri.file(href).toString();
+ }
+
+ // use a workspace relative path if there is a workspace
+ let rootPath = vscode.workspace.rootPath;
+ if (rootPath) {
+ return Uri.file(path.join(rootPath, href)).toString();
+ }
+
+ // otherwise look relative to the markdown file
+ return Uri.file(path.join(path.dirname(resource.fsPath), href)).toString();
+ }
+ return href;
+ }
+
+
+ private computeCustomStyleSheetIncludes(uri: Uri): string[] {
+ const styles = vscode.workspace.getConfiguration('markdown')['styles'];
+ if (styles && Array.isArray(styles) && styles.length > 0) {
+ return styles.map((style) => {
+ return `<link rel="stylesheet" href="${this.fixHref(uri, style)}" type="text/css" media="screen">`;
+ });
+ }
+ return [];
+ }*/
+
+ public provideTextDocumentContent(uri: Uri): Thenable<string> {
+ this._dfm_process.sayHello();
+
+ return vscode.workspace.openTextDocument(Uri.parse(uri.query)).then(document => {
+ const head = [].concat(
+ '<!DOCTYPE html>',
+ '<html>',
+ '<head>',
+ '<meta http-equiv="Content-type" content="text/html;charset=UTF-8">',
+ `<link rel="stylesheet" type="text/css" href="${this.getMediaPath('markdown.css')}" >`,
+ `<link rel="stylesheet" type="text/css" href="${this.getMediaPath('tomorrow.css')}" >`,
+ //this.computeCustomStyleSheetIncludes(uri),
+ `<base href="${document.uri.toString(true)}">`,
+ '</head>',
+ '<body>'
+ ).join('\n');
+
+ //const body = this._renderer.render(document.getText());
+ /*const body = [
+ '<p> this is a paragraph</p>',
+ '<p> this is another paragraph</p>'
+ ].join('\n');*/
+ //this._dfm_process.sayHello();
+ // Is_waiting = true;
+
+ //while(Is_waiting)
+ // setTimeout(() => {}, 300);;
+ const body = previewresult;
+
+ const tail = [
+ '</body>',
+ '</html>'
+ ].join('\n');
+
+ return head + body + tail;
+ });
+ }
+
+ get onDidChange(): Event<Uri> {
+ return this._onDidChange.event;
+ }
+
+ public update(uri: Uri) {
+ if (!this._waiting) {
+ this._waiting = true;
+ setTimeout(() => {
+ this._waiting = false;
+ this._onDidChange.fire(uri);
+ }, 300);
+ }
+ }
}
\ No newline at end of file