Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
{
"command": "codetohtml.run",
"title": "[CodeToHTML] Code to HTML"
},
{
"command": "codetohtml.runSelectionOnly",
"title": "[CodeToHTML] Code to HTML - Selection only"
}
]
},
Expand Down
20 changes: 16 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,17 @@ export function activate(context: vscode.ExtensionContext) {
if (!activeEditor) {
return;
}
const highlightHtml = await getHTML(context);
const highlightHtml = await getHTML(context, true);
await createWebview(context, highlightHtml);
}));

// Version of the command that only copies the current selection
context.subscriptions.push(vscode.commands.registerCommand('codetohtml.runSelectionOnly', async () => {
const activeEditor = vscode.window.activeTextEditor;
if (!activeEditor) {
return;
}
const highlightHtml = await getHTML(context, false);
await createWebview(context, highlightHtml);
}));
}
Expand Down Expand Up @@ -40,14 +50,16 @@ function htmlPathToUri(context: vscode.ExtensionContext, webview: vscode.Webview


// Webviewを使ってハイライトされたHTMLを取得
async function getHTML(context: vscode.ExtensionContext) {
async function getHTML(context: vscode.ExtensionContext, wholeFile: boolean): Promise<string> {
// クリップボードのデータを変更するため、古いデータを一時的に保存
const clipboardText = await vscode.env.clipboard.readText();
vscode.commands.executeCommand('editor.action.selectAll');
if (wholeFile) {
vscode.commands.executeCommand('editor.action.selectAll');
}
vscode.commands.executeCommand('editor.action.clipboardCopyWithSyntaxHighlightingAction');
vscode.commands.executeCommand('cancelSelection');

const webview = vscode.window.createWebviewPanel('codetohtml', 'Code to HTML', vscode.ViewColumn.One, {
const webview = vscode.window.createWebviewPanel('codetohtml', 'Code to HTML', vscode.ViewColumn.One, {
enableScripts: true
});

Expand Down