Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Feature: Save HTML to file without copy & paste #62

Merged
merged 2 commits into from
Nov 11, 2018

Conversation

elviswolcott
Copy link
Contributor

When dealing with files with a lot of Latex copying the content and then pasting it into a new HTML file is can cause slow down while VS Code deals with the large file at first.
It also isn't an optimal workflow for dealing with multiple files or repeated editing because it requires a manual step each time you want to update it.

To address this I've added a new command that allows you to save the HTML directly to a file.
By default it saves in the same directory as .html instead of .md, but this is fully configurable.
There's also an option to enable auto save so that whenever you save changes to a markdown file the HTML file is created/updated.

A nice example of how this could be useful is setting the save path to /docs/${file.name}.html and enabling autosave.
For someone hosting their Markdown + Math documents in a GitHub repository enabling Pages would allow the automatic creation of files that can be viewed by anyone, anywhere with these settings.

I haven't updated the README beyond the new default values or updated the version so a maintainer can do it properly.

@elviswolcott
Copy link
Contributor Author

@goessner

@goessner
Copy link
Owner

Hello Elvis,

this is a really great enhancement. Sorry for the quite long delay with answering.

I am currently in a test phase with your code. It works like a charme, at least partly. Three points so far:

  1. Why not phrasing registerCommand('extension.saveToHtml', save) instead of registerCommand('extension.renderToHtml', save)
  2. I would prefer to lazy mkdirp = require('mkdirp').sync inside of save function, as I did in clip.
  3. I always get the error message: Activating extension goessner.mdmath failed: Illegal argument: base. It relates to the code new vscode.RelativePattern(vscode.workspace.rootPath, '**/*.md'), but I cannot locate some issues with vscode regarding this. Any ideas ? I am using windows 10 OS with the latest vscode version 1.28.2. When commenting out your last anonymous function (watcher) => { ... }, everything works.

But even without the 'autosave' functionality your new feature is a great improvement.

So I would investigate here a little further, update the README, accept your pull request and publish it with version 2.3.5.

Thanks

@goessner
Copy link
Owner

goessner commented Nov 11, 2018

I obviously resolved the 'autosave' issue. After changing

new vscode.RelativePattern(vscode.workspace.rootPath, '**/*.md')

in line 97 of your extension.js to

new vscode.RelativePattern(path.dirname(vscode.window.activeTextEditor.document.uri.fsPath), '**/*.md')

it works really great. I am not sure, what was wrong here exactly. But it does not relate to the fact, that vscode.workspace.rootPath is deprecated now. Do you see any problems with that solution ?

In fact this is a feature, where even markdown users with no need of math formulas might be interested in.

Thanks again.

@goessner goessner merged commit e9edd46 into goessner:master Nov 11, 2018
@elviswolcott
Copy link
Contributor Author

No worries on the delay.
I did not realize that vscode.workspace.rootPath was depreciated, that is a great solution.
Unless I am mistaken it does not look like you made those changes to branch before merging. Should I apply them and create a new PR?

@goessner
Copy link
Owner

I already did that locally and also would like to add TeX macros. So wait and see.

@elviswolcott
Copy link
Contributor Author

Okay, sounds good.

@goessner
Copy link
Owner

@elviswolcott: In some cases the error message: Activating extension goessner.mdmath failed: Illegal argument came up again. The reason obviously was, that vscode.window.activeTextEditor.document was not defined at that runtime.

So I switched to a lazy activation of the fileSystemWatcher inside of save function. The error should be gone now.

Please have a critical look at the code now. Thanks.

@elviswolcott
Copy link
Contributor Author

I have some notes to type up tonight so I'll pull down those changes and see how they work for me.
Looking at the diffs it seems good.

@elviswolcott
Copy link
Contributor Author

@goessner I tested it out and everything worked. No errors in the terminal. Seems good to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants