jgm/commonmark-hs

More conservative `sourcepos`

not-my-profile opened this issue · 4 comments

I would love to have source positions for headings but I don't want nearly everything to be wrapped in additional spans / divs, because it completely breaks my existing pandoc AST processing code. So could there be a more conservative mode that only adds source positions to elements that actually support attributes?

(To be clear this is a feature request for Pandoc, I'm just opening the issue here since this would need to be implemented here.)

jgm commented

Of course it's possible in principle, but I'd rather not add the extra complexity this would require.
I'd rather ask you to adjust your processing code so it can handle the extra Spans and Divs.

Are you sure that the additional complexity isn't worth it? Because having an important feature such as sourcespan being largely incompatible with a whole ecosystem of Pandoc AST transformation software (It's not just my code it's also most Lua filters for pandoc) seems misguided to me.

I'd argue that the ecosystem around Pandoc is large enough that the cumulative complexity necessary to workaround sourcespan everywhere is bound to be greater than the complexity to just not do something in commonmark-hs. (I presume that many people just won't use sourcespan because it's too much hassle to get it working with existing code).

Could you elaborate on the challenge of implementing this? Would you accept a PR that implements this?

jgm commented

At minimum, you'd need to have two different sourcepos extensions that worked differently. That's already more complexity than I think is desirable.

I'd say that if filters are assuming that elements won't be contained in divs or spans, they're overly brittle and should be improved.

jgm commented

Besides, if you can't be bothered to update filters, it's fairly trivial to write a filter that matches Span and Div elements that contain no attributes other than sourcepos attributes, and replaces them by their contents. Just use this filter before the brittle filter.