r20151202

Signed-off-by: Flashwave <me@flash.moe>
This commit is contained in:
Pachira 2015-12-02 19:15:34 +01:00
parent bf44b6b807
commit 6f08ef8236
11 changed files with 225 additions and 13 deletions

View file

@ -40,7 +40,7 @@ class BBcode
$this->bbcode->addCodeDefinitionSet(new DefaultCodeDefinitionSet()); $this->bbcode->addCodeDefinitionSet(new DefaultCodeDefinitionSet());
// Header tag // Header tag
$builder = new CodeDefinitionBuilder('header', '<h2>{param}</h2>'); $builder = new CodeDefinitionBuilder('header', '<h1>{param}</h1>');
$this->bbcode->addCodeDefinition($builder->build()); $this->bbcode->addCodeDefinition($builder->build());
// Strike tag // Strike tag
@ -48,24 +48,24 @@ class BBcode
$this->bbcode->addCodeDefinition($builder->build()); $this->bbcode->addCodeDefinition($builder->build());
// Spoiler tag // Spoiler tag
$builder = new CodeDefinitionBuilder('spoiler', '<div class="spoiler">{param}</div>'); $builder = new CodeDefinitionBuilder('spoiler', '<span class="spoiler">{param}</span>');
$this->bbcode->addCodeDefinition($builder->build()); $this->bbcode->addCodeDefinition($builder->build());
// Box tag // Box tag
$builder = new CodeDefinitionBuilder('box', '<div class="spoiler-box-container"><div class="spoiler-box-title">Click to open.</div><div class="spoiler-box-content">{param}</div></div>'); $builder = new CodeDefinitionBuilder('box', '<div class="spoiler-box-container"><div class="spoiler-box-title" onclick="toggleClass(this.parentNode.children[1], \'hidden\');">Click to open</div><div class="spoiler-box-content hidden">{param}</div></div>');
$this->bbcode->addCodeDefinition($builder->build()); $this->bbcode->addCodeDefinition($builder->build());
// Box tag // Box tag
$builder = new CodeDefinitionBuilder('box', '<div class="spoiler-box-container"><div class="spoiler-box-title">{option}</div><div class="spoiler-box-content">{param}</div></div>'); $builder = new CodeDefinitionBuilder('box', '<div class="spoiler-box-container"><div class="spoiler-box-title" onclick="toggleClass(this.parentNode.children[1], \'hidden\');">{option}</div><div class="spoiler-box-content hidden">{param}</div></div>');
$builder->setUseOption(true); $builder->setUseOption(true);
$this->bbcode->addCodeDefinition($builder->build()); $this->bbcode->addCodeDefinition($builder->build());
// Quote tag // Quote tag
$builder = new CodeDefinitionBuilder('quote', '<blockquote>{param}</blockquote>'); $builder = new CodeDefinitionBuilder('quote', '<blockquote><div class="quote">{param}</div></blockquote>');
$this->bbcode->addCodeDefinition($builder->build()); $this->bbcode->addCodeDefinition($builder->build());
// Quote tag // Quote tag
$builder = new CodeDefinitionBuilder('quote', '<h4>{option} wrote:</h4><blockquote>{param}</blockquote>'); $builder = new CodeDefinitionBuilder('quote', '<blockquote><div class="quotee">{option} wrote:</div><div class="quote">{param}</div></blockquote>');
$builder->setUseOption(true); $builder->setUseOption(true);
$this->bbcode->addCodeDefinition($builder->build()); $this->bbcode->addCodeDefinition($builder->build());
@ -96,7 +96,12 @@ class BBcode
// Get as HTML // Get as HTML
public function toHTML() public function toHTML()
{ {
return nl2br($this->bbcode->getAsHtml()); $parsed = nl2br($this->bbcode->getAsHtml());
$parsed = Main::fixCodeTags($parsed);
$parsed = Main::parseEmotes($parsed);
return $parsed;
} }
// Get as BBmarkup // Get as BBmarkup

View file

@ -19,6 +19,6 @@ class Code extends CodeDefinition
public function asHtml(ElementNode $el) public function asHtml(ElementNode $el)
{ {
return preg_replace("#\n*\[code\]\n*(.*?)\n*\[/code\]\n*#s", '<pre class="code prettyprint linenums">\\1</pre>', $el->getAsBBCode()); return preg_replace("#\n*\[code\]\n*(.*?)\n*\[/code\]\n*#s", '<pre class="code"><code>\\1</code></pre>', $el->getAsBBCode());
} }
} }

View file

@ -770,4 +770,31 @@ class Main
]); ]);
} }
// Cleaning up the contents of code tags
public static function fixCodeTags($text)
{
$parts = explode('<code>', $text);
$newStr = '';
if(count($parts) > 1) {
foreach ($parts as $p) {
$parts2 = explode('</code>', $p);
if(count($parts2) > 1) {
$code = str_replace('<br />', '', $parts2[0]);
$code = str_replace('<br/>', '', $code);
$code = str_replace('<br>', '', $code);
$code = str_replace('<', '&lt;', $code);
$newStr .= '<code>'.$code.'</code>';
$newStr .= $parts2[1];
} else {
$newStr .= $p;
}
}
} else {
$newStr = $text;
}
return $newStr;
}
} }

View file

@ -10,6 +10,15 @@
{% block title %}{{ thread.title }}{% endblock %} {% block title %}{{ thread.title }}{% endblock %}
{% block css %}
<link rel="stylesheet" href="/content/libraries/highlight.css" />
{% endblock %}
{% block js %}
<script src="/content/libraries/highlight.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
{% endblock %}
{% block content %} {% block content %}
<div class="content homepage forum viewtopic"> <div class="content homepage forum viewtopic">
<div class="content-column"> <div class="content-column">
@ -54,12 +63,12 @@
</div> </div>
<div class="clear"></div> <div class="clear"></div>
</div> </div>
<div class="post-text markdown"> <div class="post-text bbcode">
{{ post.parsed|raw }} {{ post.parsed|raw }}
</div> </div>
{% if post.poster.signature and post.signature %} {% if post.poster.signature and post.signature %}
<div class="clear"></div> <div class="clear"></div>
<div class="signature"> <div class="signature bbcode">
{{ post.poster.signature|raw|nl2br }} {{ post.poster.signature|raw|nl2br }}
</div> </div>
{% endif %} {% endif %}

View file

@ -267,7 +267,6 @@
</div> </div>
</div> </div>
</div> </div>
<script type="text/javascript" src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>
{% if not sakura.versionInfo.stable and php.self == '/index.php' and stats %} {% if not sakura.versionInfo.stable and php.self == '/index.php' and stats %}
<script type="text/javascript" src="https://sakura.flash.moe/?get={{ sakura.versionInfo.version|slice(0, 4) }}-{{ sakura.versionInfo.version|slice(4, 2) }}-{{ sakura.versionInfo.version|slice(6, 2) }}&amp;variable=true"></script> <script type="text/javascript" src="https://sakura.flash.moe/?get={{ sakura.versionInfo.version|slice(0, 4) }}-{{ sakura.versionInfo.version|slice(4, 2) }}-{{ sakura.versionInfo.version|slice(6, 2) }}&amp;variable=true"></script>
<script type="text/javascript"> <script type="text/javascript">

View file

@ -0,0 +1,73 @@
/*
* BBcode Styling
*/
@charset "utf-8";
.bbcode h1 {
text-shadow: 0 0 5px #8364A1;
color: #614390;
}
.bbcode ul {
margin-left: 2em;
list-style: square;
}
.bbcode .spoiler {
background: #000;
}
.bbcode .spoiler:hover {
background: inherit;
}
.bbcode blockquote {
border: 1px solid #9475b2;
border-bottom: 0;
border-right: 0;
background: linear-gradient(90deg, #B697d4, transparent) transparent;
margin: .5em;
}
.bbcode blockquote > .quotee {
font-weight: bold;
border-bottom: 1px solid #9475b2;
background: #B697d4;
}
.bbcode blockquote > .quote {
margin-left: .5em;
padding-bottom: .5em;
}
.bbcode a {
color: #22E;
text-decoration: none;
}
.bbcode a:hover {
color: #22E;
text-decoration: underline;
}
.bbcode a:active {
color: #E22;
text-decoration: underline;
}
.bbcode .spoiler-box-container {
border: 1px solid #9475b2;
margin: .5em;
}
.bbcode .spoiler-box-container > .spoiler-box-title {
text-align: center;
background: #B697d4;
font-weight: bold;
cursor: pointer;
padding: 4px 0;
}
.bbcode .spoiler-box-container > .spoiler-box-content {
border-top: 1px solid #9475b2;
}

View file

@ -13,7 +13,8 @@
@import url('/content/fonts/segoeui/font.css'); @import url('/content/fonts/segoeui/font.css');
@import url('/content/fonts/segoeui-light/font.css'); @import url('/content/fonts/segoeui-light/font.css');
/* Import markdown specific style */ /* Import bbcode and markdown specific style */
@import url('bbcode.css');
@import url('markdown.css'); @import url('markdown.css');
/* /*

View file

@ -203,6 +203,18 @@ function notifyRequest(session) {
notificationWatcher.send(); notificationWatcher.send();
} }
// Toggle a class on an element
function toggleClass(element, name) {
// Attempt to get the index
var indexOf = element.className.indexOf(name);
if (indexOf < 0) {
element.className += ' ' + name;
} else {
element.className = element.className.replace(name, '').trim();
}
}
// Removing all elements with a certain class // Removing all elements with a certain class
function removeClass(className) { function removeClass(className) {
// Get the elements // Get the elements

View file

@ -0,0 +1,83 @@
/*
Monokai Sublime style. Derived from Monokai by noformnocontent http://nn.mit-license.org/
*/
.hljs {
display: block;
overflow-x: auto;
padding: 0.5em;
background: #23241f;
}
.hljs,
.hljs-tag,
.hljs-subst {
color: #f8f8f2;
}
.hljs-strong,
.hljs-emphasis {
color: #a8a8a2;
}
.hljs-bullet,
.hljs-quote,
.hljs-number,
.hljs-regexp,
.hljs-literal,
.hljs-link {
color: #ae81ff;
}
.hljs-code,
.hljs-title,
.hljs-section,
.hljs-selector-class {
color: #a6e22e;
}
.hljs-strong {
font-weight: bold;
}
.hljs-emphasis {
font-style: italic;
}
.hljs-keyword,
.hljs-selector-tag,
.hljs-name,
.hljs-attr {
color: #f92672;
}
.hljs-symbol,
.hljs-attribute {
color: #66d9ef;
}
.hljs-params,
.hljs-class .hljs-title {
color: #f8f8f2;
}
.hljs-string,
.hljs-type,
.hljs-built_in,
.hljs-builtin-name,
.hljs-selector-id,
.hljs-selector-attr,
.hljs-selector-pseudo,
.hljs-addition,
.hljs-variable,
.hljs-template-variable {
color: #e6db74;
}
.hljs-comment,
.hljs-deletion,
.hljs-meta {
color: #75715e;
}

File diff suppressed because one or more lines are too long

View file

@ -62,7 +62,7 @@ if ($mode != 'f') {
$post = $thread['posts'][$_GET['p']]; $post = $thread['posts'][$_GET['p']];
// Add subject to render data // Add subject to render data
$posting['text'] = '[quote]' . (new BBcode($post['post_text']))->toEditor() . '[/quote]'; $posting['text'] = '[quote=' . (new User($post['poster_id']))->username() . ']' . (new BBcode($post['post_text']))->toEditor() . '[/quote]';
// Post editing // Post editing
} elseif ($mode == 'p' && isset($_GET['edit']) && $_GET['edit'] == $_GET['p'] && array_key_exists($_GET['p'], $thread['posts'])) { } elseif ($mode == 'p' && isset($_GET['edit']) && $_GET['edit'] == $_GET['p'] && array_key_exists($_GET['p'], $thread['posts'])) {