Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
Fixed double loop issue
CSS remove limit height
Add Link rendering
Add Markdown rendering
  • Loading branch information
cth-inni committed Oct 14, 2021
1 parent 58ef16f commit 084f79f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
56 changes: 55 additions & 1 deletion src/ChatBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ function __construct($newObj=null)
'image','imagecard','mp3','background','youtube','decision',
'rawscript','rawscriptquote','codeblock','link',
'narrator','profilecard',
'#','##','###','####','#####','######'
];
$this->colonList = [':',''];
$this->colonList = ['_CODEDCOLON_'];
$this->narratorList = ['Narrator','narrator','系统','旁白'];
// default setting
$oriObj = [
Expand All @@ -48,6 +49,7 @@ function __construct($newObj=null)
}
public function feed($rawData='')
{
$rawData = str_replace(['', ':'], $this->colonList, $rawData); // mass replace
$this->rawData = $rawData;
$chat['casts'] = [];
$chat['lines'] = [];
Expand Down Expand Up @@ -256,6 +258,30 @@ public function render(){
{
switch($dialogue['name'])
{
case '#': // 标题
$this->currentCast = null;
$tempHtml .= $this->md_render_heading($dialogue,1);
break;
case '##': // 副标题
$this->currentCast = null;
$tempHtml .= $this->md_render_heading($dialogue,2);
break;
case '###': // 旁白
$this->currentCast = null;
$tempHtml .= $this->md_render_heading($dialogue,3);
break;
case '####': // other purpose, keep
$this->currentCast = null;
$tempHtml .= $this->md_render_heading($dialogue,4);
break;
case '#####': // other purpose, keep
$this->currentCast = null;
$tempHtml .= $this->md_render_heading($dialogue,5);
break;
case '######': // other purpose, keep
$this->currentCast = null;
$tempHtml .= $this->md_render_heading($dialogue,6);
break;
case 'h1':
case 'h2':
case 'h3':
Expand All @@ -269,6 +295,10 @@ public function render(){
$this->currentCast = null;
$tempHtml .= $this->render_text($dialogue);
break;
case 'link':
$this->currentCast = null;
$tempHtml .= $this->render_reflink($dialogue);
break;
case 'rawscriptquote':
$this->currentCast = null;
$tempHtml .= $this->render_rawdata($dialogue,$this->rawData);
Expand Down Expand Up @@ -454,6 +484,20 @@ private function render_codeblock($dialogue)
$tempHtml = '<pre><code>'.$sentence.'</code></pre>';
return $tempHtml;
}
private function render_reflink($dialogue)
{
$sentence = $this->fn_filter($dialogue['sentence']);
$tempArray = explode("@",$sentence);
$tempHtml = '<div class="imessage">';
$tempHtml .= '<p class="narrator">';
$tempHtml .= '<img alt="svgImg" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHg9IjBweCIgeT0iMHB4Igp3aWR0aD0iMjQiIGhlaWdodD0iMjQiCnZpZXdCb3g9IjAgMCAyNCAyNCIKc3R5bGU9IiBmaWxsOiMwMDAwMDA7Ij48cGF0aCBkPSJNIDUgMyBDIDMuOTA2OTM3MiAzIDMgMy45MDY5MzcyIDMgNSBMIDMgMTkgQyAzIDIwLjA5MzA2MyAzLjkwNjkzNzIgMjEgNSAyMSBMIDE5IDIxIEMgMjAuMDkzMDYzIDIxIDIxIDIwLjA5MzA2MyAyMSAxOSBMIDIxIDEyIEwgMTkgMTIgTCAxOSAxOSBMIDUgMTkgTCA1IDUgTCAxMiA1IEwgMTIgMyBMIDUgMyB6IE0gMTQgMyBMIDE0IDUgTCAxNy41ODU5MzggNSBMIDguMjkyOTY4OCAxNC4yOTI5NjkgTCA5LjcwNzAzMTIgMTUuNzA3MDMxIEwgMTkgNi40MTQwNjI1IEwgMTkgMTAgTCAyMSAxMCBMIDIxIDMgTCAxNCAzIHoiPjwvcGF0aD48L3N2Zz4="/>';
$tempHtml .= '<a href="'.$tempArray[1].'" target="_blank">';
$tempHtml .= '<b>'.$tempArray[0].'</b>';
$tempHtml .= '</a>';
$tempHtml .= '</p>';
$tempHtml .= '</div>';
return $tempHtml;
}
private function render_text($dialogue)
{
$sentence = $this->fn_filter($dialogue['sentence']);
Expand All @@ -472,6 +516,16 @@ private function render_heading($dialogue)
$tempHtml .= '</div>';
return $tempHtml;
}
private function md_render_heading($dialogue,$headingLevel)
{
$link = $this->fn_valid_link($dialogue['sentence']);
$tempHtml = '<div class="imessage text-center">';
$tempHtml .= '<h'.$headingLevel.'>';
$tempHtml .= $dialogue['sentence'];
$tempHtml .= '</h'.$headingLevel.'>';
$tempHtml .= '</div>';
return $tempHtml;
}
private function render_image_holder($dialogue)
{
$link = $this->fn_valid_link($dialogue['sentence']);
Expand Down
2 changes: 1 addition & 1 deletion src/chatblock.css
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,6 @@
}

.rawscript-chatblock-container{
height: 30px;
/* height: 30px; */
overflow: auto;
}

0 comments on commit 084f79f

Please sign in to comment.