Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra spaces in {linkText} #99

Closed
RicardoNunoSilva opened this issue May 8, 2012 · 4 comments
Closed

Extra spaces in {linkText} #99

RicardoNunoSilva opened this issue May 8, 2012 · 4 comments
Assignees
Milestone

Comments

@RicardoNunoSilva
Copy link

@RicardoNunoSilva RicardoNunoSilva commented May 8, 2012

About the new {linkText} option in Template, I've been noticing it sometimes includes annoying leading blank spaces.

Example: I have a template like this:
{linkText}
{url}

In this page http://www.flickr.com/photos/artour_a/5211327406/
there are some links in the sidebar to the right.
Try to use the above Template to copy the link "Caterpillars of the world", and it will give you this:

                                    Caterpillars of the world
                (Álbum: 104)

http://www.flickr.com/photos/artour_a/sets/72157627461869613/with/5211327406/

I was hoping for something like:

Caterpillars of the world
(Álbum: 104)
http://www.flickr.com/photos/artour_a/sets/72157627461869613/with/5211327406/

or

Caterpillars of the world (Álbum: 104)
http://www.flickr.com/photos/artour_a/sets/72157627461869613/with/5211327406/

You may want to check this :)
Maybe you can trim all leading spaces (ie. in the start of the string)?
Thanks.

@neocotic
Copy link
Member

@neocotic neocotic commented May 8, 2012

Instead of always trimming linkText I'd prefer to provide a set of string manipulation operations that can be used in conjunction with any other variables etc. I'm surprised I haven't done this sooner.

Operations (I'm using underscores (_) in the examples to represent spaces):

  • trim
    • "__foo__" -> "foo"
  • trimLeft
    • "__foo__" -> "foo__"
  • trimRight
    • "__foo__" -> "__foo"
  • upperCase
    • "foo" -> "FOO"
  • lowerCase
    • "FOO" -> "foo"
  • length
    • "foo" -> 3
    • Not sure how useful this will be
  • capitalize/capitalise
    • "foo_bar" -> "Foo_Bar"
  • tidy
    • "__foo___bar__" -> "_foo_bar_"
    • replace(/([ \t]+)/g, ' ')
    • This will reduce all spaces and tabs into a single space

Using tidy should achieve what you're looking for;

{#tidy}{linkText}{/tidy}

What do you think?

@RicardoNunoSilva
Copy link
Author

@RicardoNunoSilva RicardoNunoSilva commented May 8, 2012

Enabling the use of "string operators" on your Template extension seems a great idea to me.
It offers more flexibility and post-processing control for end-users, while maintaining simplicity.

@neocotic
Copy link
Member

@neocotic neocotic commented May 8, 2012

I still need to work out a workaround/fix for #97 before I can add any changes as it's preventing any additions to Template. I'll concentrate on that now and then I'll get to work on this. I might change tidy so that the result is also trimmed, removing the need to wrap {tidy} in {trim}.

@neocotic
Copy link
Member

@neocotic neocotic commented May 9, 2012

This is now live in development and I'm happy with the results of testing after fixing a few bugs so I'll be including this in an update later today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.