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

Refactor of Writers/EPUB.hs #7991

Merged
merged 2 commits into from
Mar 29, 2022
Merged

Refactor of Writers/EPUB.hs #7991

merged 2 commits into from
Mar 29, 2022

Conversation

jdonszelmann
Copy link
Contributor

After a comment by JGM we refactored EPUB.hs to make it more readable. This includes adding more comments, splitting up the main conversion function (which was 500+ lines long). We think that readability is improved like this, but more refactoring may be necessary before the kindle writer will be worked on.

If you disagree with some of the changes, let us know!

After a comment by JGM (jgm#1865 (comment))
we refactored EPUB.hs to make it more readable. More refactoring may be necessary, but
this is probably a nice first step.

Co-authored-by: Ola Wolska <A.k.wolska@student.tudelft.nl@gmail.com>
Co-authored-by: Ivar de Bruin <ivardb@gmail.com>
Co-authored-by: Jaap de Jong <jaapdejong15@gmail.com>

-- | Splits the blocks into chapters and creates a corresponding reftable
createChaptersAndReftable :: WriterOptions -> [Block] -> ([Chapter], [(Text, Text)])
createChaptersAndReftable opts secs = do
Copy link
Owner

Choose a reason for hiding this comment

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

Why is this written with do notation? There is no monad. I think you could just write

createChaptersAndReftable opts secs = (chapters, reftable)
 where
  chapterHeaderLevel = ...
  etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, my mistake, it should be fixed now, let me know if you want us to combine the commits into one.

@jgm
Copy link
Owner

jgm commented Mar 28, 2022

These look like good improvements in clarity (save the one thing I flagged in a comment).
I think it's probably possible to improve even further -- e.g. the functions with many positional arguments aren't so clear and it might be worth considering introducing records to tame the complexity (as I did already with EPUBMetadata). But (with the one small change noted above) I'd be happy to merge this as it stands, assuming CI passes.

@jgm jgm merged commit cd931e5 into jgm:master Mar 29, 2022
@jgm
Copy link
Owner

jgm commented Mar 29, 2022

Thanks! I can squash the commits through the interface here.

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.

3 participants