Is it possible to use Sass variables in the comments? - sass

I've defined a variable called $col-num: 12 in the SCSS file, and I want to show the value inside the comments. I tried both /*$col-num*/ and /*#{$col-num}*/, but they were neither working. What I want is just /*12*/. Is it possible to parse Sass variables inside the comments?

try to add a ! at the begin of your comment
/*! #{$col-num} */
From http://sass-lang.com/documentation/file.SASS_REFERENCE.html#comments
When the first letter of a comment is !, the comment will be interpolated and always rendered into css output even in compressed output modes. This is useful for adding Copyright notices to your generated CSS.

Related

Should arguments to a custom directive be escaped?

I have created a custom directive for a documentation project of mine which is built using Sphinx and reStructuredText. The directive is used like this:
.. xpath-try:: //xpath[#expression="here"]
This will render the XPath expression as a simple code block, but with the addition of a link that the user can click to execute the expression against a sample XML document and view the matches (example link, example rendered page).
My directive specifies that it does not have content, takes one mandatory argument (the xpath expression) and recognises a couple of options:
class XPathTryDirective(Directive):
has_content = False
required_arguments = 1
optional_arguments = 0
final_argument_whitespace = True
option_spec = {
'filename': directives.unchanged,
'ns_args': directives.unchanged,
}
def run(self):
xpath_expr = self.arguments[0]
node = xpath_try(xpath_expr, xpath_expr)
...
return [node]
Everything seems to be working exactly as intended except that if the XPath expression contains a * then the syntax highlighting in my editor (gVim) gets really messed up. If I escape the * with a backslash, then that makes my editor happy, but the backslash comes through in the output.
My questions are:
Are special characters in an argument to a directive supposed to be escaped?
If so, does the directive API provide a way to get the unescaped version?
Or is it working fine and the only problem is my editor is failing to highlight things correctly?
It may seem like a minor concern but as I'm a novice at rst, I find the highlighting to be very helpful.
Are special characters in an argument to a directive supposed to be escaped?
No, I think that there is no additional processing performed on arguments of rst directives. Which matches your observation: whatever you specify as an argument of the directive, you are able to get directly via self.arguments[0].
Or is it working fine and the only problem is my editor is failing to highlight things correctly?
Yes, this seems to be the case. Character * is used for emphasis/italics in rst and it gets more attention during syntax highlighting for some reason.
This means that the solution here would be to tweak or fix vim syntax file for restructuredtext.

PhpStorm Reformat Comments Automatically?

Is there any way for PhpStorm to automatically reformat all comments in my project? I've already changed the settings to use one-line comments but it doesn't seem to do anything when I run the code formatter.
For example, let's say I have the following comment:
/*
* Hello, I am a comment
*/
Is there any way for PhpStorm to auto-convert it to this:
// Hello, I am a comment
I'd also want it to work for multi-line comments i.e.:
/*
* Hello, I am a comment
* I'm on multiple lines
*/
Should become this:
// Hello, I am a comment
// I'm on multiple lines
Is it possible for PhpStorm to do this for my entire project automatically?
Just ended up doing a regex replace:
find: \/\*\n(.*)\* (.*)\n(.*)\*\/
replace: // $2
That worked for my first comment, the one with multiple lines I just changed manually.

Is it possible to write conditional statements in a pandoc template based on variable values?

The default.beamer pandoc default template for LaTex beamer has this line:
$if(theme)$
\usetheme{$theme$}
$endif$
Does the test for a specific theme work as well? Something like:
$if(theme)$
\usetheme{$theme$}
$if(Berlin)$
\setbeamertemplate{headline}
{}
$endif$
$endif$
In the Pandoc - Pandoc User Guide, I've found this:
$if(variable)$
X
$else$
Y
$endif$
This will include X in the template if variable has a non-null value;
otherwise it will include Y. X and Y are placeholders for any valid
template text, and may include interpolated variables or other
conditionals. The $else$ section may be omitted.
And more info on looping over variables with multiple values, however I can't seem to find information on how to test for a specific variable value - not true or false, but Darmstadt or Berlin in the specific example of a LaTex Beamer Theme.
Can this work somehow?
You could simply use a LaTeX conditional like
\usepackage{ifthen}
$if(theme)$
\usetheme{$theme$}
\expandafter\ifstrequal\expandafter{$theme$}{Berlin}{%
\setbeamertemplate{headline}}{%
% if false
}}%
$endif$
Pandoc itself does not allow this out of the box.
There are two ways to solve this:
Writing custom filter or looking for it. Pandoc filters have document serialized to JSON on both input and output. Having such a filter, you can mark sections using custom heading attributes.
Preprocess Pandoc input using any preprocessor like mentioned here.
For me, second approach is preferred, because:
not everything in Pandoc can be annotated with custom attributes;
headings model is flat, e.g. heading is not an attribute of something like section, but only a place in the text.

How to handle two dashes in ReST

I'm using Sphinx to document a command line utility written in Python. I want to be able to document a command line option, such as --region like this:
**--region** <region_name>
in ReST and then use Sphinx to to generate my HTML and man pages for me.
This works great when generating man pages but in the generated HTML, the -- gets turned into - which is incorrect. I have found that if I change my source ReST document to look like this:
**---region** <region_name>
The HTML generates correctly but now my man pages have --- instead of --. Also incorrect.
I've tried escaping the dashes with a backslash character (e.g. \-\-) but that had no effect.
Any help would be much appreciated.
This is a configuration option in Sphinx that is on by default: the html_use_smartypants option (http://sphinx-doc.org/config.html?highlight=dash#confval-html_use_smartypants).
If you turn off the option, then you will have to use the Unicode character '–' if you want an en-dash.
With
**-\\-region** <region_name>
it should work.
In Sphinx 1.6 html_use_smartypants has been deprecated, and it is no longer necessary to set html_use_smartypants = False in your conf.py or as an argument to sphinx-build. Instead you should use smart_quotes = False.
If you want to use the transformations formerly provided by html_use_smartypants, instead it is recommended to use smart_quotes, e.g., smart_quotes = True.
Note that at the time of this writing Read the Docs pins sphinx==1.5.3, which does not support the smart_quotes option. Until then, you'll need to continue using html_use_smartypants.
EDIT It appears that Sphinx now uses smartquotes instead of docutils smart_quotes. h/t #bad_coder.
To add two dashes, add the following:
.. include:: <isotech.txt>
|minus|\ |minus|\ region
Note the backward-slash and the space. This avoids having a space between the minus signs and the name of the parameter.
You only need to include isotech.txt once per page.
With this solution, you can keep the extension smartypants and write two dashes in every part of the text you need. Not just in option lists or literals.
As commented by #mzjn, the best way to address the original submitter's need is to use Option Lists.
The format is simple: a sequence of lines that start with -, --, + or /, followed by the actual option, (at least) two spaces and then the option's description:
-l long listing
-r reversed sorting
-t sort by time
--all do not ignore entries starting with .
The number of spaces between option and description may vary by line, it just needs to be at least two, which allows for a clear presentation (as above) on the source, as well as on the generated document.
Option Lists have syntax for an option argument as well (just put an additional word or several words enclosed in <> before the two spaces); see the linked page for details.
The other answers on this page targeted the original submitter's question, this one addresses their actual need.

.tpl file and %%. Is this smarty?

I have a .tpl file which has %% variables in it.
Example:
%%GLOBAL_Error%%
Is this a smarty template engine file?
I want to check if this variable is not empty, but I can't do this with regular smarty syntax.
{if isset($GLOBAL_Error) }
How can i do this?
I got response that this is Twig template engine :S
By default, smarty use { and } as delimiters. So, you can write code:
{if $GLOBAL_Error}{/if}
But delimiters could be changed to %% and code must be in such form:
%%if $GLOBAL_Error%%%%/if%%
See also: http://www.smarty.net/docsv2/en/language.escaping.tpl
It might be, but it might not be. Smarty tag delimiters are configurable, so it's possible the developer set them to %% and %%. GLOBAL_Error may not be a variable, but a function call with no parameters. In that case, you'd need something like:
%%if (%%GLOBAL_Error%%) %%
That's some pretty ugly syntax though. It could be anything, maybe a string token for some search/replace before or after the template is compiled. If you're already using Smarty with standard delimiters, then it's unlikely that %%GLOBAL_Error%% is meant to be parsed by Smarty - it might even be a mistake or relic of old code. The only way to know for sure is to ask the author or just look at the codebase.

Resources