Add <div> on a MediaWiki geshi syntax highlight extension - php

I use mediawiki to take note about the procedure that I follow, the source codes I write in mediawiki are highlighted with the expansion Genshi Syntax HighLight. I want to modify this expansion in mediawiki so it could be created a box above the source code in which it is written the programming language I used. I tried to see expansion sources in my mediawiki but I didn't find the segment in which is "sketch" the <div>. I also saw material about the creation of new expansion in mediawiki to understand how it runs, but I don't understand where the box is created.
I use syntax hightligher like this
some_code
and this is the result in html code generate from mediawiki
<div class="mw-geshi mw-code mw-content-ltr" dir="ltr">
<div class="bash source-bash">
<pre class="de1">
some_code
</pre>
</div>
</div>
I want to prepen the div to first div, like this
<div class='gsh-lang-label'>Language bash</div>
<div class="mw-geshi mw-code mw-content-ltr" dir="ltr">
<div class="bash source-bash">
<pre class="de1">
some_code
</pre>
</div>
</div>
Can you explain me if it is possible to do it and how can I face the problem?

I think ordinary jQuery will solve this problem. Something like:
$(".mw-geshi").each(function(){
$(this).before("<div class='gsh-lang-label'>" +
$(this).children().first().attr("class").split(' ')[0] +
"</div>")
})
Put this in [[MediaWiki:Common.js]], so this script will be run for every user.

Related

php-cs-fixer doesn't indent HTML inside PHP control structures

I'm trying to use php-cs-fixer with a WordPress project, which means I (unfortunately) have files with a mix of PHP and HTML. I'm using the #PSR12 ruleset.
I'm having trouble with getting HTML within PHP control structures to indent correctly. Take this example snippet:
<?php if (!empty($related_posts)) : ?>
<div class="module--related_posts alignfull has-2-columns has-hover-state slider-on-mobile">
<h3 class="has-text-align-center">Related <?= esc_html($title) ?></h3>
</div>
<?php endif ?>
php-cs-fixer reformats it to:
<?php if (!empty($related_posts)) : ?>
<div class="module--related_posts alignfull has-2-columns has-hover-state slider-on-mobile">
<h3 class="has-text-align-center">Related <?= esc_html($title) ?>
</h3>
</div>
<?php endif ?>
Note the closing h3 tag has been moved to a new line, and the first-level indent within the if statement body has been removed.
The h3 issue I can live with, as this is resolved if I put the opening tag on its own line:
<h3 class="has-text-align-center">
Related <?= esc_html($title) ?>
</h3>
...but the lack of indent within the if statement is going to do my head in. The same thing happens with for and while statements.
Is there a rule in php-cs-fixer that I've overlooked that will resolve this?
The Answer of keradus on the "PHP code does not align with html code" issue:
PHP CS Fixer was never written with supporting mixed html/php file.
Some fixers are supporting one php part and one html part inside single file, but not big mix of them, like in template files.
If we would like to support template files, we would need to not only detect and track concrete fixers, but also provide some big integration test (like we do for Sf ruleset) that it remains to work for most important rules.
Before that happen, I would not claim that we officially support html/php mixed-files.
And in another answer:
we do not aim to fix mixed file (PHP and HTML in single file)
Not really an answer but I ended up just switching to PHP_CodeSniffer to get around this.

Blade Template HTML Coloring Issue in Atom

When I have Laravel code within the 'carrots' of the HTML element itself, all further HTML elements become discolored.
ex. <body #php language_attributes() #endphp> discolors </body>
If I use vanilla php, all is well and fine.
ALSO:
<div class="somediv"> #php language_attributes() #endphp </div>
Works fine
My hunch is that it has something to do with the "#" symbol within the HTML element. This isn't so much as an issue, as it is an annoyance!
Screenshot provided for reference.
Code Screenshot - Note the red/orange
I would try Blade templating support

WMD editor not working in edit form

I am using WMD editor. This one.
It is working fine. But issue is, i want to get it working with edit form.
Right now i am getting html instead of markdown text.
My code is like following in my edit page.
<div id="wmd-editor" class="wmd-panel">
<div id="wmd-button-bar"></div>
<textarea id="wmd-input"><?php echo $row['description']?></textarea>
</div>
<div id="wmd-preview" class="wmd-panel"></div>
<div id="wmd-output" class="wmd-panel"></div>
Not sure what is wrong here.
First off: the repository is not maintained (and apparently has not been updated for over 7 years) so you should consider switching to an active branch. WMD was renamed to Page Down but there are many alternative editors out there you can use.
As timclutton commented you are probably storing HTML in your database. WMD does not support conversion from HTML to Markdown. So the best solution would be to store the content as Markdown.
To do this change your create page. Since I have no code I'll just give you an example on how it could look:
<form action="/create" method="POST">
<div id="wmd-editor" class="wmd-panel">
<div id="wmd-button-bar"></div>
<textarea name="content" id="wmd-input"></textarea>
</div>
<div id="wmd-preview" class="wmd-panel"></div>
<div id="wmd-output" class="wmd-panel"></div>
<button type="submit">Send</button>
</form>
Server-side you can now store the content of $_POST['content'] in your database and later output it exactly the way you are doing it right now to the edit page.
Lastly a security note from the Page Down wiki:
It should be noted that Markdown is not safe as far as user-entered input goes. Pretty much anything is valid in Markdown, in particular something like <script>doEvil();</script>. This PageDown repository includes the two plugins that Stack Exchange uses to sanitize the user's input; see the description of Markdown.Sanitizer.js below.

Getting the content of a div in google translate not working

I'm trying to get the content of the div with id result_box in google translate using simple_html_dom, but it returns nothing. I tried to return another div's content and it worked perfectly. looks like the problem is just with that div.
result_box is the div that the translation will appear on.
here is my code
$googleSearch="the contente i want to translate";
$googlePage="https://translate.google.com/#en/ar/$googleSearch";
$Chtml = file_get_html($googlePage);
$gt = $Chtml->find('#result_box ',0)->plaintext;
echo '<br>'.$gt.'<br>';
What could be the cause? and how can I solve it?
If this can't be done with simple html dom, is there any alternative ways to do it?
Note that I don't want to use Google translate API
The result_box element does not have any plain text:
<div style="zoom:1" dir="ltr">
<div id="tts_button">
<span id="result_box" class="short_text" lang="en">
<span class="hps">spring</span>
</span>
</div>
I don't know what $Chtml->find('#result_box',0) is doing, but probably you need to iterate to the next <span> and get the text from there
EDIT:
Furthermore, I do not know whether the trailing blank on the Id would probably prevent simple_hmtl_dom from finding anything:
$Chtml->find('#result_box ',0) vs. $Chtml->find('#result_box',0)

Getting unstyled text using QueryPath in PHP

I'm just getting to grips with QueryPath after using HTML Simple Dom for quite some time and am finding that the QP documentation doesn't seem to offer much in the way of examples for all of its functions.
At the moment I'm trying to retrieve some text from a HTML doc that doesn't make much use of ID's or Classes, so I'm a little outside of my comfort zone.
Here's the HTML:
<div class="blue-box">
<div class="top">
<h2><img src="pic.gif" alt="Advertise"></h2>
<p>Some uninteresting stuff</p>
<p>More stuff</p>
</div>
</div>
<div class="blue-box">
<div class="top">
<h2><img src="pic2.gif" alt="Location"></h2>
**I NEED THIS TEXT**
<div style="margin:stuff">
<img src="img3.gif">
</div>
</div>
</div>
I was thinking about selecting the class 'box-blue' as the starting point and then descending from there. The issue is that there could be any number of box-blue classes in the HTML doc.
Therefore I was thinking that maybe I should try to select the image with alt="Location" and then use ->next()->text() or something along those lines?
I've tried about 15 variations os far and none are getting the text I need.
Assistance most appreciated!
Can you have a look to this example http://jsfiddle.net/Pedro3M/mujtk/
I made like you said using the alt attribute, if you confirm if this is always unique
$("img[alt='Location']").parent().parent().text();
How about:
$doc->find('div.top:has(img[alt="Location"])')->text();

Categories