How to escape double plus plus sign "++" in Asciidoctor Asciidoc? - asciidoc

For example, if I write:
Notepad++ is *great*, I like Notepad++
it treats ++something++ as an escape construct which ignores the * bold and produces:
<p>Notepad is *great*, I like Notepad</p>
instead of the desired:
<p>Notepad++ is <strong>great</strong>, I like Notepad++</p>
Upstream discussion: https://github.com/asciidoctor/asciidoctor/issues/1864
Tested on Asciidoctor 2.0.10.

A few options that do what I want:
Notepadpass:[++] is *great*, I like Notepadpass:[++]
Notepad{blank}pass:[++] is *great*, I like Notepad{blank}pass:[++]
Notepad{plus}{plus} is *great*, I like Notepad{plus}{plus}
I'm not 100% sure if the Notepadpass:[++] is meant to work of just an accident. I think I'm just going with {plus}{plus}.
Where {plus} is documented at: https://asciidoctor.org/docs/user-manual/#charref-attributes
For the specific case of C++ there is also {cpp}.

Another option is to use a backslash to escape the first ++:
Notepad\++ is *great*, I like Notepad++
This works in a similar way on other formatting as well.

Related

replace or delete character '#' in string with bash shell [duplicate]

A console program (translate-shell) has an output with colors and uses special decorate characters for this: ^[[22m, ^[[24m, ^[[1m... and so on.
I'd like to remove them to get a plain text.
I tried with tr -d "^[[22m" and with sed 's/[\^[[22m]//g', but only is removed the number, not the special character ^[
Thanks.
You have multiple options:
https://unix.stackexchange.com/questions/14684/removing-control-chars-including-console-codes-colours-from-script-output
http://www.commandlinefu.com/commands/view/3584/remove-color-codes-special-characters-with-sed
and as -no-ansi as pointed out by Jens in other answer
EDIT
The solution from commandlinefu does the job pretty well:
sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"
The solution from unix.stackexchange might be better but is much longer and so you would want to create a separate script file because it is so long instead of just doing a shell one-liner.
I found this in the manual about the use of ANSI escape codes:
-no-ansi
Do not use ANSI escape codes.
So you should add this option when starting the program.

How to remove the decorate colors characters in bash output?

A console program (translate-shell) has an output with colors and uses special decorate characters for this: ^[[22m, ^[[24m, ^[[1m... and so on.
I'd like to remove them to get a plain text.
I tried with tr -d "^[[22m" and with sed 's/[\^[[22m]//g', but only is removed the number, not the special character ^[
Thanks.
You have multiple options:
https://unix.stackexchange.com/questions/14684/removing-control-chars-including-console-codes-colours-from-script-output
http://www.commandlinefu.com/commands/view/3584/remove-color-codes-special-characters-with-sed
and as -no-ansi as pointed out by Jens in other answer
EDIT
The solution from commandlinefu does the job pretty well:
sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"
The solution from unix.stackexchange might be better but is much longer and so you would want to create a separate script file because it is so long instead of just doing a shell one-liner.
I found this in the manual about the use of ANSI escape codes:
-no-ansi
Do not use ANSI escape codes.
So you should add this option when starting the program.

What's the name of "<<-JS" operator [duplicate]

For example:
code = <<-EOH
bundle install
bundle exec unicorn -c /etc/unicorn.cfg -D
EOH
What does this code do? What is <<- called?
It's called heredoc. An easy way to define multiline strings which may include single or double quotes without needing to escape them.
See more here, for example.
Often you use heredocs to define large chunks of code. Some editors know about this and can highlight syntax for you there (if you specify language). Look:
There is also a newer HEREDOC syntax for Ruby <<~END that more closely resembles what you would typically see in most shells and other languages with the ~ instead of the - to tell Ruby to strip the leading whitespace to match the least indented line in the block.
https://infinum.co/the-capsized-eight/multiline-strings-ruby-2-3-0-the-squiggly-heredoc
Looks to me like heredoc. The - allows the ending delimiter to ignore whitespace before it.
A simple Google Search gave me this.

Single quote string interpolation to access a file in linux

How do I make the parameter file of the method sound become the file name of the .fifo >extension using single quotes? I've searched up and down, and tried many different >approaches, but I think I need a new set of eyes on this one.
def sound(file)
#cli.stream_audio('audio\file.fifo')
end
Alright so I finally got it working, might not be the correct way but this seemed to do the trick. First thing, there may have been some white space interfering with my file parameter. Then I used the File.join option that I saw posted here by a few different people.
I used a bit of each of the answers really, and this is how it came out:
def sound(file)
file = file.strip
file = File.join('audio/',"#{file}.fifo")
#cli.stream_audio(file) if File.exist? file
end
Works like a charm! :D
Ruby interpolation requires that you use double quotes.
Is there a reason you need to use single quotes?
def sound(FILE)
#cli.stream_audio("audio/#{FILE}.fifo")
end
As Charles Caldwell stated in his comment, the best way to get cross-platform file paths to work correctly would be to use File.join. Using that, your method would look like this:
def sound(FILE)
#cli.stream_audio(File.join("audio", "#{FILE}.fifo"))
end
Your problem is with your usage of file path separators. You are using a \. Whereas this may not seem like a big deal, it actually is when used in Ruby strings.
When you use \ in a single quoted string, nothing happens. It is evaluated as-is:
puts 'Hello\tWorld' #=> Hello\tWorld
Notice what happens when we use double quotes:
puts "Hello\tWorld" #=> "Hello World"
The \t got interpreted as a tab. That's because, much like how Ruby will interpolate #{} code in a double quote, it will also interpret \n or \t into a new line or tab. So when it sees "audio\file.fifo" it is actually seeing "audio" with a \f and "ile.fifo". It then determines that \f means 'form feed' and adds it to your string. Here is a list of escape sequences. It is for C++ but it works across most languages.
As #sawa pointed out, if your escape sequence does not exist (for instance \y) then it will just remove the \ and leave the 'y'.
"audio\yourfile.fifo" #=> audioyourfile.fifo
There are three possible solutions:
Use a forward slash:
"audio/#{file}.fifo"
The forward slash will be interpreted as a file path separator when passed to the system. I do most my work on Windows which uses \ but using / in my code is perfectly fine.
Use \\:
"audio\\#{file}.fifo"
Using a double \\ escapes the \ and causes it to be read as you intended it.
Use File.join:
File.join("audio", "#{file}.fifo")
This will output the parameters with whatever file separator is setup as in the File::SEPARATOR constant.

What does "<<-" mean in Ruby?

For example:
code = <<-EOH
bundle install
bundle exec unicorn -c /etc/unicorn.cfg -D
EOH
What does this code do? What is <<- called?
It's called heredoc. An easy way to define multiline strings which may include single or double quotes without needing to escape them.
See more here, for example.
Often you use heredocs to define large chunks of code. Some editors know about this and can highlight syntax for you there (if you specify language). Look:
There is also a newer HEREDOC syntax for Ruby <<~END that more closely resembles what you would typically see in most shells and other languages with the ~ instead of the - to tell Ruby to strip the leading whitespace to match the least indented line in the block.
https://infinum.co/the-capsized-eight/multiline-strings-ruby-2-3-0-the-squiggly-heredoc
Looks to me like heredoc. The - allows the ending delimiter to ignore whitespace before it.
A simple Google Search gave me this.

Resources