Ticket #1134 (reopened defect)

Opened 4 years ago

Last modified 2 years ago

section definition syntax should allow leading spaces

Reported by: EricShulman Owned by: MartinBudden
Priority: major Milestone: 2.7.1
Component: core Version:
Severity: low Keywords:
Cc:

Description

Some authors, when defining tiddler sections (using the ! heading syntax), have used leading whitespace in the heading text, like this:

! sectionname

This whitespace is included solely for readability and does not appear when the heading is rendered in the DOM. However, it is still being treated as part of the sectionname. As a result, use of

<<tiddler SomeTiddler##sectionname>>

fails to retrieve the expected section content, and it is necessary to explicitly include the leading whitespace in the section reference, like this:

<<tiddler [[SomeTiddler## sectionname]]>>

In order to omit this space from the tiddler reference and allow flexible use of leading/trailing whitespace, the following regexp -- used in TiddlyWiki.prototype.getTiddlerText() to locate a section within a given tiddler's text -- should be changed from this:

var re = new RegExp("(^!{1,6}" + section.escapeRegExp() + "[ \t]*\n)","mg");

to this:

var re = new RegExp("(^!{1,6}[ \t]*" + section.escapeRegExp() + "[ \t]*\n)","mg");

Note that the current regexp already allows (and ignores) trailing whitespace. The proposed change simply permits leading whitespace to be processed (and ignored) in the same way.

Change History

Changed 3 years ago by MartinBudden

  • owner changed from JeremyRuston to MartinBudden
  • milestone set to 2.6

Changed 3 years ago by MartinBudden

  • status changed from new to closed
  • resolution set to fixed

Fixed in changeset:11275

Changed 3 years ago by EricShulman

  • priority changed from minor to major
  • status changed from closed to reopened
  • resolution fixed deleted

Martin,

The ticket documentation seems to be missing a whole bunch of discussion and a code sample (or link to my CoreTweak?).

Unfortunately, due to this missing info, it makes it seem as if the regexp change was the only thing to do... However, this is *not* the case. As discussed with Jeremy during the conference call, the most important part of the tweak is the complete *rewrite* of store.getTiddlerText() to allow use of sections in shadows (and clean up the code a bit, too).

Please see  http://www.TiddlyTools.com/#CoreTweaks##1134 for the full function definition that should be included in the core.

-e

Changed 3 years ago by MartinBudden

Eric,

when I was doing this ticket I remembered the stuff about the sections in shadows, but since it wasn't in the ticket documentation I thought it was part of another ticket. Thanks for pointing out my error - I'll get the rest included into the core.

Martin

Changed 3 years ago by FND

  • milestone changed from 2.6 to 2.6.2

Changed 3 years ago by MartinBudden

  • milestone changed from 2.6.2 to 2.7.1

Milestone 2.6.2 deleted

Changed 2 years ago by JohnAHind

There is another "anomaly" in this code that should be considered if it is being re-written. If 'title' refers to a tiddler or to a section and the target does not exist, then either 'defaultText' or failing that null is returned. However if 'title' refers to a slice and the tiddler exists but does not have that slice, the function returns the entire text of the tiddler ignoring the 'defaultText' parameter.

I realise that fixing this risks breaking existing code particularly if it has been coded specifically to work round this anomaly, however this seems a price worth paying to regularise the behaviour (the 'defaultText' feature being actually most useful for the 'slice' case, for example to implement simple user-configuration options).

Also could I suggest that when fixing this, we should ensure that the resultant behaviour is completely consistent between slices and sections. For example, it is not clear to me that Eric's CoreTweak? would fall back to the shadow tiddler for slices in the same way as it does for sections.

Note: See TracTickets for help on using tickets.