Template talk:Hc

From ArchWiki
Jump to: navigation, search

hc breaks in lists

  • test
what

--Larivact (talk) 08:38, 13 August 2018 (UTC)

I remember a longish discussion about this, but cannot find it... Basically the problem is the line break denoted as <!-- The line break is needed, otherwise the wiki will generate extraneous paragraphs inside the 2nd pre block --> in Template:hc. To make the problem more readable, note that using <pre> tags twice without a line break between them is not consistent:
line1
line2
line3

line1 line2

line3

Vs.

line1
line2
line3
line1
line2
line3
And of course if there is a line break in a template, it terminates the list item started by *, #, ; or :...
-- Lahwaacz (talk) 09:07, 13 August 2018 (UTC)
Great, so it's an ancient MediaWiki bug. I'll try to come up with a solution in my sandbox but it's probably not possible without fixing MediaWiki.--Larivact (talk) 09:12, 13 August 2018 (UTC)
That was a tough nut to crack, behold User:Larivact/sandbox/hc! --Larivact (talk) 09:48, 13 August 2018 (UTC)
Awesome, good work! I've applied the fix, but please take a look at a couple of pages using this template if it really looks as intended. -- Lahwaacz (talk) 14:23, 13 August 2018 (UTC)
If output starts on a new line then there is now an empty line before it. See example below. -- nl6720 (talk) 14:48, 13 August 2018 (UTC)
{{User:Larivact/sandbox/hc|headerline|
outputline1
outputline2
}}
headerline
outputline1 outputline2
Shame, let's revert the fix until we fix this... -- Lahwaacz (talk) 15:08, 13 August 2018 (UTC)
Managed to fix it, but the new approach breaks on the seldomly used multi-line heads. List of sections using multiline heads:
A better solution would be stripping leading newlines and replacing line breaks with <br> tags. This would however require some extension (possibly mw:Extension:StringFunctions). I tried using mw:Template:Trim but that doesn't work for input starting with a list marker because of another MediaWiki quirk. --Larivact (talk) 17:51, 13 August 2018 (UTC)
Compared to the original problem (using <pre> tags twice without a linebreak between them), using <code> tags immediately followed by <pre> tags just moves the inconsistency from the second tag into the first:

code: 1 2 3

code + pre: 1 2

3
a
b
c

pre + pre:

1
2
3
a

b

c
So stripping leading/trailing newlines would not solve the problem.
-- Lahwaacz (talk) 05:57, 18 August 2018 (UTC)
Yes, that's what I meant by "breaks on the seldomly used multi-line heads". Replacing all newlines with <br> however appears to completely solve the <pre> problem:
line1
line2
line3
line1
line2
line3
and would also allow for:
* {{bc|one
two
three}}
to work as intended. --Larivact (talk) 07:38, 18 August 2018 (UTC)
Replacing all newlines with <br> tags is not possible because the template arguments might contain e.g. <nowiki> tags and <br> tags don't work inside <nowiki> tags. You would have to write a custom MediaWiki markup parser in whatever scripting language the wiki provides in order to do the replacement correctly, but in that case you're better off fixing the official parser itself... -- Lahwaacz (talk) 11:53, 18 August 2018 (UTC)
You're right I didn't consider that. We could however use my first approach (a single <pre> containing a <hr>) combined with a Lua function that strips the first character of the body if it's a newline. --Larivact (talk) 12:54, 18 August 2018 (UTC)
I don't think so - Lua functions/modules are invoked using the same syntax as parser functions or normal templates, so it would have the same problem with ;:#* as the User:Larivact/sandbox/trim template. The thing is that if the core markup language sucks, combining it with a programming language for templates doesn't change the overall experience. -- Lahwaacz (talk) 13:12, 18 August 2018 (UTC)
Yes we would have the same problem, but with a programming language we can circumvent the problem by replacing the first ;:#* occurrence with the respective HTML entity. I managed to come up with a demo: w:Module:Sandbox/Larivact/test. --Larivact (talk) 14:57, 18 August 2018 (UTC)
I just realized that we can just use list HTML tags:

Source:

<ol>
<li>{{hc|one|
two
three
}}
</li>
</ol>

Output:

  1. one
    two
    three
    
This also comes with the advantage that the wikicode is more readable as it can stretch mutiple lines. Closing this. --Larivact (talk) 08:22, 30 August 2018 (UTC)