Exclude headings from table of contents
Contents
Since Moin 1.5 we don't have the pagename anymore in the page but in the theme's header. People now start to emulate this old behaviour by introducing h1-headings with some kind of page title or description, then they put the table of contents underneath that (see above). However h1 as new page title is included in the table of contents and this is not wanted.
A related issue is section numbering - when using h1 heading in the page as the page title, the heading is numbered 1. It is possible to configure section numbers to ignore the first level, but it is not a good solution, because it require special effort for the common case.
Possible Solutions
Add #pragma section-numbers 2 in the page header. It works for this page, I'm not sure if it works for included pages.
- It doesn't: All h1 headings of the included pages are thrown away either.
Go back to 1.3 title style; either use a theme that show the title inside the page, like ModernCmsTheme, or change your site theme to show the title inside the page
Change TOC macro to ignore first level heading: = Page Title = when the heading is the first heading in the page. This should work also for included pages.
- Change TOC macro to ignore anything before the toc macro itself (issue: how to treat included pages?)
- Introduce new markup for page title, use page name if the markup is not used. There was an suggestion in the past to change the page name using a #pragma.
- Introduce new markup to hide headings from TOC macro
- Or just use the HTML macro to do some header tags outside of wiki markup...
A good solution should work transparently for the common case without any configuration, and should not require converting of existing content in 1.3 or 1.5 wikis.
Title markup
My two cents: Seems like the root of the issue is that some people (myself included) want a way to put a title at the top of the page. If I were writing the spec, the requirements would go something like this:
- The title should in no way be interpreted as a heading.
Not sure about that. Or to be more precise: It shouldn't be interpreted as heading by the toc macro. But since the page title has some "super"-heading functionality, it should also be marked with the h1 html markup. As far as I can see, this is one criteria for AccessibleMoin (see http://www.w3.org/TR/1999/WAI-WEBCONTENT-19990505/ Checkpoint 3.5: Use header elements to convey document structure and use them according to specification.)
So, the only way to make a recognizable (accessible) title is to use H1? If that's the way it is, then sobeit. Unfortunately, since MoinMoin made H1 available after 1.3x, people have started using = H1 = level headings in markup, meaning that will have to change yet again.
The title text must be specifiable in the markup. The themes already show the actual page name, so it does not generally need to be repeated. This requirment would allow the author to form a title different than either the subpage name, or the full page name (path), and that is well suited for the page contents. Example: for a page named Animals/Mammals/EatingHabits/Horse, that is not the greatest title. The subpage name (Horse) is even worse. A much better title might be "What a Horse Eats" or "Horse Diet" depending on the audience.
Some of the themes show the title in the header, but it does not really work as a page title. What modern (1.5) does is show bread crumbs in huge font. Of curse Animals/Mammals/EatingHabits/Horse is a horrible page title, however, the sub page name Horse is an excellent title. If you think that the page is about horse diet, why not rename the page to Animals/Mammals/EatingHabits/HorseDiet?
I have to disagree... While it could be argued that "Horse" is an OK title, it is in no way an "excellent" title. Changing it to "Horse Diet" is redundant and may not be desirable in the organizational scheme. I could come up with many more examples if you can't imagine them yourself. Also, perhaps not all themes show the full page path, but that does not mean that a title at the top of the content area should have to do it. And that was the whole point of this requirement, let the author coin the title (independently of the official page name).
Further, since we want a title that doesn't act like a header, it would be nice to have one that doesn't look like a header, either. Things like different color, centered, larger than h1, etc., would be nice to have. None of these are possible with headers, since they do not allow markup. (To have a consistent look throughout the wiki, the default look of a title should be configurable for the wiki as a whole.)
<h1 class="title"></h1> solve the different look issue, and is configurable by wiki wide CSS.
- Eventually, it might be nice to have a way to search only the "friendly" titles, or maybe the pagenames + title.
Why not add some parameters/keywords to TOC -- ReimarBauer 2007-02-10 22:22:41
Because more arguments are not needed?
New markup to hide headings from TOC macro
Add a new markup that allows to drop certain headings. e.g. if you write != PageTitle= this heading is not included since it is marked with a ! like we do it now to escape wikilinks, e.g. !NoWikiLink.
This seems to me an easier solution than having also a min-depth in the TableOfContents macro call like suggested on FeatureRequests/TableOfContentsMinDepth. But I haven't thought on that much... -- OliverSiemoneit 2007-01-07 21:50:36
I like the idea very much!! +1. Looking forward to see a patch for that -- DollyBuster 2007-01-07 21:50:36
Thanks Dolly. Here's a patch for the text_moin_wiki parser of Moin1.6(moin-1-6-main-7c58e8af1a97)
I don't like this solution because it adds new markup which is not really needed except page titles, and it requires converting old content and more learning for end users. -- NirSoffer 2007-02-09 15:52:29
Thanks Nir for all that information. This was very helpfull and I could learn a lot form that. It's true the patch looks quite silly if you turn on section numbering (Haven't thought on that... That's again a typicall newbie mistake). Just saw some weeks ago, that TWiki has a mechanism to escape headings and thought myself: Would be nice to have that in Moin, too (so that people don't complain "What? Where is heading escaping? I don't use that.."). However, as I have already indicated, I does not make much sense for deeper levels of headings and if you just use the escaping mechanism for creating a page title - you are right - before puzzeling users it is better to forget about that TWiki transfer totally. Here is another suggestion, but I don't fell well with this either: What about having just a markup for doing some big text like ~+large+~ (large) now: ~++ very large ++~ e.g for titles? So people can put a title on a page if they want or leave it away. No pragma, no forcing of titles, no need to change TOC macro... -- OliverSiemoneit 2007-02-09 19:58:15
1 --- text_moin_wiki_old.py 2007-02-08 19:25:32.000000000 +0100
2 +++ text_moin_wiki.py 2007-02-08 19:40:06.000000000 +0100
3 @@ -88,6 +88,7 @@
4 (?P<indent>^\s+)
5 (?P<tableZ>\|\| $)
6 (?P<table>(?:\|\|)+(?:<[^>]*?>)?(?!\|? $))
7 +(?P<esc_heading>^\s*!(?P<esc_hmarker>=+)\s.*\s(?P=esc_hmarker) $)
8 (?P<heading>^\s*(?P<hmarker>=+)\s.*\s(?P=hmarker) $)
9 (?P<interwiki>[A-Z][a-zA-Z]+\:(%(q_string)s|([^\s'\"\:\<\|]([^\s%(punct)s]|([%(punct)s][^\s%(punct)s]))+))?)
10 (?P<word>%(word_rule)s)
11 @@ -745,6 +746,8 @@
12 else:
13 return self.formatter.text(word)
14
15 + def _esc_heading_repl(self, word):
16 + return self._heading_repl(word.strip(' !'))
17
18 def _heading_repl(self, word):
19 """Handle section headings."""
20 @@ -894,7 +897,7 @@
21 """ Replace match using type name """
22 result = []
23 for type, hit in match.groupdict().items():
24 - if hit is not None and not type in ["hmarker", ]:
25 + if hit is not None and not type in ["hmarker", "esc_hmarker" ]:
26
27 ##result.append(u'<span class="info">[replace: %s: "%s"]</span>' % (type, hit))
28 # Open p for certain types
With the markup != Your Title = you can now escape a heading from being included in the table of contents. Of course this works for headings of all levels and does also work with the IncludePage macro.. So you can do for example something like this:
!= TaskPlanner = [[TableOfContents]] = Installation = sdfsdsdfd sdfsdf == Step 1 == sfsdfsddff == Step 2 == sfsasfddfa !== Step 3 is escaped if you find that makes sense (I don't think so) == sdfsdfsdf = Related Work =
Output:
-- OliverSiemoneit 2007-02-08 19:15:11
New macro to produce a pagetitle
Here's a small macro that allows to create a pagetitle with '<h1 class="title">Page Title</h1>'
1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - Title Macro
4
5 This very complicated macro produces a page title
6
7 @copyright: 2007 by Oliver Siemoneit
8 @license: GNU GPL, see COPYING for details.
9 """
10
11 Dependencies = []
12
13 def execute(macro, args):
14 kw = {}
15 kw['class'] = 'title'
16 result = "%s%s%s" % (macro.formatter.heading(1, 1, **kw),
17 macro.formatter.escapedText(args),
18 macro.formatter.heading(0, 1, **kw))
19 return ''.join(result)
20
Advantages:
No need to change toc macro since the h1 is hidden in the raw text by the macro call [[Title(Page Title)]]
- Fully customizable by stylesheet
Compliant to AccessibleMoin
Disadvantage:
- Introduces extra complexity
- Need to change existing wikipages
- Does not work correctly with section-numbers on
- No way to skip the page title of an included page? Need to change Include macro either??
TOC macro changed to ignore text before
Here's a patch for the toc macro which makes toc forget about all the headings written before the toc macro in the raw text
1 --- tableofcontents_old.py 2007-02-17 22:28:02.000000000 +0100
2 +++ tableofcontents.py 2007-02-17 22:42:46.000000000 +0100
3 @@ -76,7 +76,10 @@
4 self.result.append(self.macro.formatter.escapedText(_('Contents')))
5 self.result.append(self.macro.formatter.paragraph(0))
6
7 - self.process_lines(self.pre_re.sub('', self.macro.parser.raw).split('\n'),
8 + # Ignore headings before toc macro
9 + strip_raw = self.macro.parser.raw[self.macro.parser.raw.find('[[TableOfContents'):]
10 +
11 + self.process_lines(self.pre_re.sub('', strip_raw).split('\n'),
12 self.macro.formatter.page.page_name)
13 # Close pending lists
14 for i in range(self.baseindent, self.indent):
Advantages:
- No changes to exisiting wikipages needed
- Intuitiv usage?
- No extra learning to endusers needed
- Works with included pages
Compliant to AccessibleMoin
Disadvantages
- Proper solution?
Too much limitations? --> Add a parameter to change that new default behaviour??
- Not customizable extra title by stylesheets
Does not work correctly with section-numbers on