Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

Add reference counting to all nodes #8

Closed
clayrisser opened this issue Feb 5, 2019 · 2 comments
Closed

Add reference counting to all nodes #8

clayrisser opened this issue Feb 5, 2019 · 2 comments

Comments

@clayrisser
Copy link
Owner

clayrisser commented Feb 5, 2019

During my implementation of tables, I found it quite handy to add reference counting support through node arrays.

Instead of reference counting with integers, I am using arrays of nodes.

This solved two major challenges.

  1. Knowing where I am in nested nodes of the same type
  2. Finding information from nodes outside of the current node

You can see a simple implementation of this with tables.

    tables = []

    def visit_table(self, node):
        self.tables.append(node)

    def depart_table(self, node):
        self.tables.pop()

To detect how deep you are in the tree (at least with nodes of the same type), you can simply grab the length.

    @property
    table_depth():
        return len(self.tables)

To grab the current node of a certain type, simply grab the last node from the array.

    @property
    current_table():
        return self.tables[self.table_depth - 1]

This has been so helpful with tables, I am thinking about adding this to all the nodes. Please give your feedback below.

@clayrisser
Copy link
Owner Author

To fully implement reference counting across all nodes, the doctree2md.py would eventually need to be fully deprecated. I think this is reasonable, as I am getting a decent grasp on how sphinx/docutils builders work.

Please referecne the issue below on deprecating doctree2md.py.
#9

@clayrisser
Copy link
Owner Author

DISCONTINUED: This project is no longer maintained. The active version of this project is now being maintained at liran-funaro/sphinx-markdown-builder.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant