@Reticence:
I hope you aren't too scared of PHP.
So this is the messy part. I want to rewrite this into a proper stylesheet and just parse it instead of the current scheme. Sadly, Quicktopic doesn't allow us for adding proper stylesheets, inline styles is all we get.
So this is it. On the bottom of this mess is a list of rules, plus what to do with those rules.
Code:
/***
* IMAGE style
* Syntax: |filename.png|
***/
$IMAGE_STYLE = <<<EOD
display: flex;
display: -webkit-flex;
display: -moz-box;
align-items: center;
EOD;
$IMAGE_ATTRIB = <<<EOD
EOD;
$IMAGE_REPLACE = function ($match)
{
$image = $match[1];
$imageDim = getImageSize($image) or array(0,0);
$retval = <<<EOD
<b style=
"
display:block;
background-size: contain;
background-repeat: no-repeat;
width: {$imageDim[0]}px;
height: {$imageDim[1]}px;
background-image: url('{$image}');
"
></b>
EOD;
return $retval;
};
/***
* SECTION style
* Syntax: ### Headertext
***/
$SECTION_STYLE = <<<EOD
border: 1px solid black;
background-color: #D3D3FC;
padding: 1em;
margin-bottom: 5px;
width:700px;
font-family:'Verdana'
EOD;
$SECTION_ATTRIB = <<<EOD
onmouseover= "this.style.backgroundColor='#E3E3FE';"
onmouseout= "this.style.backgroundColor='#D3D3FC';"
EOD;
$SECTION_REPLACE = <<<EOD
<b style="float:right; color:gray">$1</b>
EOD;
/***
* ICON style
* Syntax: [symbol tooltip]
* The symbol may be a character or an image.
***/
$ICON_STYLE = <<<EOD
display: flex;
display: -webkit-flex;
display: -moz-box;
align-items: center;
EOD;
$ICON_ATTRIB = <<<EOD
EOD;
$ICON_REPLACE = function($match)
{
$image_or_symbol = $match[1];
$tooltip = trim($match[2]) or "";
if(preg_match("/http[s]?:\/\//", $image_or_symbol))
{
// it's an image.
$tooltiplevel = 0;
$imageDim = getImageSize($image_or_symbol) or array(0,0);
$retval = <<<EOD
<u style=
"
display:block;
background-size: contain;
background-repeat: no-repeat;
width: {$imageDim[0]}px;
height: {$imageDim[1]}px;
background-image: url('{$image_or_symbol}');
margin-bottom: 2px;
margin-right: 4px;
border-radius: 6px;
border: 3px solid gray;
color:white;
background-color:black;
text-decoration:none;
text-align: center;
"
EOD;
} else {
// it is text
$tooltiplevel = 1;
$retval = <<<EOD
<u style=
"
display: block;
width: 32px;
height: 32px;
margin-bottom: 2px;
margin-right: 4px;
border-radius: 6px;
border: 3px solid gray;
color:white;
background-color:black;
text-decoration:none;
text-align: center;
"
EOD;
}
// add tooltip mouseover if supported
if($tooltip != "")
{
$retval .= <<<EOD
onmouseover= "this.getElementsByTagName('b')[$tooltiplevel].style.display='block';"
onmouseout= "this.getElementsByTagName('b')[$tooltiplevel].style.display='none';"
EOD;
}
$retval .= ">";
if(!preg_match("/http[s]?:\/\//", $image_or_symbol))
{
// add a content box. This is only used if symbol mode, but made anyway. Deal.
$retval .= <<<EOD
<b style=
"
font-size: 180%;
font-weight: normal;
"
>
$image_or_symbol
</b>
EOD;
}
// add tooltip box
if($tooltip != "")
{
$retval .= <<<EOD
<b style=
"
position: absolute;
margin-top: 35px;
border-radius: 6px;
border: 3px solid gray;
padding:0.4em;
background-color: black;
color:#cfcfcf;
display:none;
text-align:left;
z-index:1
"
>
$tooltip
</b>
EOD;
}
$retval .= "</u>";
return $retval;
};
/***
* HEADLINE:
* Style: *Bold text*
***/
$HEADLINE_STYLE = <<<EOD
EOD;
$HEADLINE_ATTRIB = <<<EOD
EOD;
$HEADLINE_REPLACE = <<<EOD
<b style="display: block; font-size: 130%; margin-bottom: 4px;">$1</b>
EOD;
/***
* DEFAULT TEXT
* Style: Anything that didn't match anything else
***/
$DEFAULT_TEXT_STYLE = <<<EOD
margin-top: 5px;
margin-bottom: 5px;
EOD;
// These are the transformation rules imposed by the parse() function.
// Technically not part of the stylesheet themselves, but to show how this hangs together.
// The first element is a regex. It works alongside second and fourth parameters but doesn't do anything alone.
// The second element is a style. If present, the matching container (preg_match) will be sybject to this style.
// The third element is an attribute. If present, it will be added to the container tag. Useful for JS event triggers.
// The fourth element is a replacement string OR closure. If present, tags matching (preg_replace/preg_replace_callback) will be substituted.
// - This replacement string is usually used to add additional tags before or around the actual content.
// The fifth parameter is whether the engine should inset an additional DIV tag to hold the content.
// - Ideally (but not currently) merged for several nested layers of inset divs so that only the innermost one is added.
$ruleset = array
(
array("/###(.*)/u", $SECTION_STYLE, $SECTION_ATTRIB, $SECTION_REPLACE, 0),
array("/\*(.+)\*/u", $HEADLINE_STYLE, $HEADLINE_ATTRIB, $HEADLINE_REPLACE,0),
array("/\[([^ \]]*)(.*?)\]/u", $ICON_STYLE, $ICON_ATTRIB, $ICON_REPLACE, 1),
array("/(?<!url\(')(http[s]?:\/\/.*?\.(?:png|gif|jpg|jpeg|PNG|GIF|JPG))/u", $IMAGE_STYLE, $IMAGE_ATTRIB, $IMAGE_REPLACE, 1),
);