jgm/pandoc-types

Walkable instance (and newtype) for Attributes

Opened this issue · 7 comments

jgm commented

It would be nice to be able to walk an AST and perform a replacement or query on all attributes. (We need to do that, e.g., in the EPUB writer.)

The instances wouldn't be hard to write, but probably this would require putting Attributes in a newtype or data type.

Something like

newtype Attribute = Attribute (Text, [Text], [(Text, Text)])

instance Walkable Attribute Pandoc where
-- etc.

perhaps, so that this could be done without changing the Attr type in the AST? It could be done at the same time that type is changed, of course.

I am going to implement this.

jgm commented

Note that putting Attributes in a data type (which should be Attributes not Attribute if we do it) would require changes throughout the entire pandoc and pandoc-dependent code base.

How can i change pandoc-types and pandoc in one pull request? It seems to me, it's impossible. Or I should add Attributes, then change code in Pandoc (remove using old Attr), and then in another PR remove old Attr from this repo? And should I make Attributes a datatype or just a new type?

srid commented

If we are changing the type of the attribute, it is worth reviewing other feature requests related to attributes so we can do them all in one get-go, eg: #79

jgm commented

Yes, I think when this was last discussed there were some open issues about what to do, which never got resolved, e.g. whether to take on the ordered-containers dependency. Of course, a simple newtype wrapper around the type we have now would be the least painful to implement -- but it would still require touching just about every pandoc module. I mentioned that to warn @ricnorr that this might not be the easiest project to take on. (And you're right, it would require separate pull requests for pandoc-types and pandoc -- and also for texmath, citeproc, and other things that import pandoc-types!)

Ok, and can you (@jgm) consult me about, how to do it better? Should I add 'new' attribute to each datatype (merge pr), then remove support of old attributes in other projects (merge pr), and then remove old attributes from pandoc-types?