Embedding ruby into HAML without flanking/preceding 'tags' - haml

My ruby code shows up (and renders as 'Hello World', which is what's in the database), when I type:
%p= #task.notes
But when I try it this way rails breaks (NoMethodError in Tasks#index):
%p= Some text before code #task.notes
When I try this it just shows me literally what I typed (Some text before code = #tasks.notes):
%p Some text before code = #task.notes
When I try this it also just shows me literally what I typed (Some text before code %= #task.notes):
%p Some text before code %= #task.notes
When I try this it once again just shows me literally what I typed (Some text before code =#task.notes):
%p Some text before code =#task.notes
But when I try this it works (Some text before code Hello World), but seems really odd that there is no way to just put the code in right next to the text:
%div
Some text before code
= #task.notes
But when I try this I get an error (Haml::SyntaxError in Tasks#index):
%div Some text before code
= #task.notes
I don't understand the logic of what is going on here and why I'm being forced to incorporate all these apparently meaningless returns in order to just produce the code I want next to some text. Can somebody fill me in on how I can just include some ruby code next to some text without having to incorporate all these carriage returns? Or is this just the way Haml is?

You can interpolate the code:
-# No =
%p Some text before code #{#task.notes}

Related

How do I replace part of a string with a lua filter in Pandoc, to convert from .md to .pdf?

I am writing markdown files in Obsidian.md and trying to convert them via Pandoc and LaTeX to PDF. Text itself works fine doing this, howerver, in Obsidian I use ==equal signs== to highlight something, however this doesn't work in LaTeX.
So I'd like to create a filter that either removes the equal signs entirely, or replaces it with something LaTeX can render, e.g. \hl{something}. I think this would be the same process.
I have a filter that looks like this:
return {
{
Str = function (elem)
if elem.text == "hello" then
return pandoc.Emph {pandoc.Str "hello"}
else
return elem
end
end,
}
}
this works, it replaces any instance of "hello" with an italicized version of the word. HOWEVER, it only works with whole words. e.g. if "hello" were part of a word, it wouldn't touch it. Since the equal signs are read as part of one word, it won't touch those.
How do I modify this (or, please, suggest another filter) so that it CAN replace and change parts of a word?
Thank you!
this works, it replaces any instance of "hello" with an italicized version of the word. HOWEVER, it only works with whole words. e.g. if "hello" were part of a word, it wouldn't touch it. Since the equal signs are read as part of one word, it won't touch those.
How do I modify this (or, please, suggest another filter) so that it CAN replace and change parts of a word?
Thank you!
A string like Hello, World! becomes a list of inlines in pandoc: [ Str "Hello,", Space, Str "World!" ]. Lua filters don't make matching on that particularly convenient: the best method is currently to write a filter for Inlines and then iterate over the list to find matching items.
For a complete example, see https://gist.github.com/tarleb/a0646da1834318d4f71a780edaf9f870.
Assuming we already found the highlighted text and converted it to a Span with with class mark. Then we can convert that to LaTeX with
function Span (span)
if span.classes:includes 'mark' then
return {pandoc.RawInline('latex', '\\hl{')} ..
span.content ..
{pandoc.RawInline('latex', '}')}
end
end
Note that the current development version of pandoc, which will become pandoc 3 at some point, supports highlighted text out of the box when called with
pandoc --from=markdown+mark ...
E.g.,
echo '==Hi Mom!==' | pandoc -f markdown+mark -t latex
⇒ \hl{Hi Mom!}

Is there a way to force line-breaks in pdf acro fields?

As the title states, I am currently struggling to force line-breaks ("\n" respectively "\r\n") in a pdf-acro-field. I am using OpenPdf and FlyingSaucer (see dependencies for details) and managed to enable multi-line and rich-text of fields by setting the bit-flags 13 and 26 of the "Ff" property.
I was using the PDF-Reference ISO-3200_2008 as a guide (starting on page 442).https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/PDF32000_2008.pdf
Issue
I read an existing PDF and fill the acro fields programmatically. Something like this:
acroFields.setField("address", content);
The content is just a simple string with some newline characters. Nothing special.
My text is too long and will have to break at some point. When multiline is enabled, the text will break, but only if it reaches the end of the line. Basically, what I want to display is something like an address and some additional information on top. But not all lines are equal in size and for example I want to have information 1 and 2 on the same line and info 4 and 5 each on separate lines.
What I had in mind
<h2>What I want</h2>
<pre>Company XYZ
A brand here</pre>
<pre>Another Section
With some more info that goes further to the right
phone, email, website</pre>
<br>
<h2>What it looks like</h2>
<p>Company XYZ
A brand here
Another Section
With some more info that goes further to the right
phone, email, website</p>
Questions
Is there a way to implement line-breaks in PDF in general?
Is there a way to implement line-breaks programmatically?
Can I do this in OpenPdf or FlyingSaucer?
If there is no simple way - what would be a viable workaround?
Dependencies
compile group: 'com.github.librepdf', name: 'openpdf', version: '1.3.3'
compile group: 'com.googlecode.juniversalchardet', name: 'juniversalchardet', version: '1.0.3'
compile 'org.xhtmlrenderer:flying-saucer-core:9.1.18'
compile 'org.xhtmlrenderer:flying-saucer-pdf-openpdf:9.1.18'
It did not work, because the content (input coming from parsed html file) had \r\n in it, but somehow it does only work with \n so I did the following:
content.replaceAll("\\\\r\\\\n", Chunk.NEWLINE.getContent()); // 2nd param is just "\n"
This fixed my issue.

Find and Replace script for textWrangler

I'm trying to make a script that will find and replace some xml structure.
I've made it all flat, no spaces, no return.
So far I've made :
tell application "TextWrangler"
replace text "<key>amenity</key><string>drinking_water</string>" using text "<key>ico</key>
<string>NPpotableGPS30</string>"
end tell
The script editor says :
Error in TextWrangler : text "<key>amenity</key><string>drinking_water</string>" don't have the message « replace ».
This is my first script so I'm probably doing something wrong, but what ?
The key "text" seems to be misplaced. The following appears to correctly work (the sequence from searching onwards being optional for defining the document to process, according to actual working situation):
tell application "TextWrangler"
replace "<key>amenity</key><string>drinking_water</string>" using "<key>ico</key><string>NPpotableGPS30</string>" searching in text 1 of text document "..." options {search mode:grep, starting at top:true}
end tell

busybox httpd cgi doesn't print "return"

Please help, I can't find the solution
Situation. I have busybox httpd server. In cgi-bin folder is an cgi-executable, which sends to client formatted text by printf command.
Problem is that the text format should look like a column, but client receives only a string. Despite the fact that in "printf" I use "\n" and "(char) 13".
Another words executable doesn't return "return" symbol
I wrote following
for (i=0; i<4;i++)
printf ("%9.8g%c\n", lTemp[i]*dTemp[i], (char) 13 );
The text that is sent from your CGI program to the web client is treated as HTML text, not plain text.
When HTML is processed for display in the browser, newline and carriage return (what you simply call "return") characters are ignored.
To cause the displayed text to perform a line break, the HTML break tag, "< br />" should be inserted into the output string:
printf("%9.8g <br />\r\n", lTemp[i] * dTemp[i]);
The use of newlines and whitespace in the text that your CGI programs generates will have little bearing on the actual HTML page that gets displayed. Use newlines and whitespace to format the HTML so that the source is readable, and use HTML tags to control the displayed text in the client's browser.
BTW
Using a numeric constant and a character conversion in a printf is not the preferred method of outputting a carriage-return character.
Use the defined escape sequence \r in the format.

multiline code block in markdown adds unwanted tabs

today I'm implementing my page in nanoc (haml templates) and I wanted to write some posts in markdown, but when it goes to multiline code blocks something weird is happening - second line in code block has additional tabs. I've tried multiple markdown syntaxes, such as:
//double tab wrapping
line 1 is fine
line 2 is wrapping (don't know why!)
and
~~~
//tilde code wrapping
line 1 is fine
line 2 is wrapping
~~~
And both solutions gives me the result something like this:
line 1 is fine
line 2 is wrapping
Inspecting elements through browser shows that there is no additional padding - this whitespace is made with tabs for sure.
Can someone help me with this? Maybe I'm doing something wrong?
When you use = in Haml to include the results of a script, Haml will re-indent the inserted text so that it matches the indentation of where it is included. For example, if you have Haml that looks something like this:
%html
%body
.foo
= insert_something
and insert_something returns some HTML like this:
<p>
This is possily generated from Markdown.
</p>
then the resulting HTML will look like this:
<html>
<body>
<div class='foo'>
<p>
This is possily generated from Markdown.
</p>
</div>
</body>
</html>
Note how the p element is indented to match its position in the document.
Normally this doesn’t matter, because of the way whitespace in HTML is collapsed. However there are HTML elements where the whitespace is important, in particular pre.
What it looks like is happening here is that your Markdown is generating something like
<pre><code>line 1 is fine
line 2 is wrapping
</code></pre>
and when it is included in your Haml file (I’m guessing you’re using Haml layouts with = yield to include the Markdown) it is being indented and the whitespace is showing up when you view the page. Note how the first line is immediately after the opening tags so there is no extra whitespace.
There are a couple of ways to fix this. If you set the :ugly option then Haml won’t re-indent blocks like this (sorry I don’t know how you set Haml options in Nanoc).
You could also use the find_and_preserve helper method. This replaces all newlines in whitespace sensitive tags with HTML entity
, so that they won’t be affected by the extra whitespace when indented:
= find_and_preserve(yield)
Haml provides an easy way to use find_and_preserve; ~ works the same as =, except that it runs find_and_preserve on the result, so you can do:
~ yield