Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codebraid breaks on pandoc citations. #12

Closed
Synthetica9 opened this issue Dec 11, 2019 · 3 comments
Closed

Codebraid breaks on pandoc citations. #12

Synthetica9 opened this issue Dec 11, 2019 · 3 comments
Labels
bug Something isn't working

Comments

@Synthetica9
Copy link

Minimal example:

[@test]

Fails with:

$ codebraid pandoc /tmp/test.md 
Traceback (most recent call last):
  File "/nix/store/n1nd5j5m583llfbbmqm379kmg98335zg-codebraid-0.4.0/bin/.codebraid-wrapped", line 9, in <module>
    sys.exit(main())
  File "/nix/store/n1nd5j5m583llfbbmqm379kmg98335zg-codebraid-0.4.0/lib/python3.7/site-packages/codebraid/cmdline.py", line 62, in main
    args.func(args)
  File "/nix/store/n1nd5j5m583llfbbmqm379kmg98335zg-codebraid-0.4.0/lib/python3.7/site-packages/codebraid/cmdline.py", line 85, in pandoc
    converter.code_braid()
  File "/nix/store/n1nd5j5m583llfbbmqm379kmg98335zg-codebraid-0.4.0/lib/python3.7/site-packages/codebraid/converters/base.py", line 1161, in code_braid
    self._extract_code_chunks()
  File "/nix/store/n1nd5j5m583llfbbmqm379kmg98335zg-codebraid-0.4.0/lib/python3.7/site-packages/codebraid/converters/pandoc.py", line 1146, in _extract_code_chunks
    self._load_and_process_initial_ast(source_string=source_string, single_source_name=source_name)
  File "/nix/store/n1nd5j5m583llfbbmqm379kmg98335zg-codebraid-0.4.0/lib/python3.7/site-packages/codebraid/converters/pandoc.py", line 1007, in _load_and_process_initial_ast
    node_type = node['t']
KeyError: 't'
@Synthetica9
Copy link
Author

I did some experimentation, using .get('t') in a few places seems to fix everything.

So:

diff --git a/codebraid/converters/pandoc.py b/codebraid/converters/pandoc.py
index 132a5f2..e03537c 100644
--- a/codebraid/converters/pandoc.py
+++ b/codebraid/converters/pandoc.py
@@ -510,7 +510,7 @@ def _get_walk_less_note_contents_closure(enumerate=enumerate, isinstance=isinsta
                 yield from walk_node_list_less_note_contents(obj)
             elif isinstance(obj, dict):
                 yield (obj, node_list, index)
-                if obj['t'] == 'Note':
+                if obj.get('t') == 'Note':
                     continue
                 obj_contents = obj.get('c', None)
                 if isinstance(obj_contents, list):
@@ -1004,7 +1004,7 @@ class PandocConverter(Converter):
                                            'SoftBreak', 'Span'])
         for node_tuple in self._walk_ast_less_note_contents(ast):
             node, parent_node_list, parent_node_list_index = node_tuple
-            node_type = node['t']
+            node_type = node.get('t')
             if node_type in ignorable_inline_node_types:
                 pass
             elif node_type == 'Str':
@@ -1212,7 +1212,7 @@ class PandocConverter(Converter):
             thaw_raw_node = self._thaw_raw_node
             for node_tuple in self._walk_ast(final_ast):
                 node, parent_node_list, parent_node_list_index = node_tuple
-                node_type = node['t']
+                node_type = node.get('t')
                 if node_type in ('Code', 'CodeBlock') and 'codebraid--temp' in node['c'][0][1]:
                     thaw_raw_node(node)
         else:

However, this is a blind replace on my part, simply replacing wherever it complained that it was broken, so I have no idea if this breaks anything else. Should I open a PR?

gpoore pushed a commit that referenced this issue Dec 11, 2019
…, fixing incompatibility with nodes generated by citations (#12)
@gpoore
Copy link
Owner

gpoore commented Dec 11, 2019

It should be fixed in the last commit. Citations like that are represented in Pandoc's AST in a form that I hadn't previously encountered.

@gpoore gpoore added the bug Something isn't working label Dec 11, 2019
@Synthetica9
Copy link
Author

Seems to fix it! Thank you for the quick turnaround :)

gpoore added a commit that referenced this issue Dec 27, 2019
…, fixing incompatibility with nodes generated by citations (#12)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants