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

Add rowspan, colspan and alignment to cells in jats table reader #8724

Closed

Conversation

noahmalmed
Copy link
Contributor

Description

I'm looking for some guidance on completing this code change. This is my first time writing Haskell code and I'm getting stuck on some code and I can't tell if my design is wrong/bad or if I'm just missing something syntactically or conceptually.

My issue is arising from trying to parse the xml Element attributes at the same time as when we parse the content of the Element itself, so when we create a Cell, we have all of the information we need.

The previous design of the code just parsed the xml row Elements into Blocks and then made simpleCells (which don't accept rowspan, colspan or alignment attributes) from those Blocks.

So, I'm getting stuck with a typing/monad issue. I'm able to parse out the colspan, rowspan and alignment attributes from the xml and push those values into cells, but I'm having a heard time using parseMixed to parse an Element into Blocks. parseMixed returns the type StateT JATSState Blocks. What would be an idiomatic way to get the Blocks value out of the StateT JATSState monad that is returned by this function?

I also realize that because I'm new to Haskell and Pandoc that my approach to this problem may be way off base, so any direction there would be welcome as well!

Comment on lines 307 to 312

-- How do I parse an Element into Blocks?
-- parseCell takes an element and returns a StateT JATSState Blocks, but I need it to return the unwrapped value
let parseCell = parseMixed plain . elContent

let elementToCell element = cell (toAlignment element) (RowSpan $ toRowSpan element) (ColSpan $ toColSpan element) mempty
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is where I am having trouble. Right now, I'm creating an empty Cell, but I really want to be able to use parseCell to parse the content of the xml cell into the Pandoc cell

Copy link
Collaborator

@tarleb tarleb Mar 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All parsing happens ins the StateT JATSState m type, a.k.a. JATS m. It is an instance of Monad, so we can use cellContent <- parseCell element to "unwrap" the Blocks while we are in a do block, as is the case here.
I could probably free half an hour tomorrow if you want to pair on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick response @tarleb! Running cellContent <- parseCell element makes sense, but I think what's tripping me up is that I would want to run it in the context of elementToCell, which is not in a do block.

I'd love to do a quick pair! I'm normally available between 8-5 CST (GMT -6), but also wouldn't mind stretching on either end. Let me know when works for you!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would 14:30 UTC work for you? If so, please send me an invite via mail.

@noahmalmed noahmalmed force-pushed the nm/add_rowspan_colspan_to_jats_parser branch from e72f554 to d69248e Compare March 28, 2023 16:51
@noahmalmed noahmalmed closed this Mar 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants