Edgewall Software
Modify

Ticket #2877 (closed enhancement: fixed)

Opened 6 years ago

Last modified 5 years 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@…
Release Notes:
API Changes:

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 6 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 6 years ago.
Same as the other one, but for Trac 0.9.4

Download all attachments as: .zip

Change History

comment:1 Changed 6 years ago by anonymous

  • Cc mladen@… added

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

comment:2 Changed 6 years ago by cboos

  • Component changed from general to wiki
  • Keywords CamelCase WikiPageNames added
  • Priority changed from normal to low
  • 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?

comment:3 Changed 6 years ago by anonymous

  • Component changed from wiki to general
  • Priority changed from low to normal
  • 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.

comment:4 Changed 6 years ago by mladen@…

  • Component changed from general to wiki
  • Priority changed from normal to low
  • Severity changed from normal to minor

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

comment:5 Changed 6 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 6 years ago by cboos

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

comment:6 Changed 6 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?

comment:7 Changed 6 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 6 years ago by cboos

Same as the other one, but for Trac 0.9.4

comment:8 Changed 6 years ago by Mladen Mihajlovic <mladen@…>

Works very well. Thanks a lot.

comment:9 Changed 6 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)

comment:10 Changed 6 years ago by mladen@…

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

comment:11 Changed 6 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?

comment:12 Changed 6 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 :)

comment:13 Changed 6 years ago by cboos

  • Description modified (diff)
  • Resolution set to fixed
  • Status changed from assigned to closed

Implemented in r3297.

comment:14 Changed 5 years ago by cboos

  • Milestone set to 0.10
View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
to The owner will be changed from cboos. Next status will be 'closed'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.