Edgewall Software

Ticket #2877 (closed enhancement: fixed)

Opened 2 years ago

Last modified 19 months ago

Spaces in WikiNames

Reported by: mladen@… Owned by: cboos
Priority: low Milestone: 0.10
Component: wiki system Version: 0.9.4
Severity: minor Keywords: CamelCase WikiPageNames
Cc: mladen@…

Description (last modified by cboos) (diff)

Could you please add the ability for WikiPageNames to automatically be displayed with spaces? So when entering WikiPageNames it would come out as Wiki Page Names. I suppose this could also be configurable.

Attachments

wiki_insert_spaces_r3013.diff (1.5 kB) - added by cboos 2 years ago.
A slightly refined patches, with a TracIni setting for the feature.
wiki_insert_spaces-0.9.diff (1.6 kB) - added by cboos 2 years ago.
Same as the other one, but for Trac 0.9.4

Change History

Changed 2 years ago by anonymous

  • cc mladen@… added

I suppose I should have said WikiPageNames? (so that they look like Wiki Page Names)

Changed 2 years ago by cboos

  • keywords CamelCase WikiPageNames added
  • priority changed from normal to low
  • component changed from general to wiki
  • severity changed from normal to minor

Interesting approach. I think a lot of people would like this increased readability. The only drawback I see is the small discrepance that this would introduce between visualizing and editing WikiPageNames.

Is that idea already in use in some other wikis?

Changed 2 years ago by anonymous

  • priority changed from low to normal
  • component changed from wiki to general
  • severity changed from minor to normal

Yes it is in WackoWiki. Works brilliantly, and a wiki page then tends to look more like a proper document. They made it configurable but it's on by default.

Changed 2 years ago by mladen@…

  • priority changed from normal to low
  • component changed from general to wiki
  • severity changed from normal to minor

Oops sorry, don't know how those things changed. I put them back now ;)

Changed 2 years ago by cboos

  • owner changed from jonas to cboos

If you want to play a bit with a proof-of-concept implementation:

Index: trac/wiki/api.py
===================================================================
--- trac/wiki/api.py	(revision 3013)
+++ trac/wiki/api.py	(working copy)
@@ -199,13 +199,18 @@
         ignore_missing = self.config.getbool('wiki', 'ignore_missing_pages')
         yield (r"!?(?<!/)\b[A-Z][a-z]+(?:[A-Z][a-z]*[a-z/])+"
                 "(?:#[A-Za-z0-9]+)?(?=:?\Z|:?\s|[.,;!?\)}\]])",
-               lambda x, y, z: self._format_link(x, 'wiki', y, y,
-                                                 ignore_missing))
+               lambda x, y, z: self._format_short_link(x, 'wiki', y,
+                                                       ignore_missing))
 
     def get_link_resolvers(self):
-        yield ('wiki', self._format_fancy_link)
+        yield ('wiki', self._format_long_link)
 
-    def _format_fancy_link(self, f, n, p, l):
+    def _format_short_link(self, formatter, ns, page, ignore_missing):
+        words = re.split(r"([A-Z])", page)
+        label = ' '.join([a+b for a, b in zip(words[1::2], words[::2][1:])])
+        return self._format_link(formatter, ns, page, label, ignore_missing)
+
+    def _format_long_link(self, f, n, p, l):
         return self._format_link(f, n, p, l, False)
 
     def _format_link(self, formatter, ns, page, label, ignore_missing):

Changed 2 years ago by cboos

A slightly refined patches, with a TracIni setting for the feature.

Changed 2 years ago by anonymous

Brilliant thanks. i'm not a python developer and I'm only running Trac 0.9.4. so I don't know how to implement this. But anyway, I guess I'll just wait for the next release :)

What did you think of the results?

Changed 2 years ago by cboos

Well, I liked it, the wiki pages becomes more readable IMO. But that's not a guarantee that this feature will make it into the next release :)

I'd like to have some feedback from other Trac devs on this.

In the meantime, you can try to apply a 0.9 specific patch (attachment:wiki_insert_spaces-0.9.diff) on top of your 0.9.4 package:

$ cd src/trac-0.9.4
$ ls
... 
trac/
...
$ patch -p0 < wiki_insert_spaces-0.9.diff
$ python setup.py install #optional --prefix=/where/to/install

Changed 2 years ago by cboos

Same as the other one, but for Trac 0.9.4

Changed 2 years ago by Mladen Mihajlovic <mladen@…>

Works very well. Thanks a lot.

Changed 2 years ago by cboos

I just realized that we don't care if there's also an additional space in front of the Wiki page names, so the "tricky" code above that computes the label can be replaced by a simple
label = re.sub(r"([A-Z])", r" \1", label)

Changed 2 years ago by mladen@…

So was there any decision on whether to keep this functionality or not?

Changed 2 years ago by cmlenz

  • I'd prefer the option name (and the parameter) being called split_page_names to be more intuitively understandable.
  • The name splitting should be done everywhere the name is displayed, for example in timeline event titles, search results, the window title, title index, etc.
  • I assume the option defaults to false, right?

Changed 2 years ago by cboos

  • status changed from new to assigned

We just talked a bit about this on IRC, and cmlenz suggested that in order to not be inconsistent, this style of display should also be applied in other places where we show WikiPageNames (e.g. the TitleIndex, the Timeline, etc.)

So I'll update the patch and it'll probably get in when ready.

...and to answer to cmlenz who was quicker than me at saving changes:

  • ok with split_page_names
  • ...agreed, as said above
  • right, business as usual for those unaware of this nice feature :)

Changed 2 years ago by cboos

  • status changed from assigned to closed
  • resolution set to fixed
  • description modified (diff)

Implemented in r3297.

Changed 19 months ago by cboos

  • milestone set to 0.10

Add/Change #2877 (Spaces in WikiNames)

Author



Change Properties
<Author field>
Action
as closed
Next status will be 'reopened'
 
Note: See TracTickets for help on using tickets.