Template talk:Anchor

From Wikipedia, the free encyclopedia
Jump to: navigation, search


Suggestion... need examples with renderings.[edit]

This looks to be outdated and could use a face lift to make it easier to understand. A perfect example of a perfect example is Help:List-defined references#Examples. I would be happy to do it but I'm presently tied up with another article I'm working on, that is dominating my time. If anyone has time, can you please work on this? MagnoliaSouth (talk) 20:47, 28 March 2015 (UTC)

  • MagnoliaSouth: I recently made a sizable expansion to the "Examples" section of the template documentation (#5). I'd love to know if this makes the template seem easier to understand and use. Thanks! KDS4444 (talk) 21:00, 1 February 2017 (UTC)
    • KDS4444: Excellent! I apologize for my tardiness but my mother became very ill and passed away. It was much more the time domination. Anyway, I just wanted you to know that I do appreciate the changes. You did a very fine job! MagnoliaSouth (talk) 18:15, 21 September 2017 (UTC)
  • Dude... I am so sorry to hear this. I guess I don't know what your relationship with your mom was like, but whatever it was like, she was your mom and now she is gone and there is a certain pain there that... Anyhow. I am sorry to hear this. On another note, I am very glad to know you like what I did here. Sometimes I fight with whether or not other Wikipedia editors consider me to a burden rather than benefit, and maybe I should just walk away and leave well enough alone. Any expression of gratitude seems like a real rarity, so I have to thank you deeply for that. Maybe that's the nature of collaborative editing. But thank you for noticing. And for saying something. Seven months later...! KDS4444 (talk) 00:17, 22 September 2017 (UTC)

Anchors not working?[edit]

I've noticed that anchors have not been working for me several times today on different pages. I am just taken to the top of the page. Is anyone else finding this? — Martin (MSGJ · talk) 15:43, 19 October 2015 (UTC)

Examples? --Redrose64 (talk) 22:34, 19 October 2015 (UTC)
Can't find any now. Perhaps it was my browser being silly. — Martin (MSGJ · talk) 12:32, 20 October 2015 (UTC)
To MSGJ and Redrose64: Oh, I find this all over, just not 100% of the time. Happens in Firefox for Windows, bunches & bunches of version numbers back, and I stay current (with loads of add-ons and tons of tabs open). What fixes it for me is to reload while overriding the cache, which I've always found odd. Hm. I've never noticed if it only happens when opening in a new tab as opposed to the same one. Anyway, if I notice it again, I'll try to duplicate it with add-ons disabled. --Geekdiva (talk) 03:24, 18 January 2016 (UTC)
The same here. Sometimes anchors work, sometimes they do not. ATM https://en.wikipedia.org/w/index.php?title=Qt_5.6_LTS&redirect=no is not working. Firefox 45.4.0 with NoScript on + blocking "wikipedia.org". I only enable when using "HotCat", I dislike the scripts here. AFAIK anchors have nothing to do with JS, they are HTML-only. User:ScotXWt@lk 07:42, 13 October 2016 (UTC)

────────────────────────────────────────────────────────────────────────────────────────────────────@ScotXW: I examined the problem at my sandbox (permalink). The reason the anchor fails in the example you gave is that it is used in the "style" part of a cell in a table, and that displays nothing on the page, so no output from the anchor occurs. I put a solution using #Xt5.6 to show that it can work.

Johnuniq (talk) 09:42, 13 October 2016 (UTC)

@Johnuniq Thank you very much! I would not have come up with this in a 1000 years. User:ScotXWt@lk 16:07, 13 October 2016 (UTC)
You can do it without {{anchor}}, by using the id= attribute
You are limited to one id per cell. --Redrose64 (talk) 15:56, 13 October 2016 (UTC)
Interesting, thanks. Trouble is, my brain is full. Johnuniq (talk) 23:07, 13 October 2016 (UTC)

Edit request: pls add the new Category:Wikipedia section templates[edit]

Please add the new Category:Wikipedia section templates to the template. --Fixuture (talk) 01:34, 8 January 2017 (UTC)

Not done: {{edit template-protected}} is usually not required for edits to the documentation, categories, or interlanguage links of templates using a documentation subpage. Use the 'edit' link at the top of the green "Template documentation" box to edit the documentation subpage. Primefac (talk) 01:52, 8 January 2017 (UTC)

Template-protected edit request on 19 January 2017[edit]

I've copied the module into a sandbox and made the module much simpler and faster, removing all dependencies and simplifying the algorithm. Could anyone copy my sandbox to the main module? Luis150902 (talk | contribs) 09:21, 19 January 2017 (UTC)

Links to templates/modules:
Template:AnchorTemplate:Anchor/sandbox
Module:AnchorModule:Anchor/sandboxModule:Anchor/sandbox2
I temporarily disabled the edit request because I think some testing with an actual template would be needed. A quick look at Module:Anchor/sandbox2 seems to show it only gets parameters from {{#invoke:...}} whereas it needs to get the template parameters before it can work in Template:Anchor. Why was there a need set up sandbox2 rather than use Module:Anchor/sandbox? Would Mr. Stradivarius like to comment? I find Module:Arguments a bit opaque for a simple module like this, and its need to call tableTools.compressSparseArray looks like a lot of overhead although I'm sure it amounts to nothing in actual usage. Johnuniq (talk) 09:56, 19 January 2017 (UTC)
@Luis150902 and Johnuniq: I think the idea of ignoring the order of the anchors is a good one - as they are invisible and will attach to the same point in the DOM, I can't think of a drawback of changing their order. There are a few things that would break with this change, though:
  • If there are any blank arguments (e.g. the first argument in {{anchor||foo}}) then they will create spans with an empty id attribute (<span id=""></span>), which we should avoid.
  • We should be trimming whitespace from the arguments, so that {{anchor| foo }} produces <span id="foo"></span>, not <span id=" foo "></span>.
  • If there are any template transclusions with named arguments (e.g. {{anchor|foo=bar}}), then they will create anchors where none existed before.
Also, I would avoid repeating the for loop in the main and _main functions. DRY code is good code, IMO. :) Best — Mr. Stradivarius ♪ talk ♪ 01:08, 20 January 2017 (UTC)
A thought - maybe anchor order makes a difference to people editing Wikipedia with screen readers? — Mr. Stradivarius ♪ talk ♪ 14:14, 20 January 2017 (UTC)
As regards whether the anchor is placed before, within or after a section heading (remember that section headings auto-generate anchors) - it definitely makes a difference. But if the question is merely about when two anchors are placed consecutively, the order of those is immaterial. --Redrose64 🌹 (talk) 21:43, 20 January 2017 (UTC)
@Mr. Stradivarius: I have added tests for named anchors as well as for mixtures of both in my sandbox and I am now using DRY code. All 9 tests have passed. Luis150902 (talk | contribs) 16:56, 31 January 2018 (UTC)
@Luis150902: Thanks for the code update! I've added a couple more tests for whitespace-related things which aren't passing right now. You might also want to consider using the inequality operator ~= - that means you can do v ~= "" instead of not (v == ""), which is a little bit easier to read in my opinion. And if you want, you can also check whether arguments are positional by doing type(k) == "number". If this was being called from Lua then that wouldn't be enough, as you can pass in keys like 1.5; but if we assume that the module is being called from a template, then keys like those would be turned into strings. After the tests pass I think we're probably good to roll it out to the wider world. Best — Mr. Stradivarius ♪ talk ♪ 13:41, 1 February 2018 (UTC)
@Mr. Stradivarius: After the code modifications, all 12 tests have passed, including the tests you added. Luis150902 (talk | contribs) 18:30, 14 February 2018 (UTC)

Typo[edit]

In the third-from-last line under "Examples", the page has "Eurpoean". Nortonius (talk) 10:18, 17 February 2017 (UTC)

@Nortonius: fixed by Michael Bednarek. Actually, you could have fixed it yourself too, as the documentation page is not protected. Thanks for pointing it out. :) Best — Mr. Stradivarius ♪ talk ♪ 15:39, 17 February 2017 (UTC)
Aha! You're welcome, and thanks Mr. Stradivarius, I had no idea! Nortonius (talk) 15:43, 17 February 2017 (UTC)

Section heading examples[edit]

Section headings already have anchors attached to them, so they do not need additional anchors. For example, this section of the talk page will have the heading #Section_heading_examples. So, please take out examples showing use with section headings. They are unnecessary. This template would be better in tables.

Also, would it not be better for text to be included inside the anchor?

{{Anchor|anchor_name|anchor text}} that would show <span id="anchor_name">anchor text</span>. Something about empty anchors bugs me.

So please make the change to the documentation and take out the examples with headings and maybe add some text to the anchor so it will not be an empty tag. LA (T) @ 13:07, 5 January 2018 (UTC)

@Lady Aleena: This is a rather late reply, but I'm afraid you're slightly mistaken about the uses of anchors. Anchors are used in many cases where the title of a section has been changed, to preserve old links to that section (mostly in policy pages, because mainspace articles don't have that many links to individual sections.)
However, it may be worthwhile as you suggest to add table examples. E to the Pi times i (talk | contribs) 14:53, 8 April 2018 (UTC)