Skip to content

Commit

Permalink
Merge pull request #46 from jhultgre/output-locally
Browse files Browse the repository at this point in the history
Output locally
  • Loading branch information
tbfisher authored Jan 16, 2017
2 parents 8008964 + 58bc31c commit 88480b8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
30 changes: 23 additions & 7 deletions Pandoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,32 @@ def run(self, edit, transformation):
args = args.remove(
short=['t', 'w'], long=['to', 'write'], values=['pdf'])

# output file locally
try:
transformation['out-local']
except:
argslocal = None
else:
argslocal = transformation['out-local']

# get current file path
current_file_path = self.view.file_name()
if current_file_path:
working_dir = os.path.dirname(current_file_path)
file_name = os.path.splitext(current_file_path)[0]
else:
working_dir = None
file_name = None

# if write to file, add -o if necessary, set file path to output_path
if oformat is not None and oformat in _s('pandoc-format-file'):
output_path = args.get(short=['o'], long=['output'])
if output_path is None:
# note the file extension matches the pandoc format name
output_path = tempfile.NamedTemporaryFile().name
if argslocal and file_name:
output_path = file_name
else:
output_path = tempfile.NamedTemporaryFile().name
# If a specific output format not specified in transformation, default to pandoc format name
if oext is None:
output_path += "." + oformat
Expand All @@ -143,11 +163,6 @@ def run(self, edit, transformation):
cmd.extend(args)

# run pandoc
current_file_path = self.view.file_name()
if current_file_path:
working_dir = os.path.dirname(current_file_path)
else:
working_dir = None
process = subprocess.Popen(
cmd, shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, cwd=working_dir)
Expand Down Expand Up @@ -186,7 +201,7 @@ def run(self, edit, transformation):
region = sublime.Region(0, view.size())
else:
view = self.view
view.replace(edit, region, result.decode('utf8').replace('\r\n','\n'))
view.replace(edit, region, result.decode('utf8').replace('\r\n', '\n'))
view.set_syntax_file(transformation['syntax_file'])


Expand Down Expand Up @@ -247,6 +262,7 @@ def _c(item):


class Args(list):

'''Process Pandoc arguments.
"short" are of the form "-k val""".
Expand Down
7 changes: 5 additions & 2 deletions Pandoc.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
"text.html": "html",
"text.html.markdown": "markdown"
},
// use to place the output in the same directory as the curent file
// if -o or --output are set in "pandoc-arguments" this is ignored
// "out-local": true,
"pandoc-arguments": [
"-t", "pdf"
// use --latex-engine=engine where engine is
Expand Down Expand Up @@ -95,7 +98,7 @@
"text.html.markdown": "markdown",
},
"pandoc-arguments": [
"-V", "geometry:margin=1.25in",
"-V", "geometry:margin=1.25in",
"-s", "--toc", "--number-sections", "--parse-raw",
"-t", "pdf",
],
Expand Down Expand Up @@ -147,7 +150,7 @@
"-t", "beamer",
]
},

"s5 Slides": {
"scope": {
"text.html": "html",
Expand Down

0 comments on commit 88480b8

Please sign in to comment.