Module talk:Delink#Optimization of nested links

Help for writing code

{{Tmbox

| type = style

| image = 60px

| text = You used the {{Tlx|Help me}} template, but you wanted an answer from a specific editor. If you still need help, please add your question to that editor's talk page instead. Alternatively, you can ask your question at the Teahouse, the help desk, or join Wikipedia's Live Help IRC channel to get real-time assistance. Click here for instant access.}}

Hello everyone, I need help on delinking wikilinks. The current template {{tl|delink}} works like this:

Can someone with experience provide the code to make a template, let's call it X, so that

That is, how can I get the target of the wikilink instead of the label? I guess we can use Module:String, 'cause I see many string-manipulating templates are based on it but I have no knowledge about Lua, so... Thank you in advance. Tran Xuan Hoa (talk) 23:24, 10 September 2016 (UTC)

:I checked around on IRC to see if I could find someone who might be able to help you and it was suggested that I direct you to {{u|Mr. Stradivarius}}. I'm going to mark this as needing a specific user to answer. Cheers! --Cameron11598 (Talk) 05:26, 11 September 2016 (UTC)

:: {{ping|Tran Xuan Hoa}} You can use :

::* wikicode : {{#invoke:String|replace|{{{1|}}}|%[%[ *([^%[%]{{!}}]+)[^%[%]]*%]%]|%1|plain=false}}

::* lua : {{code|article = article:gsub( '%[%[ *([^%[%]|]+)[^%[%]]*%]%]', '%1' )|lua}}

:: --Zebulon84 (talk) 11:46, 24 September 2016 (UTC)

@Zebulon84: It worked. Actually I'm writing a template on my wiki. I myself was able to make up the code to achieve the same result but yours is more efficient. I will apply yours now. Thank you so much! Tran Xuan Hoa (talk) 13:39, 24 September 2016 (UTC)

Where is this line break coming from?

I am trying to delink text that starts with a pound sign (#), and I am getting unexpected results.

Foo bar {{delink|#SomethingNew}}

Biz Baz {{delink|Foo bar #SomethingNew}}

I am expecting:

Foo bar #SomethingNew

Biz Baz Foo bar #SomethingNew

Actual results:

Foo bar {{delink|#SomethingNew}}

Biz Baz {{delink|Foo bar #SomethingNew}}

In the first example, there is a line break before the pound sign. Where is the extra line break coming from in the first example?

And yes, I know that the text contains no wikilinks; I am trying to strip wikilinks from all text in a template parameter (see {{tl|YouTube/sandbox}} and :Template:YouTube/testcases#Playlist) and need to ensure that delinking does not affect unlinked text that was working fine before my changes.– Jonesey95 (talk) 06:39, 5 January 2020 (UTC)

:The module returns the correct text without a newline. However, something outside our control inserts a newline when a module returns text begining with certain characters, and one of the characters is #. See Template talk:Weather box#Spacing. Johnuniq (talk) 09:05, 5 January 2020 (UTC)

:: Additional unexpected lines are often related to parser bug {{phab|T18700}}. A before a template call can help for templates returning an HTML table.   Jts1882 | talk  09:28, 5 January 2020 (UTC)

:::This is expected behaviour and is nothing to do with tables. If the first non-whitespace character of a parameter is one of those used to generate list markup (: ; * #), then a list will be started. See H:T#Problems and workarounds. --Redrose64 🌹 (talk) 10:02, 5 January 2020 (UTC)

: {{phab|T14974}} is the bug here. Anomie 14:31, 5 January 2020 (UTC)

::Thanks, all. That's a strange one. I have added , which seems to have done the trick. – Jonesey95 (talk) 15:43, 5 January 2020 (UTC)

Handling HTML line breaks

{{edit template-protected|answered=yes}}

Hello!

On the sandbox I've made a small change which means that HTML line breaks (
,
,
, etc.) are replaced by newline characters and thus treated in the same way as normal newlines.

I've added new test cases, and it doesn't seem to have broken any existing tests.

Thanks - odg (talk) 00:25, 18 August 2020 (UTC)

:File:Red information icon with gradient background.svg Not done for now: It seems to remove newlines completely:

:{{delink/sandbox|[http://www.example.com HTML line breaks] between
two [http://www.example.com links]}}

:{{delink/sandbox|[http://www.example.com HTML line breaks] between
two [http://www.example.com links]}}

:{{delink|[http://www.example.com HTML line breaks] between
two [http://www.example.com links]}}

:{{delink|[http://www.example.com HTML line breaks] between
two [http://www.example.com links]}}

:Please try again. – Jonesey95 (talk) 02:52, 18 August 2020 (UTC)

Performance enhancement?

I have made a few changes to the /sandbox version

  1. delinkLinkClass now searches forward for the next '[' rather than one char at a time
  2. a check in _delink is made for the existence of '[' as Module:Delink is called often without any links to delink (eg 2018–19_UEFA_Europa_League_qualifying_phase_and_play-off_round_(Main_Path))
  3. in function getDelinkedLabel a check is made for the 'colon trick' - it will be the third byte or not at all

I believe this to be a helpful improvement

Desb42 (talk) 07:01, 30 April 2022 (UTC)