What is that i should write to convert this to haml
When I tried like this
%p
We prefer questions that can be
%b answered
. not just discussed.
I got Illegal element: classes and ids must have values error.
IS there any way i can get the dot not bolded.
This should work:
%p
We prefer questions that can be
<b>answered</b>. not just discussed.
Edit
As #mark pointed out below the reason you were receiving the error was because if a line starts with a . haml is expecting a class name in order to render a div with that class.
\.
escapes the .
Mark's answer is still going to be the best, for readability.
You could do this in pure HAML by using the > operator on the b tag to remove surrounding spaces. However, you'd need to insert a non-breaking space before the bold word to keep it separate.
%p
We prefer questions that can be
%b> answered
\. not just discussed.
You need to escape the leading period as it's evaluating it as a div with a class.
%div.my_class
==
.my_class
==
<div class='my_class'></div>
%p
We prefer questions that can be
%b answered
\. not just discussed.
Related
How can I select a XPath that contains a text with both quote & comma character?
I have to find an element if the text contains =Yes, It's OK
My XPath does not save in ranorex tool even though if i put the text inside the double quotes like below
//span[text()="Yes, It's OK"]
So how can I save this xpath that uses "".in Ranorex
your use of double-quotes is correct. if
//span[text()="Yes, It's OK"]
doesn't match, it might be because the xpath engine has a lowercase bug (i have encountered PHP+DOMXPath+libxml2 systems where it would only match lowercase text even for text with uppercase characters, never quite figured out the problem there), or it might be because the text has hidden whitespace you're not aware of, maybe it actually has a hard-to-spot whitespace at the start or the end? anyway maybe contains() will work:
//span[contains(text(),"Yes, It's OK"]
or.. if it has the lowercase-issue i have encountered in the wild once before, maybe this will work:
//span[contains(text(),"yes, it's ok"]
(that really shouldn't be required, but i have been in that situation once before, and that was years ago, and that was... probably php5)
I noticed while experimenting with tr///, that it doesn't seem to translate backslashes, even when escaped. For example,
say TR"\^/v"." given 'v^/\\';
say TR"\\^/v"." given 'v^/\\';
say TR"\ ^/v"." given 'v^/\\';
All of them output ...\ rather than what I expected, ....
There's some other weird behaviour too, like \ seemingly only escaping lowercase letters, but the docs page doesn't have much information... What exactly is the behaviour of backslashes (\) in transliteration (tr///)?
There is a bug caused by backslashes getting swallowed instead of correctly escaping things in the grammar for tr///.
say TR/\\// given '\\'
===SORRY!=== Error while compiling:
Malformed replacement part; couldn't find final /
at line 2
------> <BOL>⏏<EOL>
I have raised https://github.com/rakudo/rakudo/issues/2456 and submitted https://github.com/rakudo/rakudo/pull/2457 which fixes it.
The second part of the answer is that Perl 6 tries quite hard in some quoting constructs to only interpret \ as an escape for valid escape sequences, i.e. \n, \r, \s, \', etc. Otherwise it is left as a literal \.
I do not have an explanation for the observed problem. However, when you use the Perl 6 Str.trans method it looks like it's working as expected:
say 'v^/\\'.trans( "\\^/v" => "." );
Outputs:
....
Reference:
https://perl6advent.wordpress.com/2010/12/21/day-21-transliteration-and-beyond/
I know there are a lot of resources with regex for it. But I could not find the one I want.
My problem is:
I want to remove one line comments (//) from obj-c sources, but I don't want to break the code in it. For instance, with this regex: #"//.*" I can remove all comments, but it also corrupts string literal:
#"bsdv//sdfsdf"
I played with non-capturing parentheses (?:(\"*\")*+), but without success.
Also I found this expression for Python:
r'(\".*?\"|\'.*?\')|(/\*.*?\*/|//[^\r\n]*$)'
It should cover my case, but I've not figure out how to make it work with obj-c.
Please, help me to build proper regex.
UPDATE: Yeah, that's a tough one, I know there're a lot of caveats, other than the one I described. I would appreciate if someone post regex that only fix my issue. Anyway, I gonna post my solution, without regex soon, I hope it will be helpful for anyone who struggling with such problem too.
Try this regex:
(?:^|.*;(?!.*")|#(?:define|endif|ifn?def|import|undef|...).*)\s*(//[^\r\n]+$)
Demo
http://regex101.com/r/jT4xC8
Description
Discussion
Besides all the warnings expressed in the comments, I assume that a single line can appear in two distinct cases:
Case 1: Alone on its line preceded or not by blank chars
Case 2: Not Alone on its line preceded or not by blank chars, and other chars.
In the first case, we match the beginning of the line (^ with /m flag). Then we search zero or more blank chars (\s*) and finally the single line comment: //[$\r\n]+$.
In the second case, if there are other chars on the line, they form statements. Any statement is ended by a semicolon ;. So we search the last statement and its corresponding semicolon .*;(?!.*"). Then we search the single line comment. Those other chars can be also preprocessor statements. In this case, they are introduced by a sharp #.
One important keypoint is that I assume the code passed to the regex is a code that compiles.
There is more
Don't forget also to add some other pre-processor directives that may apply in your case. Check this SO answer: https://stackoverflow.com/a/18014883/363573
How would you represent this in HAML?:
<a>Link</a> | <a>Link</a>
Note that I want to retain the spaces on either side of the bar.
I would write exactly what you've written, which is perfectly valid HAML. You may embed regular HTML into HAML:
%h1
<a>Link</a> | <a>Link</a>
Sometimes whitespace bites you when you're marking things up with HAML, and there is no pretty way of making your tags come out correctly. That is why HAML gives you the option of falling back to HTML.
Note that, if you're ok with one or more spaces between your links and the |, you can just write regular old HAML:
%h1
%a link
|
%a link
The new lines will be preserved, and render as a space in the browser, where any amount of any kind of whitespace will always be treated like a single space.
Put '|' on next line, new line will be preserved, and render as a white space.
%a link
|
%a link
meagar's answer is how I would do it, you could also use haml filters to write exactly the HTML you need.
This might sound dirty, but filters use is encouraged, see this article : http://chriseppstein.github.io/blog/2010/02/08/haml-sucks-for-content/
When I'm saying:
%p= item.price + " dollars"
I'm getting
50  ;dollars
instead of having non-breakable space symbol.
How to insert this and another special symbols using HAML ?
How about
%p= item.price + " dollars".html_safe
Use != instead of =
See "Unescaping HTML" in the haml reference: http://haml.info/docs/yardoc/file.REFERENCE.html#unescaping_html
The interpolation option:
%p= "#{item.price} dollars".html_safe
I tried using html_safe in different ways, but none worked. Using \xa0 as suggested by ngn didn't work, either, but it got me to try the Unicode escape of the non-breaking space, which did work:
"FOO\u00a0BAR"
and .html_safe isn't even needed (unless something else in the string needs that, of course).
The Ruby Programming Language, first edition, says: "In Ruby 1.9, double-quoted strings can include arbitrary Unicode escape characters with \u escapes. In its simplest form, \u is followed by exactly four hexadecimal digits ..."
This answer is for a slightly different question but I found this question searching for it...
If you have a submit tag %input{ :type => "submit", :value => " dollars", :name => "very_contrived" } even if you throw an html_safe on the :value it will not evaluate the html.
The solution is to use the rails helper... duh
= submit_tag " dollars".html_safe
this is pretty obvious but it tripped me up. Legacy code + rails upgrade = this kind of stuff :P
You could use \xa0 in the string instead of . 0xa0 is the ASCII code of the non-breaking space.
I prefer using the character itself with the escaped HTML method with most symbols other than the whitespace characters. That way i don't have to remember all the html codes. As for the whitespace characters i prefer to use CSS, this is a much cleaner way.
%p&= "#{item.price} $%&#*#"