Jekyll Pygments Processing - highlighting

I have been fighting with Jekyll and Pygments highlighting for a while now. I have pygments installed and have generated the css file, however when I run Jekyll to generate the site, the code highlighting does not appear to generate properly.
Here is some example code I have in place for processing
{% highlight php lineos %}
/**
* Passing by reference
*
* Outputs
*
* 10 - before add() call
* 10 - after add() call
* 15 - after addref() call
*/
$a = 10;
echo $a;
add($a);
echo $a;
addref($a);
echo $a;
function addref(&$a)
{
$a += 5;
}
function add($a)
{
$a += 5;
}
{% endhighlight %}
and here is what it looks like after Jekyll builds my site.
<div class="highlight"><pre><code class="php"><span class="x">/**</span>
<span class="x"> * Passing by reference</span>
<span class="x"> *</span>
<span class="x"> * Outputs</span>
<span class="x"> *</span>
<span class="x"> * 10 - before add() call</span>
<span class="x"> * 10 - after add() call</span>
<span class="x"> * 15 - after addref() call</span>
<span class="x"> */</span>
<span class="x">$a = 10;</span>
<span class="x">echo $a;</span>
<span class="x">add($a);</span>
<span class="x">echo $a;</span>
<span class="x">addref($a);</span>
<span class="x">echo $a;</span>
<span class="x"> </span>
<span class="x">function addref(&$a)</span>
<span class="x">{</span>
<span class="x"> $a += 5;</span>
<span class="x">}</span>
<span class="x"> </span>
<span class="x">function add($a)</span>
<span class="x">{</span>
<span class="x"> $a += 5;</span>
<span class="x">}</span>
</code></pre>
</div>
As you can see Jekyll seems to be marking every line as class="x" and I am not quite sure why.
I have tried using both the liquid and jekyll from the Github repos, I have even tried using redcarpet even though it has nothing to do with the liquid template processing. I have tried just about everything I can think of but cannot seem to get this to work.
This is what it actually looks like when I view my website
http://i.stack.imgur.com/kCvLN.png
I am running the following versions.
Ruby: ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin11.4.2]
rdiscount: rdiscount (1.6.8)
redcarpet: redcarpet (2.2.2)
pygments: pygments.rb (0.2.13)
Liquid: liquid (2.4.1)
Jekyll: jekyll (0.11.2)
I have just gone as far as using a redcarpet_markdown.rb plugin and setting the configuration settings to use redcarpet2 and I set the extensions for redcarpet.
markdown: redcarpet2
redcarpet:
extensions: ["no_intra_emphasis", "fenced_code_blocks", "autolink", "strikethrough", "superscript", "with_toc_data"]
Once that was in place I changed the code highlighting to be like this
```php
/**
* Passing by reference
*
* Outputs
*
* 10 - before add() call
* 10 - after add() call
* 15 - after addref() call
*/
$a = 10;
echo $a;
add($a);
echo $a;
addref($a);
echo $a;
function addref(&$a)
{
$a += 5;
}
function add($a)
{
$a += 5;
}
```
I then tried generating the site again and I got the same result. I am not sure if this is Jekyll causing the issue or Pygments but I have been fighting with this for the last 2 days now. But I now know it is not the markdown processor.
If you have any ideas I would be more than willing to try anything.

If you want to avoid the <?php tags you can specify the Pygment option startinline
{% highlight php startinline %}
phpinfo();
{% endhighlight %}
This way it should render properly (it worked for me).

It appears you not only have to include the opening tag for the code block but with PHP you also have to include the
```php
<?php
/**
* Passing by reference
*
* Outputs
*
* 10 - before add() call
* 10 - after add() call
* 15 - after addref() call
*/
$a = 10;
echo $a;
add($a);
echo $a;
addref($a);
echo $a;
function addref(&$a)
{
$a += 5;
}
function add($a)
{
$a += 5;
}
```

Related

Razor-Pages - HTML markup

Following the answer on this post I was using #:<div class="col-md-6">
Problems
The Formatting gets all messed up:
The intellicode gets all messed up (I only deleted the paragraph on the second #:)
Also, my if (i == (Model.CellsNotStarted.Count - 1) && i % 2 != 0) won't work when using the #:; it will always go on the else. If I don't use the #: markup, and if I, for instance put all my html in a if/else instead of only the <div> tag it will work with no problems.
My question is:
Is the #: markup viable? If so, what am I doing wrong. If not what is the alternative (that does not imply putting my entire code in an if/else)
PS: I know I should not post images of code, but I wanted to show the format and syntax errors.
There are neater ways to manage conditions within your Razor code. It's difficult to provide a full example because you don't provide the full code, but you can do this, for example:
<div class="col-md-#(i+1 == Model.CellsNotStarted.Count && i % 2 ! = 0 ? "12" : "6")">
Whenever you are tempted to use a remainder operator (%) in Razor, you should also consider whether a GroupBy would be better. It most often is, as I was shown in this question: Building tables with WebMatrix
You can try to use js to set html.Here is a demo:
<div id="myDiv"></div>
<script>
$(function () {
var html = "";
if ("#(Model.CellsNotStarted != null)"=="True")
{
for (var i = 0; i <#Model.CellsNotStarted.Count; i++)
{
if (i == (#Model.CellsNotStarted.Count - 1) && i % 2 != 0)
{
html += '<div class="col-md-12">';
}
else
{
html += '<div class="col-md-6">';
}
html += i+'</div>';
}
}
$("#myDiv").html(html);
})
</script>
result:

return template interpolation within ternary operator in angular 5

How do achieve following in angular 5 template:
<h6>{{userWalletData.BTCWalletBalance ? {{userWalletData.BTCWalletBalance}} BTC = {{userWalletData.BTCWalletBalanceInFiat}} : 'Fetching balance...'}}</h6>
You can use Angular's *ngIf in the template to achieve it.
<h6 *ngIf="userWalletData.BTCWalletBalance != undefined && userWalletData.BTCWalletBalanceInFiat != undefined; else fetching_balance">{{userWalletData.BTCWalletBalance}} BTC = {{userWalletData.BTCWalletBalanceInFiat}}</h6>
<ng-template #fetching_balance><span>Fetching balance...</span></ng-template>
hope it helps!

Insert an if statement in go tmpl range

In my project, in the index.tmpl file is the range function defined: {{ range $index, $jb := .Jailbreaks }} which iterates through the Jailbreaks array.
I was wondering if there is a way to check if the $index is on a defined position. So for this I tried {{ if $index == 0 }} but on compiling I get the error
Error rendering index template: template: index.tmpl:63: unexpected "=" in operand
Do I have to define a function in the main.go file to complete this task?
I am working with this project for everyone who is wondering.
You are looking for {{ if eq $index 0 }}. See https://golang.org/pkg/text/template/#hdr-Actions and https://golang.org/pkg/text/template/#hdr-Functions.

Failed to load resource:soy template {Not all code is in Soy V 2 syntax (found file simple.soy not in Soy V2 syntax). }

I have two soy templates in my plugin one of them loads fine but other is not getting loaded with 500 Internal server error. I am attaching the error from console.
Here is the code I have:
{namespace JIRA.Templates.Impacttemplate.ImpactRow}
/**
* Render the information page for the Requirement Template.
* #param actor : string
#param impact: string
*
*/
{template .renderImpactRow}
<tr class="impact-soy" data-key="{$impact}" >
/*<td><span class="key">{$productName}</span></td>*/
<td><span class="key">{$impact}</span></td>
<td><span class="name">{$actor}</span></td>
</tr>
{/template}
Finally I could figure out the solution:
There should not be blank line after soy doc comment.
#param impact: string should be like #param impact : string
Here is the actual working code:
/**
* Render the impact.
* #param new_actor : string
* #param impact : string
*/
{template .renderImpactRow}
<tr class="impact-soy" data-key="{$impact}" >
<td><span class="key">{$impact}</span></td>
<td><span class="name">{$new_actor}</span></td>
</tr>
{/template}

errors not showing

I have an issue with my php photo upload script. When I upload a file that exceeds 2mb, it won't show that error when I click upload..yet it's there in my script..any idea why this is? For ex. I uploaded a .wma file and It was 2.38MB..that exceeds the limit..but yet it just says "file type not allowed" why didn't it show the exceeds 2mb error as well?
Here is my script:
<?php
include 'init.php';
if(!logged_in()){
header('Location: index.php');
exit();
}
include 'template/header.php';
?>
<h3>Upload Image</h3>
<?php
if(isset($_FILES['image'], $_POST['album_id'])){
$image_name = $_FILES['image']['name'];
$image_size = $_FILES['image']['size'];
$image_temp = $_FILES['image']['tmp_name'];
$allowed_ext = array('jpg', 'jpeg', 'png', 'gif');
$image_ext = strtolower(end(explode('.', $image_name)));
$album_id = $_POST['album_id'];
$errors = array();
if (empty($image_name) || empty($album_id)){
$errors[] = 'Something is missing';
} else {
if(in_array($image_ext, $allowed_ext) === false){
$errors[] = 'File type not allowed';
}
if($image_size > 2097152){
$errors[] = 'Maximum file size is 2MB';
}
if(album_check($album_id) === false){
$errors[] = 'Couldn\'t upload to that album';
}
}
if(!empty($errors)){
foreach ($errors as $error){
echo $error, '<br />';
}
} else {
// upload image
}
}
$albums = get_albums();
if(empty($albums)){
echo '<p>You don\'t have any albums. Create an album</p>';
} else {
?>
<form action="" method="post" enctype="multipart/form-data">
<p>Choose a file:<br /><input type="file" name="image" /></p>
<p>
Choose an album:<br />
<select name="album_id">
<?php
foreach ($albums as $album){
echo '<option value="', $album['id'], '">', $album['name'], '</option>';
}
?>
</select>
</p>
<p><input type="submit" value="Upload" /></p>
</form>
<?php
}
include 'template/footer.php';
?>
Thanks again for all of the patience with my probably easy posts for a lot of you more experienced programmers out there!
-TechGuy24
As per code, it should, if uploaded file size is >2mb. However, computers never make mistake but the human and thus debugging is important.
Just replace the code
if($image_size > 2097152){
$errors[] = 'Maximum file size is 2MB';
}
with debug statements
if($image_size > 2097152){
echo "in if, image size=".$image_size;
$errors[] = 'Maximum file size is 2MB';
} else {
echo "in else, image size=".$image_size;
}
This is just a first step of debugging. It may or may not fix the real cause. Let us know the output.
Edit after comment:
Put that code in the starting of the file.
echo "files<pre>";
print_r($_FILES);
echo "</pre>imgsz=".$_FILES['image']['size'];
What is the output. I guess it might include
[error] => 1
If it show error=1, Check http://php.net/manual/en/features.file-upload.errors.php
That mean your upload_max_filesize in php.ini is set to 2MB or less. As soon as person upload file bigger than that, it never reach your code as PHP reject the file by default.
To fix that, open php.ini and increase the limit of upload_max_filesize.
Edit 3 after comment
Change
if($image_size > 2097152){
to
if($_FILES['image']['error']==1){
That will fix the issue.