From: Mohsen M. <mo...@sc...> - 2004-08-30 17:27:01
|
Quoting Felix Wiemann <Fel...@gm...>: > Mohsen Moeeni wrote: > > > ``node.rawsource`` returns the source of a node stripping its > > indentation, while for some reason, I need the indented version. > > I don't think it's (easily) possible to retrieve a node's indentation, > because in many (or even most) cases it simply doesn't matter to the RST > parser. > > But why do you need to know the indentation? I.e., what specific > problem are you trying to solve that way? > It's a long story related to a Zope product which I am developing. The product is like ``BackTalk`` but it uses ``ReST`` instead of ``STX``. BackTalk is a product which is used to delveop Zope Book and lets reader to annotate the text. I can express the problem with this statement: I attach an Id to each node. Having a node's Id, In some function, I need to put a directive just after that node. I can find the node with its Id and get its rawsource. If the rawsource was indented, I could use a simple python code to put the directive in its place (This code does not consider that there might be multiple nodes with the same source, however I have managed this case in the existing code, but for sake of brievity, I do not go into that here):: parts = source.split(rawsource) source = parts[0] + rawsource + \ '\n\n.. mydirective::' + parts[1] But now that there is no easy way to get the indented version of a node, I have to play with regular expressions to split the source. Thanks for your reply. Cheers, Mohsen, |