So the question is how to get this kind of information:
from
This is one of my ideas:
get = Function[notebook,
Block[{i = 0, cells},
cells = Cells[notebook];
# /. _Cell :> cells[[++i]] (*a*)
] & @ Block[{Cell, cells, i = 0},
Cell[CellGroupData[c_, ___], ___] := c;
First @ NotebookGet[#]
] & @ notebook
]
(*Ad a: We are using ReplaceAll instead of Cell[___]:=cells[[++i]] because
we want to avoid counting inline cells. We also have to do this in separate Block so
Cell[CellGroupData will be flat already.*)
But NotebookGet
is not so fast, the bigger the notebook the slower, obviously. For help notebook it takes about 2 seconds. Far to much in my opinion.
get[help] // AbsoluteTiming
On the other hand it is quite compact and deals well with InlineCells
, nondefault CellGrouping
or custom cell styles.
So is there faster alternative? It doesn't even have to deal with non standard cellgrouping etc.