11<?php
22require_once __DIR__ . '/vendor/autoload.php ' ;
33
4- require_once 'Description.php ' ;
5- require_once 'Code.php ' ;
4+ require_once 'class/Description.php ' ;
5+ require_once 'class/Code.php ' ;
6+ require_once 'class/LanguageBlock.php ' ;
67
78/**
89 * Returns the DOM-Parser with custom options and the HTML-Tree
@@ -23,6 +24,10 @@ function getDOM(&$content) {
2324 return $ dom ;
2425}
2526
27+ function createTab (string &$ code , int $ index , string $ extra = 'outer ' ) {
28+ return '<div class=" ' .$ extra .' tab-content ' .($ index == 0 ? 'tc-active ' : '' ).'" data-tab=" ' .$ index .'"> ' .$ code .'</div> ' ;
29+ }
30+
2631/**
2732 * Returns the MultiCodeBlock as a whole.
2833 *
@@ -31,18 +36,17 @@ function getDOM(&$content) {
3136 *
3237 * @return string The whole MultiCodeBlock.
3338 */
34- function createFrame (array $ lang , string &$ code ) {
39+ function createFrame (array $ lang , string &$ code, string $ extra = ' outer ' , bool $ addCopy = false ) {
3540 $ size = sizeof ($ lang );
3641 $ copyIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0z" fill="none"/><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg> ' ;
3742
3843 $ return = '<div class="multicodeblock">
39- <div class="copy" title="Copy code to clipboard"> ' .$ copyIcon .'<span class="tooltip">Failed to copy!</span>
40- </div>
41- <div class="tabs">
42- <div class="tab-sidebar">
44+ ' .($ addCopy ? '<div class="copy" title="Copy code to clipboard"> ' .$ copyIcon .'<span class="tooltip">Failed to copy!</span></div> ' : '' ).'
45+ <div class=" ' .$ extra .' tabs">
46+ <div class=" ' .$ extra .' tab-sidebar">
4347 ' ;
4448 for ($ i = 0 ; $ i < $ size ; $ i ++) {
45- $ return .= '<button class="tab-button ' .($ i == 0 ? 'tb-active ' : '' ).'" data-for-tab=" ' .$ i .'"> ' .$ lang [$ i ].'</button> ' ;
49+ $ return .= '<button class=" ' . $ extra . ' tab-button ' .($ i == 0 ? 'tb-active ' : '' ).'" data-for-tab=" ' .$ i .'"> ' .$ lang [$ i ].'</button> ' ;
4650 }
4751 $ return .= '</div> ' .$ code .'</div></div> ' ;
4852
@@ -66,31 +70,46 @@ function replaceLang(string $lang) {
6670/**
6771 * Returns a single codeblock
6872 *
69- * @param DOMElement $codevariant The content of the `<codevariant>` element .
70- * @param string $code The code inside the `<codevariant >` block .
71- * @param DOMElement $description The content of the `<desc>` element .
72- * @param Parser $parser The parser object by MediaWiki
73- * @param Highlighter $h1 The highlighter object
73+ * @param string $codeTags The code inside the `<codevariant>` block .
74+ * @param DOMElement $descriptions The content of the `<desc >` element .
75+ * @param string $lang The language of the `<codevariant>` .
76+ * @param Parser $parser The parser object by MediaWiki.
77+ * @param Highlighter $h1 The highlighter object.
7478 *
7579 * @return array The codeblock as the first element and the language as the second element.
7680 */
77- function createCodeBlock (& $ code , & $ description , $ lang , Parser &$ parser , \Highlight \Highlighter &$ h1 ) {
81+ function createCodeBlock (array & $ codeTags , DOMNodeList & $ descriptions , $ lang , Parser &$ parser , \Highlight \Highlighter &$ h1 ) {
7882 if ($ lang == null ) {
7983 return array ('<span style="color: red; font-size: 700;">No Lang Attribute</span> ' , 'No lang ' );
8084 }
8185
8286 $ lang = strtolower ($ lang );
8387
84- $ code = new Code ($ code , $ lang );
85- $ desc = new Description ($ description );
86- $ highlight = $ code ->highlight ($ h1 );
88+ $ languageBlock = new LanguageBlock ($ codeTags , $ descriptions , $ lang );
89+
90+ $ return = '' ;
91+
92+ $ versions = [];
8793
88- $ isObject = true ;
89- if (!isset ($ highlight ->value )) {
90- $ isObject = false ;
94+ for ($ i = 0 ;$ i < $ languageBlock ->size ; ++$ i ) {
95+ if ($ languageBlock ->code [$ i ] === null ) {
96+ continue ;
97+ }
98+
99+ $ highlight = $ languageBlock ->code [$ i ]->highlight ($ h1 );
100+
101+ $ isObject = true ;
102+ if (!isset ($ highlight ->value )) {
103+ $ isObject = false ;
104+ }
105+
106+ array_push ($ versions , 'Version # ' .($ i + 1 ));
107+ $ return .= createTab (combineCodeDescription (($ isObject ? $ highlight ->value : $ highlight ), $ languageBlock ->getDescription ($ i ), $ parser ), $ i , 'inner ' );
91108 }
109+
110+ $ return = createFrame ($ versions , $ return , 'inner ' , true );
92111
93- return array (combineCodeDescription (( $ isObject ? $ highlight -> value : $ highlight ), $ desc , $ parser ), ( $ isObject ? replaceLang ($ highlight -> language ) : $ lang ));
112+ return array ($ return , replaceLang ($ lang ));
94113}
95114
96115/**
@@ -102,7 +121,7 @@ function createCodeBlock(&$code, &$description, $lang, Parser &$parser, \Highlig
102121 *
103122 * @return string A combined version of the code and the description with the MediaWiki syntax.
104123 */
105- function combineCodeDescription (string $ code , Description &$ desc , Parser &$ parser ) {
124+ function & combineCodeDescription (string $ code , Description &$ desc , Parser &$ parser ) {
106125 $ arr = explode ("\n" , $ code );
107126 $ size = sizeof ($ arr );
108127
0 commit comments