On Fri, Apr 3, 2009 at 12:49 PM, Edward K. Ream <[email protected]> wrote: > > Kent and I spent quite awhile at the sprint discussing Leo as a > platform for rST markup. Kent's idea was that Leo should be able to > import rst files, have the user edit the files, and then write the > files with no changes whatever except the changes the user actually > made. I agree completely that this is a good goal. > > During the sprint, Kent talked to David Goodger, the author of > docutils, about how to use the docutils rst parser to help import rst > files into Leo. Kent worked on a script that was supposed to do the > job.
Docutils includes a 'GenericNodeVisitor' class which provides methods like "visit_section" and "depart_section" in which to do things to the rst doctree. Docutils seems to have a bug, in that the 'rawsource' attribute in these methods is empty, it is intended to contain the lines from the rst file which comprise the section heading. The jiggery-pokery I've been messing with is to get around this limitation, if docutils provided the 'rawsource', determining the adornment style of a section title would be much easier. > > However, I think there is another way, namely to create a Leo importer > for rst files. Parsing rst files is actually not too difficult. The > problem lies in retaining the exact markup used to represent rST > section. That is, we want to remember, say, that the original file > used ###### as the underlining for top-level markup. I also make use of the "visit_image" method to build a list of image filenames mentioned in the rst file. The advantage of using the GenericNodeVisitor include - guaranteed to be and remain accurate - easy access to all element types - want to gather all literal blocks? no problem. Leo will benefit from an rst importer which converts sections to nodes however it is implemented. > > Kent proposed to keep this info in uA's, but I think a clearer, more > explicit way would be to create a new Leo directive, say @rst- > underlines. This would correspond to the rst3 plugins > underline_characters option. The idea is that the importer code would > automatically create this directive when importing, and the code > (maybe a separate command) that writes the rst file would use the @rst- > underlines directive to generate the rST markup for sections. > > Some important details remain. For example, importing an rst file > probably should not create an @thin node (or any other kind of > @<file> node), because Leo's write code doesn't understand rST markup, > and should not be asked to create such markup. Instead, as I said > above, a separate command, say rst-write, would be needed to write the > revised rst file. But this kind of complication will remain > regardless of how the rst file gets imported into Leo. > > Your comments, please. > > Edward > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "leo-editor" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/leo-editor?hl=en -~----------~----~----~----~------~----~------~--~---
