Skip to content

✨ Allow simple way to create custom block sorting #480

@MiWeiss

Description

@MiWeiss

We'd want to facilitate users sorting blocks according to their needs.

They easiest and most general way to do this would probably be to create a new abstract class SortBlocksMiddleware with the following properties:

  • The abstract class should have just one unimplemented method, and it should have the signature compare(block1, block2) -> int, following the standard convention that any returned value > 0 indicates that block2 should come anywhere after block1, any value <0 the opposit and a return value of 0 sais that any order of the two should be fine.
  • The docstring of the compare method should list the standard conventions for such a method (the conditions above, but also that it's transitive, pure, ...)
  • Our own SortBlocksByTypeAndKeyMiddleware should extend/implement SortBlocksMiddleware
  • The documentation should provide a simple MWE

Location of the code: https://github.com/sciunto-org/python-bibtexparser/blob/main/bibtexparser/middlewares/sorting_blocks.py

I am currently not working on this, so feel free to comment below if you want to take over.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions