Skip to content

Commit

Permalink
Implement utput.text.addFormat option.
Browse files Browse the repository at this point in the history
  • Loading branch information
niszet committed May 1, 2020
1 parent 61ac34d commit 1a96869
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 42 deletions.
48 changes: 16 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,46 +21,24 @@ You must install Pandoc executable. If you can run Pandoc as `pandoc` in command
Following options are implemented preliminary.

- `Pandoc.path`
- You can specify path to Pandoc executable. Default is "pandoc".
- `Pandoc.args`
- You can add arguments for Pandoc. See [Options](https://pandoc.org/MANUAL.html#options) section in the manual of Pandoc for detail.
- `Pandoc.extension`
- You can add extensions for Pandoc. See [Extensions](https://pandoc.org/MANUAL.html#extensions) section in the manual of Pandoc for detail.
- `Pandoc.workdir`
- Running directory of pandoc. Default is current directory. Selected text range or code block is written to temp file when you exec pandoc. This temp file location and its filename cannot be changed.
- `input.from`
- You can set input file format (This value is used with `--from` option.). To know available file format, see [General options](https://pandoc.org/MANUAL.html#general-options) section in the manual of Pandoc for detail.
- `output.to`
- You can set output file format (This value is used with `--to` option.). To know available file format, see [General options](https://pandoc.org/MANUAL.html#general-options) section in the manual of Pandoc for detail.
- `output.text.Add`
- You can add output result at the next line of mouse cursor or after code block.
- `output.text.addFormat`
- You can add output file format which specifed by `output.to` to the output result.
- `output.pane`
- You can select to output to OUTPUT pane or not.

### Pandoc.path

You can specify path to Pandoc executable. Default is "pandoc".

### Pandoc.args

You can add arguments for Pandoc. See [Options](https://pandoc.org/MANUAL.html#options) section in the manual of Pandoc for detail.

### Pandoc.extension

You can add extensions for Pandoc. See [Extensions](https://pandoc.org/MANUAL.html#extensions) section in the manual of Pandoc for detail.

### Pandoc.workdir

Running directory of pandoc. Default is current directory. Selected text range or code block is written to temp file when you exec pandoc. This temp file location and its filename cannot be changed.

### input.from

You can set input file format (This value is used with `--from` option.). To know available file format, see [General options](https://pandoc.org/MANUAL.html#general-options) section in the manual of Pandoc for detail.


### `output.to`

You can set output file format (This value is used with `--to` option.). To know available file format, see [General options](https://pandoc.org/MANUAL.html#general-options) section in the manual of Pandoc for detail.

### output.text.Add

You can add output result at the next line of mouse cursor or after code block.

### output.pane

You can select to output to OUTPUT pane or not.

## Known Issues

Expand All @@ -74,6 +52,12 @@ If you have any issues, please use issue of this repository.

## Release Notes

### 0.0.3

* Delete Replace function (Not implemented yet)
* Implement `output.text.addFormat` to add output format.
* Update README.

### 0.0.2

Add screen shot to use this extension (Run Pandoc Selection Range).
Expand Down
7 changes: 1 addition & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,10 @@
"default": false,
"description": "Pandoc's output will be added after cursor."
},
"Pandocplay.output.text.Replace": {
"type": "boolean",
"default": false,
"markdownDescription": "TODO: Only for Selection. **If true, selections will be deleted.**"
},
"Pandocplay.output.text.addFormat": {
"type": "boolean",
"default": false,
"markdownDescription": "TODO: Add format name at code block"
"markdownDescription": "Add specified format name to output code block"
},
"Pandocplay.output.file.enable": {
"type": "boolean",
Expand Down
25 changes: 21 additions & 4 deletions src/pandocplay/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,17 @@ export class Pandocplay {
const pandoc_output = this.runCode(code, cwd, from, to, ext, args, path, pane_enable);
//vscode.window.showInformationMessage(cwd);

// TODO: add or replace texts
// Replace can be done by delete after adding outputs. So, It should NOT be implemented.
const output_add = this.getOutputAdd(conf);

const output_add_format = this.getOutputAddFormat(conf);

if(output_add){
this.appendResult(editor, line, pandoc_output)
let local_to = "";
if (output_add_format){
local_to = to;
}
this.appendResult(editor, line, pandoc_output, local_to)
}

// TBD
Expand All @@ -104,7 +111,8 @@ export class Pandocplay {
private appendResult = (
editor: vscode.TextEditor,
targetLine: number,
text: string
text: string,
to: string
) => {

let eol: string;
Expand All @@ -114,7 +122,7 @@ export class Pandocplay {
default:
eol = "\n";
}
const outputText = "```" + eol + text + eol + "```" + eol;
const outputText = "```" + to + eol + text + eol + "```" + eol;
editor.edit(edit => {
edit.insert(new vscode.Position(targetLine, 0), outputText);
});
Expand Down Expand Up @@ -222,6 +230,15 @@ private getOutputAdd = (conf: vscode.WorkspaceConfiguration): boolean => {
}
};

private getOutputAddFormat = (conf: vscode.WorkspaceConfiguration): boolean => {
const output_addFormat = conf.get("output.text.addFormat");
if(output_addFormat){
return true;
} else {
return false;
}
};

private getOutputPane = (conf: vscode.WorkspaceConfiguration, to: string): boolean => {
//TODO: check with --to file type?
const bin_list = ["docx", "pdf", "odt", "opendocument", "epub", "epub2", "epub3"];
Expand Down

0 comments on commit 1a96869

Please sign in to comment.