oli-obk / pandoc-ast

35 stars 11 forks source link

Unknown Variant `Figure` Error #17

Closed Atreyagaurav closed 10 months ago

Atreyagaurav commented 1 year ago
thread 'main' panicked at 'json is not in the pandoc format: Error("unknown variant `Figure`, expected one of `Plain`, `Para`, `LineBlock`, `CodeBlock`, `RawBlock`, `BlockQuote`, `OrderedList`, `BulletList`, `DefinitionList`, `Header`, `HorizontalRule`, `Table`, `Div`, `Null`", line: 4776, column: 19)

I got the above error, I think it has to be updated for the latest version.

oli-obk commented 1 year ago

I am not really maintaining or using this crate anymore. If you supply a PR I will merge and publish it though.

Atreyagaurav commented 1 year ago

Thank you for the response. For now, I found this one https://github.com/rloic/pandoc which seems to work with the current pandoc version. Although it doesn't have the variety on the data types that yours has.

jonassmedegaard commented 11 months ago

The following patch seems to adequately implement support for Figure AST element:

Description: implement support for Figure introduced in Pandoc API 1.23
Author: Jonas Smedegaard <dr@jones.dk>
Last-Update: 2023-12-29
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -97,6 +97,8 @@
     /// Definition list Each list item is a pair consisting of a term (a list of inlines)
     /// and one or more definitions (each a list of blocks)
     DefinitionList(Vec<(Vec<Inline>, Vec<Vec<Block>>)>),
+    /// Figure, with attributes, caption, list of blocks
+    Figure(Attr, Caption, Vec<Block>),
     /// Header - level (integer) and text (inlines)
     Header(Int, Attr, Vec<Inline>),
     HorizontalRule,
--- a/src/visitor.rs
+++ b/src/visitor.rs
@@ -80,6 +80,18 @@
                     }
                 }
             }
+            Figure(ref mut attr, ref mut caption, ref mut vec_block) => {
+                self.visit_attr(attr);
+                {
+                    let (short, caption) = caption;
+                    if let Some(shortcaption) = short {
+                        self.visit_vec_inline(shortcaption);
+                    }
+
+                    self.visit_vec_block(caption);
+                }
+                self.visit_vec_block(vec_block);
+            }
             Header(_, ref mut attr, ref mut vec_inline) => {
                 self.visit_attr(attr);
                 self.visit_vec_inline(vec_inline);