Skip to content

Commit

Permalink
fixed Pandoc 2.8+ compatibility by using -raw_attribute in intermedia…
Browse files Browse the repository at this point in the history
…te Markdown (closes #26)
  • Loading branch information
gpoore committed May 3, 2020
1 parent 565bff0 commit e1c3fbe
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# codebraid
_dev_research/
*/_codebraid
examples/*.jpg
examples/*.png
*.ffs_db

# Byte-compiled / optimized / DLL files
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
24 changes: 15 additions & 9 deletions codebraid/converters/pandoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 ['']
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion codebraid/version.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit e1c3fbe

Please sign in to comment.