66 * file that was distributed with this source code.
77 */
88
9- require_once __DIR__ . '/vendor/autoload.php ' ;
10-
11- require_once 'class/Description.php ' ;
12- require_once 'class/Code.php ' ;
13- require_once 'class/LanguageBlock.php ' ;
14-
15- /**
16- * Returns the DOM-Parser with custom options and the HTML-Tree
17- *
18- * @param string $content The content that should be parsed by the DOM-Parser
19- *
20- * @return PHPHtmlParser\Dom The DOM-Element that has the HTML-Tree
21- */
22- function getDOM (&$ content ) {
23- $ dom = new DOMDocument ();
24-
25- $ dom ->validateOnParse = false ;
26-
27- libxml_use_internal_errors (true );
28- $ dom ->loadHTML ($ content );
29- libxml_clear_errors ();
30-
31- return $ dom ;
32- }
33-
34- /**
35- * Creates an HTML-Element to warp around the content.
36- *
37- * @param string $code The code where the Element should wrap around
38- * @param int $index The index of the element
39- * @param string $extra Another class to be added to the element.
40- *
41- * @return string The full object.
42- */
43- function createTab (string &$ code , int $ index , string $ extra = 'outer ' ) {
44- return '<div class=" ' .$ extra .' tab-content ' .($ index == 0 ? 'tc-active ' : '' ).'" data-tab=" ' .$ index .'"> ' .$ code .'</div> ' ;
45- }
46-
47- /**
48- * Returns the MultiCodeBlock as a whole.
49- *
50- * @param array $lang All of the languages of the different codeblocks.
51- * @param string $code The codeblocks as a whole.
52- * @param bool $addCopy If a copy button should be added to the element.
53- * @param string $extra Another class to be added to the element.
54- *
55- * @return string The whole MultiCodeBlock.
56- */
57- function createFrame (array &$ lang , string &$ code , bool $ addCopy = true , string $ extra = 'outer ' ) {
58- $ size = sizeof ($ lang );
59- $ 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> ' ;
60-
61- $ return = '<div class="multicodeblock">
62- ' .($ addCopy ? '<div class="copy" title="Copy code to clipboard"> ' .$ copyIcon .'<span class="tooltip">Failed to copy!</span></div> ' : '' ).'
63- <div class=" ' .$ extra .' tabs">
64- <div class=" ' .$ extra .' tab-sidebar">
65- ' ;
66- for ($ i = 0 ; $ i < $ size ; $ i ++) {
67- $ return .= '<button class=" ' .$ extra .' tab-button ' .($ i == 0 ? 'tb-active ' : '' ).'" data-for-tab=" ' .$ i .'"> ' .$ lang [$ i ].'</button> ' ;
68- }
69- $ return .= '</div> ' .$ code .'</div></div> ' ;
70-
71- return $ return ;
72- }
9+ require_once 'require.php ' ;
7310
7411/**
7512 * Returns a human-readable-version of the language.
@@ -85,51 +22,6 @@ function replaceLang(string $lang) {
8522 return $ languages [$ lang ];
8623}
8724
88- /**
89- * Returns a single codeblock
90- *
91- * @param string $codeTags The code inside the `<codevariant>` block.
92- * @param DOMElement $descriptions The content of the `<desc>` element.
93- * @param string $lang The language of the `<codevariant>`.
94- * @param Parser $parser The parser object by MediaWiki.
95- * @param Highlighter $h1 The highlighter object.
96- *
97- * @return array The codeblock as the first element and the language as the second element.
98- */
99- function createCodeBlock (array &$ codeTags , DOMNodeList &$ descriptions , $ lang , Parser &$ parser , \Highlight \Highlighter &$ h1 ) {
100- if ($ lang == null ) {
101- return array ('<span style="color: red; font-size: 700;">No Lang Attribute</span> ' , 'No lang ' );
102- }
103-
104- $ lang = strtolower ($ lang );
105-
106- $ languageBlock = new LanguageBlock ($ codeTags , $ descriptions , $ lang );
107-
108- $ return = '' ;
109-
110- $ versions = [];
111-
112- for ($ i = 0 ;$ i < $ languageBlock ->size ; ++$ i ) {
113- if ($ languageBlock ->code [$ i ] === null ) {
114- continue ;
115- }
116-
117- $ highlight = $ languageBlock ->code [$ i ]->highlight ($ h1 );
118-
119- $ isObject = true ;
120- if (!isset ($ highlight ->value )) {
121- $ isObject = false ;
122- }
123-
124- array_push ($ versions , 'Version # ' .($ i + 1 ));
125- $ return .= createTab (combineCodeDescription (($ isObject ? $ highlight ->value : $ highlight ), $ languageBlock ->getDescription ($ i ), $ parser ), $ i , 'inner ' );
126- }
127-
128- $ return = createFrame ($ versions , $ return , false , 'inner ' );
129-
130- return array ($ return , replaceLang ($ lang ));
131- }
132-
13325/**
13426 * Returns the combined version of the code and the description.
13527 *
@@ -182,16 +74,3 @@ function &combineCodeDescription(string $code, Description &$desc, Parser &$pars
18274
18375 return $ return ;
18476}
185-
186- /**
187- * Returns the code in the `<code>` tags.
188- *
189- * @param string $codeblock The object where all of the codeblocks should be removed.
190- *
191- * @return array An array of the code.
192- */
193- function findCodeBlocks (string &$ codeblock ) {
194- preg_match_all ("(< *code *>((.| \n)*?)<\/code *>) " , $ codeblock , $ array );
195-
196- return $ array [1 ];
197- }
0 commit comments