[forge:site-support:#246]
On the page above there is a table of contents just underneath the Versions Heading, and then each of the headings after that are included from seperate pages per version. I would expect that the table of contents to display the headings from the included pages as well as the headings from the current page. This does not happen.
It may just be me not quite understanding it, however it would be nice to have
I've put together a page demonstrating this here: https://sourceforge.net/p/strawhat/wiki/top/
Originally by: ligc
HI,
We are running into the same issue with the TOC supporting included pages, see https://sourceforge.net/p/forge/site-support/8032/.
This is very important for us, we are using included pages everywhere, without the TOC for these included pages, our documentation seems quite messed up.
Any idea on when this bug will fixed? Thank you.
Phew! This was a tough one. Make sure you test it against different wiki pages with different markup, macros, etc, since it changes markdown pipeline a bit.
Closed #635.
je/42cc_4771
Can you comment (here or in the code) about what the change in
ForgeMacroPattern
really does? The inline comment seems to be about thestrip()
andjoin()
but it's not obvious to me what callingetree.fromstring()
does in this context.The custom
slugify
function took me a bit to get (maybe just because its a friday afternoon) but looks like its the same as the original but with better unicode handling.The change in
ForgeMacroPattern
is essentially about making included page's content available toTOC
extension. We need to include processed page contents (html) into parent page, so thatTOC
will find it. Old code just put macro result onto html stash, which is processed after all the extensions (and there's no way around it), so it was hidden fromTOC
extension.Returning html as a string does not work in this context. Actually, it includes page contents as needed, but
TOC
extension still can't find it (don't sure why). If we return html as aetree
, thenTOC
can find it and do the job.The
except
might happen if macro returned error, which is just text and can't be parsed to html, so it's ok to return that text, since there will not be any headers that we need to include in TOC anyway.Regarding
slugify
you're completely right, it is only for better unicode handling. I was getting some "TypeError: must be unicode, not str" errors from within markdown, bacauseetree
that I return fromForgeMacroPattern
is always returns a bytestring, when coerced into string, and slugify needed unicode.Hope, this clarifies it.
If the include macro is used to include a repo file, the line numbers get squashed together. HTML changed from
to:
Closed #672.
ib/4771
I have added comments and fixed the case when page includes file from a repo directly, but there's still a problem if you include a wiki page, which, in turn, includes a file from a repo. I managed to fix issues with the line numbers in that case, but not with file contents (code). It gets extra
<br>
's which break layout. I've tried a lot of things to fix that, but nothing works.Entire approach is very fragile... Any ideas on how to tackle it in more robust way and fix the issue with multi-level includes?
I'm actually not seeing the extra
<br>
s with a double include. Current example: http://sf-dbrondsema-1015.sb.sf.net/p/testit/wiki/Home/I forgot to mention it. Add a header to the included page. If there's no headers entire TOC-related logic just skipped to avoid those nasty effects
Latest commits cause text to be omitted sometimes. Specifically it seems like a child page with a header will only include the text from the first line after the header.
Test case improvement:
I agree this approach is fragile, and getting quite messy. I don't really have a complete picture of how all the pieces fit together, so I can't really help with a specific recommendation. What it looks like to me though is the challenge is getting the includes to run before the TOC. And you've worked on moving includes earlier in the process but that is causing problems with how they get rendered. What about moving the TOC to later in the process, and leave the includes how they originally were? Would that be any better?
That was my first thought too. Unfortunately, I don't see how it's possible. According to markdown's code treeprocessors run before postprocessors. The TOC is implemented as treeprocessor. But output of "include" macros inserted into final page only on postprocessors stage.
The only way we can make TOC run later is re-implementing it from scratch as a postprocessor, which would search for headers and modify final html string to include table of contents. This approach would be also error-prone and hard to maintain...
Last edit: Igor Bondarenko 2014-11-12