This may seem to defeat the purpose of a code block, but I'd like to be able to bold something within a code block. For example, if I wanted to bold the return line:
int main(void) {
**return 0;**
}
You would have to do this in HTML,
by design.
However, inside Markdown code spans and blocks, angle brackets and ampersands
are always encoded automatically.
<pre>
int main(void) {
<b>return 0;</b>
}
</pre>
This syntax should solve your problem :
```
int main(void) {
**return 0;**
}
```
Just type three backticks in the beginning of the code block and it's should work.
Related
I'm looking at the algorithm for breadth-first sorting of a binary search tree, and there is a symbol used that I cannot understand. Funny enough, Google returns zero results.
// levelorder()
// q = empty queue
// q.enqueue(root)
// while not q.empty do
// node := q.dequeue() //Referring to this
// visit(node)
// if node.left != null then
// q.enqueue(node.left)
// if node.right != null then
// q.enqueue(node.right)
What is the operation being used here? I'm quite confused by this line.
The code you posted is pseudo code, and is not intended to be valid C++.
In C++, the assignment operator is =.
In other languages such as Ada, BCPL, Cecil, Dylan, E, Eiffel, Maple, Mathematica, Modula-3, Pascal, Pliant, Sather, Simula, Smalltalk, SML, the assignment operator is :=.
GNU make also uses := for a way of assigning.
Since the code you posted is a comment, it is not intended to be valid C++.
Here is a closer representation of the code you posted in valid C++:
#include <iostream>
#include <string>
#include <queue>
//A node might look like this:
struct Node{
Node* left;
Node* right;
};
//somewhere you have a node and a root
Node* node = new Node;
Node* root = new Node;
//a visit function is called in the pseudo code you posted
void visit(Node* node){
// ... code ...
return;
}
//here is what valid C++ that is similar to the pseudo code:
void levelorder(){
//empty queue
std::queue<Node*> q;
//add the root to the queue
q.push(root);
do {
visit(node);
if (node->left != nullptr){
q.push(node->left);
}
if (node->left != nullptr){
q.push(node->right);
}
}while(!q.empty());
return;
}
//I just added this main function so the whole code snippet compiles successfully
int main(){}
:= is assignment in pseudocode.
Or ADA. But that's kinda like psuedocode anyway.
It's inside a comment (per // prefix)... it's not compilable code and doesn't mean anything in C++.
It's not a C++ operator. It is used in some languages such as Pascal to mean the same thing as what an assignment = does.
See: Assignment operator (Computer science)
I have the following code in a view:
#if (SiteSession.SubPageHelper.DisplayType == DisplayType.List)
{
Html.Partial("_SubLandingPage_List");
}
else
{
Html.Partial("_SubLandingPage_Grid");
}
and within the partials I just have a foreach loop like this:
#foreach (Product product in SiteSession.SubPageHelper.PagedProducts)
{
some html code here
}
Where PagedProducts is got from doing a .Take() on a cached list of products
Now the above code doesn't display my paged products but if I change the partial to include the at symbol remove the semi-colon:
#Html.Partial("_SubLandingPage_Grid")
It will display the products properly. Can anyone tell me what the difference between the two version are as it took me ages to figure out why the products weren't displaying
It is actually razor syntax to tell that we are starting to write c# code, if your don't put # it will be considered as plain text so you need to put # sign before writing c# code in the view and in html helper method you don't need to put semicolon in front of then it is razor syntax to write helpers this way.
For Example:
#Html.LabelFor(x=>m.SomeProperty) // here # is telling that we are writing c# statement
When you write:
#if (SiteSession.SubPageHelper.DisplayType == DisplayType.List)
{
Html.Partial("_SubLandingPage_List"); // this is wrong syntax
}
else
{
Html.Partial("_SubLandingPage_Grid");
}
the right way is to tell that this is a razor html helper and c# statement:
#if (SiteSession.SubPageHelper.DisplayType == DisplayType.List)
{
#Html.Partial("_SubLandingPage_List")
}
else
{
#Html.Partial("_SubLandingPage_Grid")
}
you can see more on razor syntax HERE
Few more links which will help you understanding razor:
http://www.asp.net/web-pages/tutorials/basics/2-introduction-to-asp-net-web-programming-using-the-razor-syntax
http://weblogs.asp.net/scottgu/asp-net-mvc-3-razor-s-and-lt-text-gt-syntax
http://weblogs.asp.net/scottgu/introducing-razor
UPDATE:
An alternative can be to use RenderPartial which will work in the if statement without putting # sign:
#if (SiteSession.SubPageHelper.DisplayType == DisplayType.List)
{
Html.RenderPartial("_SubLandingPage_List");
}
else
{
Html.RenderPartial("_SubLandingPage_Grid");
}
For understanding Difference between Html.Partial and Html.RenderPartial, visist these links:
Html.Partial vs Html.RenderPartial & Html.Action vs Html.RenderAction
http://dotnethelpers.wordpress.com/2013/06/18/difference-between-html-renderpartial-vs-html-partial-and-html-renderaction-vs-html-action-in-mvc/
http://www.em64t.net/2010/12/razor-html-renderpartial-vs-html-partial-html-renderaction-vs-html-action-what-one-should-use/
Well simply the "#" symbol instructs Razor that it have to render something. The # always expect something to print from the supplied statement.
If you don't want to use this syntax you can still render the content with minor changes in your code in loop .. look at this.
#if (SiteSession.SubPageHelper.DisplayType == DisplayType.List)
{
Html.RenderPartial("_SubLandingPage_List"); // this is wrong syntax
}
else
{
Html.RenderPartial("_SubLandingPage_Grid");
}
Html.RenderPartial will directly write it to stream and doesn't requires #.
Even if you try to write something like following
#Html.RenderPartial("_SubLandingPage_Grid")
This will give you an error as # expect something to return and Html.RenderPartial returns void
Suppose I have a really long escaped property value to input in LESS. I can get it to output with newlines in the final formatted css by setting a variable to add a newline like so #nl: `"\n"`; and use that in my escaped string to output newlines in the property value. So this:
#nl: `"\n"`;
.test {
property: ~"one,#{nl} two";
}
Will output this:
.test {
property: one,
two;
}
The question is whether there is any way to input it with newlines, something like:
.test {
property: ~"one,
two";
}
This throws a Parse error: Unrecognised input in LESS. A long set of property values like one might have with a progid:DXImageTransform.Microsoft.Matrix would benefit from being able to code it with newlines to begin with.
Though I posted an answer to my own question that I discovered worked, I'm open to a simpler one if it exists.
Well, one solution I have found is to put each line in its own escaped string. So this seems to work reasonably well for both input and output (depending on what the tab setting is):
Input LESS
#nl: `"\n\t\t\t"`;
.test {
property: ~"#{nl}"
~"one,#{nl}"
~"two";
}
Output CSS
.test {
property:
one,
two;
}
In short, no. Less does not support any kind of multiline strings (Recently this feature was proposed and rejected for various reasons). Though, speaking of IE hacks, the following code compiles fine since v1.4.2:
.rotate(#angle) {
#cos: cos(#angle);
#sin: sin(#angle);
#nsin: (0-sin(#angle));
-ms-filter: progid:DXImageTransform.Microsoft.Matrix(
M11=#cos,
M12=#sin,
M21=#nsin,
M22=#cos,
sizingMethod='auto expand'
);
}
test {
.rotate(20deg);
}
The only problem there is the combination of =, - and func() that needs some special handling.
Update,
as for the per line escaped strings example I guess the following would look a bit more clear:
#nl: ~`"\n "`;
.test {
property: #nl
~"one", #nl
~"two";
}
I am using fenced code blocks in Doxygen using the markdown syntax. This makes it easy to add a simple code example, like this:
~~~~~{.cpp}
void doSomething()
{
}
~~~~~
When I try to add comments into the fenced code block using two forward slashes, Doxygen seems to remove the slashes. So when I write this:
~~~~~{.cpp}
void doSomething()
{
// This function should do something
}
~~~~~
I get this output:
void doSomething()
{
This function should do something
}
How can I tell Doxygen to keep the comments in the fenced code block?
EDIT:
The complete file looks like this (we use the standard Doxygen extension of .dox for documentation-only files):
/*!
\page PATTERN_SAMPLE Sample
~~~~~{.cpp}
void doSomething()
{
// This function should do something
}
~~~~~
*/
The result looks like this:
Try with \code
\code{.cpp}
class Cpp {};
\endcode
I encountered the same issue. No need to change code format. You can specify STRIP_CODE_COMMENTS as NO: this setting outputs the source code with the comment.
# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any
# special comment blocks from generated source code fragments. Normal, C++ and
# Fortran comments will always remain visible.
# The default value is: YES.
STRIP_CODE_COMMENTS = NO
I know this is a fairly contentious issue amongst programmers, but when developing I like my IDE to position the opening curly bracket underneath the method/interface/control declaration, for illustrative purposes: -
This is how Xcode automatically generates skeleton methods with the { at the end: -
-(void) isTrue:(BOOL)input {
if(input) {
return YES;
}
else {
return NO;
}
}
This is how I like to lay out my code (which I believe is called the Allman style): -
-(void) isTrue:(BOOL)input
{
if(input)
{
return YES;
}
else
{
return NO;
}
}
I'm just wondering if there's any configuration switch in Xcode to enable this style of development? It's really annoying when typing out if/else statements as it tends to auto-complete the else clause with the { at the end of the line which just looks silly if you like developing with them underneath.
Or am I being unreasonable? Is Objective-C supposed to adhere to a standard defined by Apple?
Take a look at:
Xcode: Adjusting indentation of auto-generated braces?
Apple Xcode User Defaults
XCCodeSenseFormattingOptions = {
BlockSeparator = "\\n";
PreMethodDeclSpacing = "";
};
This should at least solve your problem after if, for, or while statements.
After digesting the helpful information from WhirlWind above (thanks), the resulting snippet (just cut and paste into terminal) is:
defaults write com.apple.Xcode
XCCodeSenseFormattingOptions -dict
BlockSeparator "\\n"
PreMethodDeclSpacing ""
Stupid backslash quoting. When typed at the terminal, there should be TWO exactly TWO backslashes in the block separator.
Even with those settings, it does not appear to work with the templates. If you set this and then type "init" in a .m file you get:
- (id)init
{
self = [super init];
if (self) {
<#initializations#>
}
return self;
}
Note the "if (self) {" line.
I believe that "defaults write com.apple.Xcode" doesn't work on the latest versions of Xcode (7.x)
Here are the solutions I know:
Snippet Edit -- this little program will allow to edit default Xcode's code snippets. So, you will be able to open braces from new line in your if, for, while, etc. However, this doesn't allow to change the block indentation.
Uncrustify -- this might solve your problem too, but it doesn't look like being easy to set up. And it only formats the code after it is already written, instead of formatting 'on the go'.