[Home]NamedAnchorsInWiki

MeatballWiki | RecentChanges | Random Page | Indices | Categories

From MeatballWikiSuggestions

There are two main issues involved with NamedAnchorsInWiki

  1. what tag to write to cause a named anchor to be coded by the WikiEngine
  2. how to make links to named anchors in wiki pages, from within wiki pages

Once we have pages with named anchors in place, it might be handy to be able to automatically insert the list of named anchors as a small list.

Current suggestions for creating named anchors

Suggestions for referencing named anchors

Suggestion for bonus feature:

[CategoryMeatballWikiSuggestion]


Named anchors (todo for 0.92)

I am thinking about placing named tags in a wiki page so that at this place in the page output, UseModWiki emits

<a name="named_anchors"></a>

so when I go to MeatBall:MeatballWikiSuggestions#named_anchors it goes to that location. I'm not sure what the WikiSyntax should be, but it would be handy when referring to specific entries in my diary or to entries in a (hypothetical) FAQ.

How about <anchor>anchor_text</anchor>? I don't think this will be commonly used, but it could be useful occasionally. The anchor_text will probably be limited to just alphanumerics and underscore characters, so you can't do bad anchors like <anchor>" HREF="javascript:...</anchor>. (I'm now getting suitably paranoid.) -- ca

[anchor:anchor_name] -- I like this one, since (a) it's quite similar to the bracket notation for http/ftp etc, and also (b) because I hate to type those damn angle brackets everywhere, especially twice by twice (once before, once after).

-- darn, couldn't get better than this could it? The syntax is reminiscent of how to refer to it, minimal typing required, none of that balancing end tags or shift-comma shift-period foolishness. -- EricScheid

I've had several occasions when I wanted to specifically link to one entry on my diary, so it would be useful to me. <anchor>anchor_pattern</anchor> would be perfect. --ss

Patch

 sub CommonMarkup {
   my ($text, $useImage, $doLines) = @_;
   local $_ = $text;

   if ($doLines < 2) { # 2 = do line-oriented only
     # The nowiki tag stores text with no markup (except quoting HTML)
     s/\<nowiki\>((.|\n)*?)\<\/nowiki\>/&StoreRaw($1)/ige;
     # The pre tag wraps the stored text with the HTML pre tag
     s/\<pre\>((.|\n)*?)\<\/pre\>/&StorePre($1)/ige;
     s/\<anchor\>(\w+)\<\/anchor>/&StoreHref(" name=\"$1\"")/ige;   ## ADD THIS LINE

(Notice the bug: the < and > actually make it out as < and > instead of &lt; and &gt;. See the source of this page to understand what I mean.)

Not a bug. Underdocumented side-effect, perhaps. The HTML-escaping step is done first, and allows sequences like &xyz; to remain unescaped. This allows you to use characters like ∞, ©, and δ in your pages. This behavior is not likely to change. If you really want to escape a HTML character sequence, you'll need to replace the starting & character with &amp; as in &infin;. --CliffordAdams

I've implemented [#anchor_name] with this line of code:

    s/\[\#(\w+)\]/&StoreHref(" name=\"$1\"")/ige;
-- EricScheid

You could perhaps mark the === headline === syntax as named anchors ... automatically creating named anchors for page sections at the same time. Less work for everyone, plus encourages page structure over ThreadMess. Oooh ... you get something else for free if you do this: hierachical ordering of named anchors (eg. 1, 2, 2.1, 2.2, 2.2,1, 3, 4)

One problem is what to do with disallowed characters, such as spaces and punctuation, and also how to handle the situation of people editing the text and breaking links to that named anchor.

-- EricScheid

See also: Named Anchor Links and Named Anchor Summary


Named Anchor Links

Once we have named anchors in the page, we need some way to link to them, other than writing out the full URL by hand as in http://meatballwiki.org/wiki/MeatballWikiSuggestions#Anchor1.

Since named anchors won't necessarily be LinkPatterns?, it might be better to allow the link URL be hidden in the same way that [square-bracket-urls with textual link text] works. Thus, suggest format might be: [WikiName#anchorname display text]

-- EricScheid

For what it's worth, I agree completely. We don't want to get into the unreadable gook that is MeatballWikiSuggestions#Anchor1. Furthermore, this is amazingly similar to SubPages which are equally unreadable, in my humble opinion. (Sorry, Cliff ;) At least anchors are easier to navigate. -- SunirShah

Upon reflection, the simplest thing that could possibly work is to let WikiName#anchor be recognised as links ... then you could use them with [bracket notation] and InterWiki notation, or just plain jane unobfuscated.

Implementation ... would have to allow # in the wikilink pattern when rendering, and pass that through to the sub that creates the link. That sub would then check to see if there is a #anchor, and if so strips it off before checking to see if wikilink is a known WikiName, and then (if known) adds it back into the URL. Sigh ... looks like I'll be slurping spaghetti tonite. -- EricScheid

That's how they are currently implemented. Note how the undefined pages suppress anchors by a hereto unknown dependency in the code. SampleUndefinedPage#anchor SandBox#anchor SampleUndefinedPage? SandBox#anchor -- SunirShah


Named Anchor Summary

Once we have named anchors in the page, it could well be handy to be able to automatically insert the list of those named anchors. Ideally, this would be via a wiki-tag so the list could be inserted after an introductory paragraph, left out entirely, etc. Bonus points if we could specify in the wiki-tag a different WikiName.

Thus:

<anchors> could produce:

and <anchors:WikiName> could produce:

where each of those lines is in fact a link to the corresponding anchor.

I'm not 100% liking the repetition of WikiName in that format though. Perhaps it could suffice to insert a table header

An example of where this could be useful is on MeatballWikiBugs, which could present an automatically updated table of contents of its sister page, MeatballWikiBugsResolved.

Note that by re-using the === headline === syntax we can introduce a hierachical structure to the anchor summary

-- EricScheid


Named Anchors and TableOfContents

Perhaps we just need yet another WikiSyntax for numbered headings. Perhaps, simply...

== # heading2 ==
=== # heading3 ===
==== # heading4 ====

which emits

1. heading2

1.1. heading3

1.1.1. heading4

... see UseMod:WikiPatches/NumberedHeadings

And then you can easily generate a TableOfContents. ... see UseMod:WikiPatches/TableOfContents


Discussion

MeatballWiki | RecentChanges | Random Page | Indices | Categories
Edit text of this page | View other revisions
Search: