def __call__(self, args, should_open): # build arguments to pass pandoc buffer_bibliographies = vim.eval('b:pandoc_biblio_bibs') if len(buffer_bibliographies) < 1: buffer_bibliographies = find_bibfiles() bib_arg = " ".join(['--bibliography "' + i + '"' for i in buffer_bibliographies]) if \ len(buffer_bibliographies) > 0 \ else "" strict_arg = "-r markdown_strict" if \ vim.current.buffer.options["ft"] == "markdown" and \ not bool(vim.vars["pandoc#filetypes#pandoc_markdown"]) \ else "" c_opts, c_args = getopt.gnu_getopt(shlex.split(args), self.opts.shortopts, self.opts.longopts) def wrap_args(i): if re.search('=', i[1]): return (i[0], re.sub('$', '"', re.sub('(.*)=', '\\1="', i[1]))) else: return (i[0], i[1]) c_opts = [wrap_args(i) for i in c_opts] output_format = c_args.pop(0) if len(c_args) > 0 and c_args[0] in PandocHelpParser.get_output_formats_table().keys() else "html" output_format_arg = "-t " + output_format if output_format != "pdf" else "" self._output_file_path = vim.eval('expand("%:r")') + '.' + PandocHelpParser.get_output_formats_table()[output_format] output_arg = '-o "' + self._output_file_path + '"' engine_arg = "--latex-engine=" + vim.vars["pandoc#command#latex_engine"] if output_format in ["pdf", "beamer"] else "" extra = [] for opt in c_opts: eq = '=' if opt[1] and re.match('^--', opt[0]) else '' # if it begins with ~, it will expand, otherwise, it will just copy val = os.path.expanduser(opt[1]) if os.path.isabs(val) and os.path.exists(val): extra.append(opt[0] + (eq or ' ') + '"' + val + '"') else: extra.append(opt[0] + eq + opt[1]) extra_args = " ".join(extra) extra_input_args = '"' + '" "'.join(c_args) + '"' if len(c_args) > 0 else "" input_arg = '"' + vim.eval('expand("%")') + '"' self._run_command = " ".join(filter(lambda i: i != "", ["pandoc", \ bib_arg, \ strict_arg, \ output_format_arg, \ engine_arg, \ output_arg, \ extra_args, \ extra_input_args, \ input_arg])) # execute self.execute(should_open)
def __call__(self, args, should_open): # build arguments to pass pandoc buffer_bibliographies = vim.eval('b:pandoc_biblio_bibs') if len(buffer_bibliographies) < 1: buffer_bibliographies = find_bibfiles() bib_arg = " ".join(['--bibliography "' + i + '"' for i in buffer_bibliographies]) if \ len(buffer_bibliographies) > 0 \ else "" strict_arg = "-r markdown_strict" if \ vim.current.buffer.options["ft"] == "markdown" and \ not bool(vim.vars["pandoc#filetypes#pandoc_markdown"]) \ else "" c_opts, c_args = getopt.gnu_getopt(shlex.split(args), self.opts.shortopts, self.opts.longopts) def wrap_args(i): if re.search('=', i[1]): return (i[0], re.sub('$', '"', re.sub('(.*)=', '\\1="', i[1]))) else: return (i[0], i[1]) c_opts = [wrap_args(i) for i in c_opts] output_format = c_args.pop(0) if len(c_args) > 0 and c_args[0] in PandocHelpParser.get_output_formats_table().keys() else "html" output_format_arg = "-t " + output_format if output_format != "pdf" else "" self._output_file_path = vim.eval('expand("%:r")') + '.' + PandocHelpParser.get_output_formats_table()[output_format] output_arg = '-o "' + self._output_file_path + '"' engine_arg = "--latex-engine=" + vim.vars["pandoc#command#latex_engine"] if output_format in ["pdf", "beamer"] else "" extra = [] for opt in c_opts: eq = '=' if opt[1] and re.match('^--', opt[0]) else '' # if it begins with ~, it will expand, otherwise, it will just copy val = os.path.expanduser(opt[1]) if os.path.isabs(val) and os.path.exists(val): extra.append(opt[0] + (eq or ' ') + '"' + val + '"') else: extra.append(opt[0] + eq + opt[1]) extra_args = " ".join(extra) extra_input_args = '"' + '" "'.join(c_args) + '"' if len(c_args) > 0 else "" input_arg = '"' + vim.eval('expand("%")') + '"' self._run_command = " ".join(filter(lambda i: i != "", ["pandoc", \ bib_arg, \ strict_arg, \ output_format_arg, \ engine_arg, \ output_arg, \ extra_args, \ extra_input_args, \ input_arg])) # execute self.execute(should_open)
def __call__(self, args, should_open): # build arguments to pass pandoc if "bibliographies" in plugin_enabled_modules(): buffer_bibliographies = vim.eval("b:pandoc_biblio_bibs") if len(buffer_bibliographies) < 1: buffer_bibliographies = find_bibfiles() bib_arg = ( " ".join(['--bibliography "' + i + '"' for i in buffer_bibliographies]) if len(buffer_bibliographies) > 0 else "" ) else: bib_arg = "" strict_arg = ( "-r markdown_strict" if vim.current.buffer.options["ft"] == "markdown" and not bool(vim.vars["pandoc#filetypes#pandoc_markdown"]) else "" ) c_opts, c_args = getopt.gnu_getopt(shlex.split(args), self.opts.shortopts, self.opts.longopts) def wrap_args(i): if re.search("=", i[1]): return (i[0], re.sub("$", '"', re.sub("(.*)=", '\\1="', i[1]))) else: return (i[0], i[1]) c_opts = [wrap_args(i) for i in c_opts] output_format = c_args.pop(0) if len(c_args) > 0 and self.opts.in_allowed_formats(c_args[0]) else "html" output_format_arg = "-t " + output_format if output_format != "pdf" else "" def no_extensions(fmt): return re.split("[-+]", fmt)[0] self._output_file_path = ( vim.eval('expand("%:r")') + "." + self.opts.get_output_formats_table()[no_extensions(output_format)] ) output_arg = '-o "' + self._output_file_path + '"' engine_arg = ( "--latex-engine=" + vim.vars["pandoc#command#latex_engine"] if output_format in ["pdf", "beamer"] else "" ) extra = [] for opt in c_opts: eq = "=" if opt[1] and re.match("^--", opt[0]) else "" # if it begins with ~, it will expand, otherwise, it will just copy val = os.path.expanduser(opt[1]) if os.path.isabs(val) and os.path.exists(val): extra.append(opt[0] + (eq or " ") + '"' + val + '"') else: extra.append(opt[0] + eq + opt[1]) extra_args = " ".join(extra) extra_input_args = '"' + '" "'.join(c_args) + '"' if len(c_args) > 0 else "" input_arg = '"' + vim.eval('expand("%")') + '"' self._run_command = " ".join( filter( lambda i: i != "", [ "pandoc", bib_arg, strict_arg, output_format_arg, engine_arg, output_arg, extra_args, extra_input_args, input_arg, ], ) ) # execute self.execute(should_open)
def __call__(self, args, should_open): # build arguments to pass pandoc if 'bibliographies' in plugin_enabled_modules(): buffer_bibliographies = vim.eval('b:pandoc_biblio_bibs') if len(buffer_bibliographies) < 1: buffer_bibliographies = find_bibfiles() bib_arg = " ".join(['--bibliography "' + i + '"' \ for i in buffer_bibliographies]) \ if len(buffer_bibliographies) > 0 \ else "" else: bib_arg = "" strict_arg = "-r markdown_strict" if \ vim.current.buffer.options["ft"] == "markdown" and \ not bool(vim.vars["pandoc#filetypes#pandoc_markdown"]) \ else "" if re.search('--mathjax( |$)', args): args = re.sub('--mathjax', '', args) extra_mathjax = True else: extra_mathjax = False c_opts, c_args = getopt.gnu_getopt(shlex.split(args), self.opts.shortopts, self.opts.longopts) def wrap_args(i): if re.search('=', i[1]): return (i[0], re.sub('$', '"', re.sub('(.*)=', '\\1="', i[1]))) else: return (i[0], i[1]) c_opts = [wrap_args(i) for i in c_opts] output_format = c_args.pop(0) \ if len(c_args) > 0 \ and self.opts.in_allowed_formats(c_args[0]) \ else "html" output_format_arg = "-t " + output_format if output_format != "pdf" \ else "" def no_ext(fmt): return re.split("[-+]", fmt)[0] self._output_file_path = vim.eval('expand("%:r")') + '.' \ + self.opts.get_output_formats_table()[no_ext(output_format)] output_arg = '-o "' + self._output_file_path + '"' try: # try a buffer local engine engine_var = vim.current.buffer.vars['pandoc_command_latex_engine'] except: engine_var = vim.vars['pandoc#command#latex_engine'] # vim's python3's .vars are bytes, unlike in neovim if type(engine_var) == bytes: engine_var = '"' + engine_var.decode() + '"' engine_arg = "--latex-engine=" + str(engine_var) \ if output_format in ["pdf", "beamer"] \ else "" extra = [] for opt in c_opts: eq = '=' if opt[1] and re.match('^--', opt[0]) else '' if opt[0] in ("-V", "--variable") and "=" in opt[1]: # we have -V var=thing # Should also apply logic below regarding paths var, _, arg = opt[1].partition("=") # Coerse opt such that the below works on the true value, i.e. # the value of the variable being set. opt = ("-V " + var, arg.strip('"')) eq = "=" # if it begins with ~, it will expand, otherwise, it will just copy val = os.path.expanduser(opt[1]) extra.append(opt[0] + (eq or ' ') + (('"' + val + '"') if len(val) else '')) if extra_mathjax: extra.append('--mathjax') extra_args = " ".join(extra) extra_input_args = '"' + '" "'.join(c_args) + '"' if len(c_args) > 0 \ else "" input_arg = '"' + vim.eval('expand("%")') + '"' arglist = ["pandoc", \ bib_arg, \ strict_arg, \ output_format_arg, \ engine_arg, \ output_arg, \ extra_args, \ extra_input_args, \ input_arg] self._run_command = " ".join(filter(lambda i: len(i) > 0, arglist)) # execute self.execute(should_open)
def __call__(self, args, should_open): largs = shlex.split(args) if largs == [] or largs[0].startswith('-'): largs = ['html'] + largs # make sure we pass an output format p = self.pandoc_info.build_argument_parser() c_vars = vars(p.parse_args(largs)) # Infer arguments from vim environment # a) bibliographies if 'bibliographies' in plugin_enabled_modules(): local_bibs = vim.eval('b:pandoc_biblio_bibs') found_bibs = find_bibfiles() if local_bibs or found_bibs and not c_vars['bibliography']: c_vars['bibliography'] = [] if local_bibs: c_vars['bibliography'].extend(local_bibs) if found_bibs: c_vars['bibliography'].extend(found_bibs) # Now, we must determine what are our input and output files # a) First, let's see what is the desired output format... output_format = c_vars['output_format'] \ if self.pandoc_info.is_valid_output_format(c_vars['output_format']) \ or c_vars['output_format'] == 'pdf' \ else "html" # overwrite --to with this value # 'pdf' is not a valid output format, we pass it to -o instead) if output_format != 'pdf': c_vars['to'] = output_format else: c_vars['to'] = 'latex' if output_format == 'pdf': # pdf engine if self.pandoc_info.version >= '2': engine_option = 'pdf_engine' else: engine_option = 'latex_engine' if not c_vars[engine_option]: try: # try a buffer local engine engine_var = ensure_string( vim.current.buffer.vars['pandoc_command_latex_engine']) except: # use te global value engine_var = ensure_string( vim.vars['pandoc#command#latex_engine']) c_vars[engine_option] = str(engine_var) if not c_vars['output']: self._output_file_path = vim.eval('expand("%:r")') + '.' \ + self.formats_table[re.split("[-+]", output_format)[0]] c_vars['output'] = self._output_file_path else: self._output_file_path = os.path.expanduser(c_vars['output'][0]) input_arg = '"' + vim.eval('expand("%")') + '"' # Now, we reconstruct the pandoc call arglist = [] arglist.append(ensure_string(vim.vars['pandoc#compiler#command'])) arglist.append(ensure_string(vim.vars['pandoc#compiler#arguments'])) # Only consider enabled flags and arguments with values extra_arg_vars_keys = [ k for k in c_vars.keys() if c_vars[k] and k != 'output_format' ] for var in extra_arg_vars_keys: real_var = var.replace("_", "-") val = c_vars[var] if type(val ) == list and len(val) > 1: # multiple values, repeat keys for vv in val: if type(vv) == list and type(vv[0]) == list: vv = vv[0][0] elif type(vv) == list: vv = vv[0] elif type(val) == bool: vv = None if vv: vv = os.path.expanduser(vv) arglist.append("--" + real_var + '="' + str(vv) + '"') else: arglist.append("--" + real_var) else: if type(val) == list and type(val[0]) == list: val = val[0][0] elif type(val) == list: val = val[0] elif type(val) == bool: val = None if val: val = os.path.expanduser(val) arglist.append('--' + real_var + '="' + str(val) + '"') else: arglist.append('--' + real_var) arglist.append(input_arg) self._run_command = " ".join(arglist) # execute self.execute(should_open)
def __call__(self, args, should_open): largs = shlex.split(args) if largs == [] or largs[0].startswith('-'): largs = ['html'] + largs # make sure we pass an output format p = self.pandoc_info.build_argument_parser() c_vars = vars(p.parse_args(largs)) # Infer arguments from vim environment # a) bibliographies if 'bibliographies' in plugin_enabled_modules(): local_bibs = vim.eval('b:pandoc_biblio_bibs') found_bibs = find_bibfiles() if local_bibs or found_bibs and not c_vars['bibliography']: c_vars['bibliography'] = [] if local_bibs: c_vars['bibliography'].extend(local_bibs) if found_bibs: c_vars['bibliography'].extend(found_bibs) # Now, we must determine what are our input and output files # a) First, let's see what is the desired output format... output_format = c_vars['output_format'] \ if self.pandoc_info.is_valid_output_format(c_vars['output_format']) \ or c_vars['output_format'] == 'pdf' \ else "html" # overwrite --to with this value # 'pdf' is not a valid output format, we pass it to -o instead) if output_format != 'pdf': c_vars['to'] = output_format else: c_vars['to'] = 'latex' if output_format == 'pdf': # pdf engine if self.pandoc_info.version >= '2': engine_option = 'pdf_engine' else: engine_option = 'latex_engine' if not c_vars[engine_option]: try: # try a buffer local engine engine_var = ensure_string(vim.current.buffer.vars['pandoc_command_latex_engine']) except: # use te global value engine_var = ensure_string(vim.vars['pandoc#command#latex_engine']) c_vars[engine_option] = str(engine_var) if not c_vars['output']: self._output_file_path = vim.eval('expand("%:r")') + '.' \ + self.formats_table[re.split("[-+]", output_format)[0]] c_vars['output'] = self._output_file_path else: self._output_file_path = os.path.expanduser(c_vars['output'][0]) input_arg = '"' + vim.eval('expand("%")') + '"' # Now, we reconstruct the pandoc call arglist = [] arglist.append(ensure_string(vim.vars['pandoc#compiler#command'])) arglist.append(ensure_string(vim.vars['pandoc#compiler#arguments'])) # Only consider enabled flags and arguments with values extra_arg_vars_keys = [k for k in c_vars.keys() if c_vars[k] and k != 'output_format'] for var in extra_arg_vars_keys: real_var = var.replace("_", "-") val = c_vars[var] if type(val) == list and len(val) > 1: # multiple values, repeat keys for vv in val: if type(vv) == list and type(vv[0]) == list: vv = vv[0][0] elif type(vv) == list: vv = vv[0] elif type(val) == bool: vv = None if vv: vv = os.path.expanduser(vv) arglist.append("--" + real_var + '="' + str(vv) + '"') else: arglist.append("--" + real_var) else: if type(val) == list and type(val[0]) == list: val = val[0][0] elif type(val) == list: val = val[0] elif type(val) == bool: val = None if val: val = os.path.expanduser(val) arglist.append('--' + real_var + '="' + str(val) + '"') else: arglist.append('--' + real_var) arglist.append(input_arg) self._run_command = " ".join(arglist) # execute self.execute(should_open)
def __call__(self, args, should_open): # build arguments to pass pandoc if 'bibliographies' in plugin_enabled_modules(): buffer_bibliographies = vim.eval('b:pandoc_biblio_bibs') if len(buffer_bibliographies) < 1: buffer_bibliographies = find_bibfiles() bib_arg = " ".join(['--bibliography "' + i + '"' \ for i in buffer_bibliographies]) \ if len(buffer_bibliographies) > 0 \ else "" else: bib_arg = "" strict_arg = "-r markdown_strict" if \ vim.current.buffer.options["ft"] == "markdown" and \ not bool(vim.vars["pandoc#filetypes#pandoc_markdown"]) \ else "" c_opts, c_args = getopt.gnu_getopt(shlex.split(args), self.opts.shortopts, self.opts.longopts) def wrap_args(i): if re.search('=', i[1]): return (i[0], re.sub('$', '"', re.sub('(.*)=', '\\1="', i[1]))) else: return (i[0], i[1]) c_opts = [wrap_args(i) for i in c_opts] output_format = c_args.pop(0) \ if len(c_args) > 0 \ and self.opts.in_allowed_formats(c_args[0]) \ else "html" output_format_arg = "-t " + output_format if output_format != "pdf" else "" def no_extensions(fmt): return re.split("[-+]", fmt)[0] self._output_file_path = vim.eval('expand("%:r")') + \ '.' + self.opts.get_output_formats_table()[no_extensions(output_format)] output_arg = '-o "' + self._output_file_path + '"' try: # try a buffer local engine engine_var = vim.current.buffer.vars['pandoc_command_latex_engine'] except: engine_var = vim.vars['pandoc#command#latex_engine'] # vim's python3's .vars are bytes, unlike in neovim if type(engine_var) == bytes: engine_var = '"' + engine_var.decode() + '"' engine_arg = "--latex-engine=" + str(engine_var) \ if output_format in ["pdf", "beamer"] \ else "" extra = [] for opt in c_opts: eq = '=' if opt[1] and re.match('^--', opt[0]) else '' # if it begins with ~, it will expand, otherwise, it will just copy val = os.path.expanduser(opt[1]) if os.path.isabs(val) and os.path.exists(val): extra.append(opt[0] + (eq or ' ') + '"' + val + '"') else: extra.append(opt[0] + eq + opt[1]) extra_args = " ".join(extra) extra_input_args = '"' + '" "'.join(c_args) + '"' if len( c_args) > 0 else "" input_arg = '"' + vim.eval('expand("%")') + '"' arglist = ["pandoc", \ bib_arg, \ strict_arg, \ output_format_arg, \ engine_arg, \ output_arg, \ extra_args, \ extra_input_args, \ input_arg] self._run_command = " ".join(filter(lambda i: len(i) > 0, arglist)) # execute self.execute(should_open)