symbols in restructuredText - markup

I want to use some symbols in restructuredText; how can I do this? (e.g. → in Markdown yields the "→" symbol as defined in the list of standard HTML character entities -- see also w3c reference)
Note: I don't want to require math formula support as a dependency.

You have a large number of defined symbols via the "substitution" operator.
You have to include the definitions via .. include:: <isonum.txt> or something similar.
Most of them have the form |larr| or |rarr|.
They are defined in the docutils.parsers.rst.include installation directory. There are dozens of files which define numerous Unicode characters.

It was my impression that rst supported Unicode; can you just type in the raw character and let docutils handle encoding for HTML?

I think you were looking for this: http://docutils.sourceforge.net/docs/ref/rst/roles.html#raw
You can define the following role:
.. role:: raw-html(raw)
:format: html
And then you can write:
This way :raw-html:`→`
Which renders like this:
This way →

I had a similar problem when making html from .rst files containing the ± character in Windows using Sphinx. Changing the file encoding from windows-1252 to UTF-8 fixed it for me.
Simply open with notepad, Save As..., and change Encoding: to UTF-8

Related

Better way to include content as-is with AsciiDoc include directive

Context
I am making a script that dynamically inserts include directives in code blocks on an AsciiDoc file and then generates a PDF out of that. A generated AsciiDoc file could look like this:
= Title
[source,java]
---
include::foo.java[]
---
I want the user to be free to include whatever char-based file he or she wants, even other AsciiDoc files.
Problems
My goal is to show the contents as are of these included files. I run into problems when the included file:
is recognized as AsciiDoc beacuse of its extension, an thus any include directives it has are interpreted. I don't want nested includes, just to show the include directive in the code block. Example of undesired behaviour:
contains the code block delimiter ----, as seen on the image above when I end up with two code blocks instead of the intended single one. In this case, it does not matter if the file is recognized as an AsciiDoc file, the problem persists.
My workaround
The script I am writing uses AsciidoctorJ and I am leveraging that I can control how the content of each file is included by using an include processor. Using the include processor I wrap each line of each file with the pass:[] macro. Additionally, I activate macro substitution on the desired code block. A demonstration of this idea is shown in the image above.
Is there a better way to show the exact contents of a file? This works, but it seems like a hack. I would much rather prefer not having to change the read lines as I am currently doing.
EDIT for futher information
I would like to:
not have to escape the block delimiter. I am not exclusively referring to ----, but whatever the delimiter happens to be. For example, the answer by cirrus still has the problem when a line of the included file has .....
not have to escape the include directives in files recognized as AsciiDoc.
In a general note, I don't want to escape (or modify in any way) any lines.
Problem I found with my workaround:
If the last char of a line is a backslash (\), it escapes the closing bracket of the pass:[] macro.
You can try using a literal block. Based on your above example:
a.adoc:
= Title
....
include::c.adoc[]
....
If you use include:: in c.adoc, asciidoctor will still try to find and include the file. As such you will need to replace include:: with \include::
c.adoc:
\include::foo.txt[]
----
----
Which should output the following pdf:

Pandoc, Markdown to Doc, how to use variables?

AFAIK, variables can be defined in a YAML external file or inside the Markdown file in a header.
Then they can be used in the document. I have found examples with two different sytaxes:
$variable$ will convert variable to math mode, which is great (i.e. I want to keep that behaviour).
#{variable} does nothing.
Questions:
Is it possible to use variables in the pandoc conversion from markdown to .docx?
If so, how?
Pandoc variables can only be used in pandoc templates, not the document itself (there's an open issue about that).
For that you should check out a preprocessor like gpp or use a pandoc filter like pandoc-mustache or this lua-filter.

unicode in firefox extension

Application works when I am using the following code :
xulschoolhello.greeting.label = Hello World?
But when I use Unicode, Application does not work :
xulschoolhello.greeting.label = سلام دنیا ?
Why does not work?
I don't have a problem loading that string in my extension in a xul file from chrome://. Make sure you are not overriding the encoding (UTF-8 by default). See this page for more information.
To make sure, change your XUL's first line to:
<?xml version="1.0" encoding='UTF-8' ?>
In case you are using this in a properties file, make sure you save the .properties file in utf-8 format. From Property Files - XUL | MDN:
Non-ASCII Characters, UTF-8 and escaping
Gecko 1.8.x (or later) supports property files encoded in UTF-8. You
can and should write non-ASCII characters directly without escape
sequences, and save the file as UTF-8 without BOM. Double-check the
save options of your text editor, because many don't do this by
default. See Localizing extension descriptions for more details.
In some cases, it may be useful or needed to use escape sequences to
express some characters. Property files support escape sequences of
the form: \uXXXX , where XXXX is a Unicode character code. For
example, to put a space at the beginning or end of a string (which
would normally be stripped by the properties file parser), use \u0020
.

How do you write a link containing a closing bracket in markdown syntax?

Markdown syntax for a link is pretty simple:
[Example](http://example.com/)
produces:
Example
But what if the link itself contains a closing bracket?
[Syntax](http://en.wikipedia.org/wiki/Syntax_(programming_languages))
produces:
Syntax)
which is obviously broken.
Edit
Putting the url in quotes does not work
Sometimes you need to encode ) with %29.
[Syntax](http://en.wikipedia.org/wiki/Syntax_(programming_languages%29)
E.g.: This was the only method I could find to get a correct Markdown preview in the Atom Editor.
You can try to escape the character:
[Syntax](http://en.wikipedia.org/wiki/Syntax_\(programming_languages\))
You can also encode the characters
[Syntax](http://en.wikipedia.org/wiki/Syntax_%28programming_languages%29)
The most reliable way I've found to do this is to use reference-style links instead of inline links.
Here is the wikipedia article on [Syntax][1]
[1]: http://en.wikipedia.org/wiki/Syntax_(programming_languages)
renders correctly as
Here is the wikipedia article on Syntax
I've found that with some sites, percent-escaping the parentheses will break URLs, especially anchors. For example, at least in my version of Firefox, this Android documentation link doesn't take me directly to the method with percent encoding.
But this one with a reference-style link does.
For example, at least in my version of Firefox, this Android documentation link
doesn't take me directly to the method [with percent encoding](https://developer.android.com/reference/android/webkit/WebView.html#addJavascriptInterface%28java.lang.Object,%20java.lang.String%29).
But this one with a [reference-style link][2] does.
I have found that using < around > the url seems to solve the problem.
In the two internal systems we use that use markdown.
Your mileage may vary with other systems.
[Test](<https://en.wikipedia.org/wiki/Slowloris_(computer_security)>)
Test
Quoting w3Schools:
URLs can only be sent over the Internet using the ASCII character-set.
So, you need to encode any special characters that is not a ASCII character into its respective ASCII character.
In your case, the characters for brackets or parenthesis are
open bracket ( - %28
closing bracket ) - %29
You can use this website to get the encoded url of any website link.
You don't have to scape it at all.
On GitHub, I've just done the following without any problems:
[Slowloris](https://en.wikipedia.org/wiki/Slowloris_(computer_security))
Actually, even here you can use it directly, as you can see here.

How to read/write Chinese/Japanese characters from/to INI files?

Using WritePrivateProfileString and GetPrivateProfileString results in ??? instead of the real characters.
GetPrivateProfileString() and WritePrivateProfileString() will work with Unicode, sort of.
If the ini file is UTF-16LE encoded, i.e. it has a UTF-16 BOM, then the functions will work in Unicode. However if the functions have to create the file they will create an ANSI file and only work in ANSI.
So to use the functions with Unicode, create your ini file before you first use it and write a UTF-16LE Byte Order Mark to it. Then carry on as normal.
Note that the functions do not work at all with UTF-8.
See Michael Kaplan's blog for more detail than you ever wanted to know about this.
The WritePrivateProfileStringW function will write the INI file in legacy system encoding (e.g. Shift-JIS on a Japanese system) because it is a legacy support function. If you want to have a fully Unicode-enabled INI file, you will need to use an external library.
Try SimpleIni http://code.jellycan.com/simpleini/
It is C++, single header file, template library with an MIT licence (i.e. commercial use is OK). Include it into your source file and use it. It is cross-platform, supports UTF-8 and legacy encoded files, and can read and write the INI file largely preserving comments and structure, etc. Easiest to check out the page.
It's been around for a while and is appears to be used by quite a number of people. I wrote it and continue to support it.
According to the WritePrivateProfileString documentation, there is a Unicode version: WritePrivateProfileStringW. Use that, and you should be able to use Unicode characters.
It might just be a problem with how you are displaying or handling the strings.
For example, the normal console window can't display japanese strings with printf.
Can you post some of your code?

Resources