From e1c3fbe7c0947bf0fa7b9c126c116ac1c0526e80 Mon Sep 17 00:00:00 2001 From: Geoffrey Poore Date: Sun, 3 May 2020 11:59:33 -0500 Subject: [PATCH] fixed Pandoc 2.8+ compatibility by using -raw_attribute in intermediate Markdown (closes #26) --- .gitignore | 3 +++ CHANGELOG.md | 13 +++++++++++++ codebraid/converters/pandoc.py | 24 +++++++++++++++--------- codebraid/version.py | 2 +- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index fdc1eef..6ce874f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ # codebraid _dev_research/ +*/_codebraid +examples/*.jpg +examples/*.png *.ffs_db # Byte-compiled / optimized / DLL files diff --git a/CHANGELOG.md b/CHANGELOG.md index 149ba6e..2b28500 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # Change Log +## v0.5.0 (2020-05-??) + +* Fixed Pandoc 2.8+ compatibility by using `-raw_attribute` in intermediate + Markdown. Code output in raw format (interpreted as Markdown) is no longer + lost when converting to document formats other than Markdown (#26). +* Added support for SageMath (#5). +* Documentation now includes details of code execution and how this can result + in different output compared to interactive sessions (#11). +* AST walking code no longer assumes that all dict nodes represent types and + have a "t" (type) key. Dict nodes without a "t" key are now skipped. This + fixes a bug with citations of the form `[@cite]` (#12). + + ## v0.4.0 (2019-07-10) * Added support for Jupyter kernels with the `jupyter_kernel` option, which diff --git a/codebraid/converters/pandoc.py b/codebraid/converters/pandoc.py index 981cd55..03a0e31 100644 --- a/codebraid/converters/pandoc.py +++ b/codebraid/converters/pandoc.py @@ -888,10 +888,13 @@ def _load_and_process_initial_ast(self, *, # such as might occur in an incomplete bullet list, are difficult to # deal with. - # Convert source string to trace plus AST with Pandoc - from_format_pandoc_extensions = self.from_format_pandoc_extensions or '' - if self.from_format == 'markdown': - from_format_pandoc_extensions += '-latex_macros-smart' + # Convert source string to trace plus AST with Pandoc. + # Order of extensions is important: earlier override later. + from_format_pandoc_extensions = ''.join(['-latex_macros', + '-smart']) + if self.from_format_pandoc_extensions is not None: + from_format_pandoc_extensions += self.from_format_pandoc_extensions + stdout_bytes, stderr_bytes = self._run_pandoc(input=source_string, input_name=single_source_name, from_format=self.from_format, @@ -909,9 +912,7 @@ def _load_and_process_initial_ast(self, *, if not (isinstance(ast, dict) and 'pandoc-api-version' in ast and isinstance(ast['pandoc-api-version'], list) and all(isinstance(x, int) for x in ast['pandoc-api-version']) and 'blocks' in ast): - raise PandocError('Incompatible Pandoc API version') - if ast['pandoc-api-version'][0:2] != [1, 17]: - warnings.warn('Pandoc API is {0}.{1}, but Codebraid is designed for 1.17; this might cause issues'.format(*ast['pandoc-api-version'][0:2])) + raise PandocError('Unrecognized AST format (incompatible Pandoc version?)') self._asts[single_source_name] = ast source_string_lines = util.splitlines_lf(source_string) or [''] @@ -1171,8 +1172,13 @@ def _postprocess_code_chunks(self): node['c'].insert(0, io_map_span_node(source_name, line_number)) # Convert modified AST to markdown, then back, so that raw output - # can be reinterpreted as markdown - processed_to_format_extensions = self.from_format_pandoc_extensions or '' + '-latex_macros-smart' + # can be reinterpreted as markdown. + # Order of extensions is important: earlier override later. + processed_to_format_extensions = ''.join(['-latex_macros', + '-raw_attribute', + '-smart']) + if self.from_format_pandoc_extensions is not None: + processed_to_format_extensions += self.from_format_pandoc_extensions processed_markup = collections.OrderedDict() for source_name, ast in self._asts.items(): markup_bytes, stderr_bytes = self._run_pandoc(input=json.dumps(ast), diff --git a/codebraid/version.py b/codebraid/version.py index dba3c66..d9bd57d 100644 --- a/codebraid/version.py +++ b/codebraid/version.py @@ -1,4 +1,4 @@ # -*- coding: utf-8 -*- from .fmtversion import get_version_plus_info -__version__, __version_info__ = get_version_plus_info(0, 5, 0, 'dev', 1) +__version__, __version_info__ = get_version_plus_info(0, 5, 0, 'dev', 2)