Template:Boxcode

From PS3 Developer wiki
Revision as of 13:59, 6 September 2021 by Sandungas (talk | contribs)
Jump to navigation Jump to search
Code Sample
Edit-copy purple.svg.png
code



Usage

{{Boxcode|code=Code Sample}}
...or...
{{Boxcode|title=Custom Title|code=Code Sample}}
...or...
{{Boxcode|width=50%|title=Custom Title|code=Code Sample}}
...or...
{{Boxcode|width=50%|float=right|title=Custom Title|code=Code Sample}}
...or...
{{Boxcode|width=500px|height=500px|float=center|title=Custom Title|code=Code Sample}}

Examples

Custom Title
Edit-copy purple.svg.png
<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
width=50% float=left
Edit-copy purple.svg.png
<code>
lines
<!--here-->
very long lines adds a horizontal scroll bar at bottom of the template to preserve the width of the wiki pages
width=50% float=right
Edit-copy purple.svg.png
<code>
lines
<!--here-->
very long lines adds a horizontal scroll bar at bottom of the template to preserve the width of the wiki pages 
width=700px float=left
Edit-copy purple.svg.png
<code>
lines
<!--here-->
very long lines adds a horizontal scroll bar
width=auto float=right
Edit-copy purple.svg.png
<code>
lines
<!--here-->
very long lines adds a horizontal scroll bar
width=auto float=right
Edit-copy purple.svg.png
<code>
lines
<!--here-->
very long lines adds a horizontal scroll bar
width=350px height=200px float=right
Edit-copy purple.svg.png
<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
###############################################
width=auto height=auto float=left
Edit-copy purple.svg.png
<code>
lines
<!--here-->
width=150px height=auto float=left
Edit-copy purple.svg.png
<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|width=50%|float=right|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 :/