Jade indentation errors - javascript

So for my Express site, I'm using jade. So I decided to try modifying my layout file so I can start designing my site. I modified the original layout code (which worked), but I started getting indentation errors in any file that extends layout like this:
500 Error: /home/kevin/Blue/views/layout.jade:6 4| p Hello World Invalid indentation, you can use tabs or spaces but not both
4| p Hello World
Invalid indentation, you can use tabs or spaces but not both
at Object.Lexer.indent (/home/kevin/Blue/node_modules/jade/lib/lexer.js:679:15)
at Object.Lexer.next (/home/kevin/Blue/node_modules/jade/lib/lexer.js:777:15)
at Object.Lexer.lookahead (/home/kevin/Blue/node_modules/jade/lib/lexer.js:107:46)
at Object.Parser.lookahead (/home/kevin/Blue/node_modules/jade/lib/parser.js:115:23)
at Object.Parser.peek (/home/kevin/Blue/node_modules/jade/lib/parser.js:92:17)
at Object.Parser.tag (/home/kevin/Blue/node_modules/jade/lib/parser.js:640:22)
at Object.Parser.parseTag (/home/kevin/Blue/node_modules/jade/lib/parser.js:624:17)
at Object.Parser.parseExpr (/home/kevin/Blue/node_modules/jade/lib/parser.js:198:21)
at Object.Parser.block (/home/kevin/Blue/node_modules/jade/lib/parser.js:592:25)
at Object.Parser.tag (/home/kevin/Blue/node_modules/jade/lib/parser.js:721:26)
So the code that I have is this:
index.jade
extends layout
block content
p Hello World
and
doctype 5
html
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
body
div#header
p This is the header
block content
Keep in mind that I didn't spell anything incorrectly, and I do know how to link together files using the extends option just fine. In fact, the code worked perfectly fine until I started messing with the layout file. All of this is mostly an indention issue. I tried figuring out if it is my text editor causing the problem, and I have been unsuccessful figuring out if it is, as I can't get the code working again.
I am using the sublime text 2 editor to write this jade code. If it is the text editor not indenting correctly, could somebody help me learn how to fix it?

In the lower right-hand corner of Sublime Text, there should be a label that says Spaces: N or Tab Size: N where N is a number. Select this and you'll see options to convert the entire document's indentation to use either tabs or spaces:
Convert Indentation to Spaces
Convert Indentation to Tabs

for edit form on server.js file set variable like this
var applications = row;
res.render("edit", { applications : applications[0] });
for edit.jade file :
block content
table
thead
tr
th First Name
th Last Name
tbody
- each item in applications
tr
td= item.username
td= item.email

This answer is an extension to the answer of André Dion (I don't have enough reputation to comment on his post). One can also do the same procedure he described in Visual Studio Code Directly. If you use Pug in Visual Studio Code it will be very nice.

Related

node.js and jade: Display content from attribute value - line feeds not displaying

I am quite sure that this could be a simple question, but unfortunately I was not able to find the right answer.
What I have is a database where I have some free text in with \n\r in it for starting new lines. At the moment I am using jade as the framework. When I try to render the pages with the values from the database, the \n\r are not working, as they appear to be just characters that are not interpreted in the html source.
My jade view looks like this:
extends layout
block content
h1 #{doc.recipetitle}
h3 Zutaten:
p #{doc.ingredients}
h3 Anleitung:
p #{doc.recipe}
h3 So siehts aus:
img(src=doc.img)
My issues are with the doc.ingredients and doc.recipe, as this could be values like:
potatotes\r\nbeef\r\nwater\r\n
and it displays to:
potatoes beef water
But what I want is:
potatoes
beef
water
Is it possible to format the paragraph correctly?
You need line breaks to break to next line <br/>
You can accomplish this by doing #{your.param.replace('\r\n', '<br/>')}
(the replace statement might be different but you hopefully see the concept)

Display rich text in ExtJS component

I'm trying to display some rich text in a component with a tpl in my extjs application. I get the rich text from my database and it looks like this:
this is some example text \r\n\r\n with two line breaks
At the moment extjs just displays the text but I want it to also make the line breaks.
On the server-side I use PHP and the data then gets loaded into extjs via a direct layer.
Are there any possibilities to do this? The best thing would be if you could somehow translate the rich text to HTML.
Here is an example of my tpl:
tpl:[
'<h2>Some HTML Title</h2>'
'{RICH_TEXT}'
'<p>Some more HTML Stuff</p>'
]
Thanks in advance for your help.
EDIT:
I also encountered some cases where there is more than just some line breaks for example:
{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
{\colortbl ;\red0\green0\blue0;}
\viewkind4\uc1\pard\cf1\lang2055\b\f0\fs16 text text text\b0 , more text }
How can I handle this? If there is no possibility, how can I get rid of that stuff and just display the clear text, because this is visible in extjs.
In JS you can replace the linebreaks with br tags with the following
str = str.replace(/(?:\r\n|\r|\n)/g, '<br />');
Or, you can do this same process on the PHP side before the data is sent using the built in function nl2br: http://php.net/manual/en/function.nl2br.php

HTML tags selectively stripped out

On the results page of this quiz, when you get an answer wrong, there's explanatory text given. For some reason, html tags like <strong> are stripped out of that text, even though they display correctly everywhere else in the quiz. I've checked both js files but can't find the culprit. Any ideas?
I'm trying to add formatting in this line of Q/A js
$('#quiz-form').append('<p class="special" id="special_'+key+'" ><strong>Correct answer(s): '+answer+'</strong> '+special+'</p>');
I think you should replace the " with this " in this Q/A.js file for content
this link has list the characters which
http://www.ascii.cl/htmlcodes.htm
check this example
JS Fiddle

tinymce default applied (written) style

I'm using tinymce to edit some field in a web application.
I need to have an html result (after editing) with some specification.
For example: when I press enter tinymce create a new paragraph (that's ok, and I know this behaviour can be changed, but paragraph is ok).
What I need is a specific style to the paragraph be applied.
I saw there is the possibility to specify content_css, but this is a visual deformation of what is written in the edited html.
my need is when I press enter a paragraph with specific style (margin, alignmnent, ..) must be written directly in the edited html text.
e.g. <P style="margin-top:2px; margin-bottom:10px"> ...</P>
Is it possibile to define specific style to be applied to each html tags ?
I need this because after editing, the html content is used in another part of application, where I can not add additional style configurations.
Did you try that?
...
'content_css' : './path/to/your/styles.css',
...
styles.css
p {
margin-top:2px;
margin-bottom:10px
}
..I saw there is the possibility to specify content_css, but this is a visual deformation..
True, but don't forget that this visual deformation is extracted when you call tinyMCE.activeEditor.getContent().
Though, i'm not sure it will extract your specific styles applied to <p> (untested)
Check also here
UPDATED
Ok, i have another suggestion using HTML parsing using this.
$html = str_get_html("<div>add here your HTML from tinymce editor <p></p></div> test <p></p>");
foreach($html->find("p") as $p) {
$p->style = "margin:2px 0 10px 0";
}
$html_modified = $html;
The $html_modified should contain the <p> with margin applied.
Yes it is possible in tinymce. Just go to Tools -> Source Code of the editor toolbar. Write your HTML code with style there. You can try yourself.

How to output new lines in javascript using jsfiddle?

I am trying to learn basic javascript and using jsfiddle as my tool of choice to play around with code. I've found I really learn through working examples I can see output for.
However, I find when I do something along the lines of the following, both lines are displayed on the same line:
document.writeln("This is Line One");
document.writeln("This is Line Two");
i.e. http://jsfiddle.net/u1sonderzug/NVSsy/
I understand as a beginner I might be going about doing this in the completely wrong way, so I'd like to understand best practices.
In html, <br> is for new lines.
document.writeln("This is Line One<br>");
This is not an issue of Javascript but an issue of HTML : println adds a carriage return at the end of the text but it has no effect in HTML because html doesn't take care of those characters. So you have to to :
writeln("....<br/>");
where is the html tag for carriage return;
OR
<pre>
writeln("...");
</pre>
*if your javascript is wrotten in the html page. Where is a balise to say to html he has to read every character including the carriage return added by writeln.
Anyway you should try to find tutorials for html and DOM, it's far more powerfull that this println and it's standard :)

Categories