Template:Boxcode: Difference between revisions
m (Bad idea fixed... by default, doing something different than float=none was creating dsiplacements in lot of other pages that uses this template) |
mNo edit summary |
||
Line 21: | Line 21: | ||
<nowiki>{{</nowiki>Boxcode|'''float='''right|'''title='''Custom Title|'''code='''Code Sample<nowiki>}}</nowiki> | <nowiki>{{</nowiki>Boxcode|'''float='''right|'''title='''Custom Title|'''code='''Code Sample<nowiki>}}</nowiki> | ||
<br>...or...<br> | <br>...or...<br> | ||
<nowiki>{{</nowiki>Boxcode|'''float=''' | <nowiki>{{</nowiki>Boxcode|'''float='''left|'''width='''50%|'''title='''Custom Title|'''code='''Code Sample<nowiki>}}</nowiki> | ||
<br>...or...<br> | <br>...or...<br> | ||
<nowiki>{{</nowiki>Boxcode|'''float='''right|'''width=''' | <nowiki>{{</nowiki>Boxcode|'''float='''right|'''width='''50%|'''height='''500px|'''title='''Custom Title|'''code='''Code Sample<nowiki>}}</nowiki> | ||
== Examples == | == Examples == |
Revision as of 15:20, 7 September 2021
Usage
All the parameters in bold are optional, for a good look the "code sample" should start with either a <pre> or a <syntaxhighlight>
{{Boxcode|code=Code Sample}}
...or...
{{Boxcode|title=Custom Title|code=Code Sample}}
...or...
{{Boxcode|float=right|title=Custom Title|code=Code Sample}}
...or...
{{Boxcode|float=left|width=50%|title=Custom Title|code=Code Sample}}
...or...
{{Boxcode|float=right|width=50%|height=500px|title=Custom Title|code=Code Sample}}
Examples
<code>
lines
<!--here-->
very long lines adds a horizontal scroll bar at bottom of the template to preserve the width of the wiki pages ...............................................................................................................................................................................................................................................................................................o/sup
<code>
lines
<!--here-->
very long lines adds a horizontal scroll bar at bottom of the template to preserve the width of the wiki pages
<code> lines <!--here--> very long lines adds a horizontal scroll bar at bottom of the template to preserve the width of the wiki pages
<code>
lines
<!--here-->
very long lines adds a horizontal scroll bar
<code>
lines
<!--here-->
very long lines adds a horizontal scroll bar
<code>
lines
<!--here-->
very long lines adds a horizontal scroll bar
<code>
lines
<!--here-->
very long lines adds a horizontal scroll bar
<code>
lines
<!--here-->
very long lines adds a horizontal scroll bar
<code>
lines
<!--here-->
very long lines adds a horizontal scroll bar
###############################################
<code>
lines
<!--here-->
<code>
lines
<!--here-->
- Notes:
The line wrapping inside <syntaxhighlight> and <pre> applyed when the text is longer than the container is an annoyance because it wraps the lines at the positions of the space characters (thats very bad for displaying code), by default is a lot better to display the lines entirelly and let them float "hidden" at the right of the box (thats when the horizontal scrollbar appears at bottom of the box)
It seems it can be achieved by using white-space:pre as explained in 1 and 2 but doesnt seems to work when is included inside the {{boxcode}} template (so i cant predefine it to do it automatically), another aditional problem is that it works only for <pre> but doesnt seems to work for <syntaxhighlight>. If someone knows how to implement this feature in the template (maybe with a mediawiki class ?) please do it, in the meantime the only 2 solutions i see are:
- Do the white-space:pre when calling the {{boxcode}} template, this way. {{Boxcode|title=Something|code=<pre style="white-space:pre;">code here</pre>}}
Add a long line of consecutive characters (of the same lenght of the longest code line) at the last line of the code, to force the scroll bar to appear (this is a dirty hack but is easy and solves the problem)This doesnt works, the long line is not wrapped, but all the other lines are :/