hieroglyph
hieroglyph copied to clipboard
All rst files must have a slide when autoslides=False
When the autoslides setting=False it's a problem that all rest files must then contain at least one slide. My use case is for a bunch of html notes to supports some lecture slides. It'd like to have only the lectures as slides, and the notes as html. This seems impossible currently however. The error is:
Exception occurred: File "/Users/ben/Envs/lectures/lib/python2.7/site-packages/docutils/nodes.py", line 954, in replace_self 'Losing "%s" attribute: %s' % (att, self[att]) AssertionError: Losing "ids" attribute: ['mydocumenttitle']
Where mydocumenttitle is the top level heading of the page without a slide.
That sort of makes sense given where Hieroglyph lives in the Sphinx processing pipeline. I'd have to dig a little deeper, but I think this is going to be a little gnarly to fix: the "right" thing to do is along the lines of detecting that we're in this state (autoslides off), and then only processing files that contain a slide. That'd only work, then, when set in the project config (as opposed to in the per-file header).
On Thu, Feb 19, 2015 at 1:42 PM, puterleat [email protected] wrote:
When the autoslides setting=False it's a problem that all rest files must then contain at least one slide. My use case is for a bunch of html notes to supports some lecture slides. It'd like to have only the lectures as slides, and the notes as html. This seems impossible currently however. The error is:
Exception occurred: File "/Users/ben/Envs/lectures/lib/python2.7/site-packages/docutils/nodes.py", line 954, in replace_self 'Losing "%s" attribute: %s' % (att, self[att]) AssertionError: Losing "ids" attribute: ['mydocumenttitle']
Where mydocumenttitle is the top level heading of the page without a slide.
— Reply to this email directly or view it on GitHub https://github.com/nyergler/hieroglyph/issues/86.
I think it's more reasonable - or at least explicable - that it fails when you set autoslides to off within a file but you don't explicitly provide a slide to process. Fixing the case where autoslides is set in conf.py would be a great first step at least.
I'm not an expert on docutils, but isn't it possible to read a flag set in the file from the hieroglyph processor?
The issue is that by the time Sphinx has processed an RST file into a docutils tree, I think it's too late to bail out and remove it from the set. And it's definitely possible to hook into Sphinx and modify the list of files to process, but that happens well before the files are parsed. So there's something of a chicken/egg problem here: you want look at some data from the parse, but you want to look at it before Sphinx has parsed the files.
It's probably worth digging into Sphinx to see if there's a call we can make to drop a file from the set after parse, or at least after it's read.
Fixing this is/seems simple. There are two ways (used) to replace self
node.replace_self(something) # This may raise an error; as described
# OR
node.parent.replace(node, something) # Will NOT raise an error
The latter typically calls the former.
Both constructs are used in hieroglyph; but I don't know the reason for that. I was wonderring about replacing the second by the first, as part of a code cleanup (in my branch, to fix other items). But walked into the same error; so I didn't.
Given the request; it possible to work around the raised error. However, i'm a but reluctant as I have study the consequences yet: what does it functionally do/change?
Do you have an opinion on that @nyergler?
My recollection is that there were cases where the node didn't necessarily have a parent. I seem to recall that docutils did something slightly different in the two cases when there wasn't a parent. That said, in this particular case there'd always be a parent node, so probably doesn't matter.
Hieroglyph has better test coverage than it used to, so it might be interesting to see if replacing it works.
I'm having trouble with the autoslides option. If it is set False in config.py, the hieroglyph build fails, apparently in any document with a toctree:
Extension error (hieroglyph.directives): Handler <function process_slideconf_nodes at 0x7f6a2b4621f0> for event 'doctree-resolved' threw an exception (exception: Losing "ids" attribute: ['tier-i-to-tier-ii-data-extraction']) make: *** [Makefile:35: slides] Error 2
A work-around is to turn on autoslides for those totcree documents, but that can lead to problems with toctrees longer than the slide (which can again be manually overcome with a next_slide directly).
Or, use 2 different configs as mentioned by @NatalieZelenka.
A native fix for autoslides/toctree would be ideal.