77
88use PHPHtmlParser \Dom ;
99
10+ /**
11+ * Returns the DOM-Parser with custom options and the HTML-Tree
12+ *
13+ * @param string $content The content that should be parsed by the DOM-Parser
14+ *
15+ * @return PHPHtmlParser\Dom The DOM-Element that has the HTML-Tree
16+ */
1017function getDOM (&$ content ) {
1118 $ dom = new Dom ();
1219 $ dom ->loadStr ($ content , getOptions ());
1320
1421 return $ dom ;
1522}
1623
17- function createFrame ($ lang , &$ code ) {
24+ /**
25+ * Returns the MultiCodeBlock as a whole.
26+ *
27+ * @param array $lang All of the languages of the different codeblocks.
28+ * @param string $code The codeblocks as a whole.
29+ *
30+ * @return string The whole MultiCodeBlock.
31+ */
32+ function createFrame (array $ lang , string &$ code ) {
1833 $ size = sizeof ($ lang );
1934 $ 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> ' ;
2035
@@ -32,13 +47,31 @@ function createFrame($lang, &$code) {
3247 return $ return ;
3348}
3449
35- function replaceLang ($ lang ) {
50+ /**
51+ * Returns a human-readable-version of the language.
52+ *
53+ * @param string $lang The specific language token
54+ *
55+ * @return string The replaced language.
56+ */
57+ function replaceLang (string $ lang ) {
3658 $ file = file_get_contents (__DIR__ . '/languages/languages.json ' );
3759 $ languages = json_decode ($ file , true );
3860
3961 return $ languages [$ lang ];
4062}
4163
64+ /**
65+ * Returns a single codeblock
66+ *
67+ * @param DOMElement $codevariant The content of the `<codevariant>` element.
68+ * @param string $code The code inside the `<codevariant>` block.
69+ * @param DOMElement $description The content of the `<desc>` element.
70+ * @param Parser $parser The parser object by MediaWiki
71+ * @param Highlighter $h1 The highlighter object
72+ *
73+ * @return array The codeblock as the first element and the language as the second element.
74+ */
4275function createCodeBlock (&$ codevariant , &$ code , &$ description , Parser &$ parser , \Highlight \Highlighter &$ h1 ) {
4376
4477 $ lang = $ codevariant ->getAttribute ("lang " );
@@ -60,7 +93,16 @@ function createCodeBlock(&$codevariant, &$code, &$description, Parser &$parser,
6093 return array (combineCodeDescription (($ isObject ? $ highlight ->value : $ highlight ), $ desc , $ parser ), ($ isObject ? replaceLang ($ highlight ->language ) : $ lang ));
6194}
6295
63- function combineCodeDescription ($ code , Description &$ desc , Parser &$ parser ) {
96+ /**
97+ * Returns the combined version of the code and the description.
98+ *
99+ * @param string $code The code inside the `<code>` element
100+ * @param Description $desc The description as a Description object
101+ * @param Parser $parser The parser object by MediaWiki
102+ *
103+ * @return string A combined version of the code and the description with the MediaWiki syntax.
104+ */
105+ function combineCodeDescription (string $ code , Description &$ desc , Parser &$ parser ) {
64106 $ arr = explode ("\n" , $ code );
65107 $ size = sizeof ($ arr );
66108
@@ -99,7 +141,14 @@ function combineCodeDescription($code, Description &$desc, Parser &$parser) {
99141 return $ return ;
100142}
101143
102- function findCodeBlocks (&$ codeblock ) {
144+ /**
145+ * Returns the code in the `<code>` tags.
146+ *
147+ * @param string $codeblock The object where all of the codeblocks should be removed.
148+ *
149+ * @return array An array of the code.
150+ */
151+ function findCodeBlocks (string &$ codeblock ) {
103152 preg_match_all ("(< *code *>((.| \n)*?)<\/code *>) " , $ codeblock , $ array );
104153
105154 return $ array [1 ];
0 commit comments