With AsciiDoctor, how to pass variables in source and example blocks? - asciidoc

Any one knows how to pass variables {var} into [source] blocks and example blocks (with ====) in Asciidoc?
I have tried the following
:country: France
:city: Shanghai
[source]
----
print("{country} is a country")
print("{city} is a city")
----
.Example
====
{country} is a country +
{city} is a city
====
.Example with better alignment
====
{country} is a country
{city} is a city
====
But this is what I get:
Actually the first "example" is working but it is not the ideal solution because:
It does not have the grey area like other examples
I need to add a + at the end of each line
Looking forward your inputs. Thanks in advance!

As described here you need to switch on attribute replacement in code blocks. You can achieve it with [subs="attributes"]complete example should look something like:
[source, subs="attributes"]
----
print("{country} is a country")
print("{city} is a city")
----
.Example with better alignment
====
[subs="attributes"]
{country} is a country
{city} is a city
====

Related

Bibiliography style with Quarto documents

The default way of displaying references with Quarto documents seems to put author names in this format: Last1, First1, First2 Last2, First3 Last3, and First4 Last4. So the first author name is displayed differently than the rest. Is that intentional and is there a way to change that?
Here's an example:
---
project:
type: website
format: html
bibliography: references.bib
---
## Text
#bibitem1
Content of references.bib
#article{bibitem1,
author = {First1 Last1 and First2 Last2 and First3 Last3 and First4 Last4},
title = {Article title},
journal = {Journal name},
year = {2013},
volume = {3},
number = {72},
pages = {14--18}
}
which is displayed as
Last1, First1, First2 Last2, First3 Last3, and First4 Last4. 2013. “Article Title.” Journal Name 3 (72): 14–18.
How your references are displayed is entirely determined by the bibliography format you use. Quarto adopts a default one. You can specify a custom one with the csl option, specified in your YAML header as for example:
csl: biomed-central.csl
Styles for many journals are available with the Zotero project: https://www.zotero.org/styles
These styles are composed using the Citation Style Language. In principle, you could customize such a style (including the default style used by Quarto). It is not that trivial, though, and would require some effort to understand and use the language.

Why do some apps change the value of their Windows Clipboard format code?

I have an app that writes some rich text in HTML format to the Windows clipboard. The text is meant to be manually pasted in other apps, such as a browser, MS Word, Thunderbird email client, etc. Adding the content to the clipboard requires specifying a format code.
I use the SetClipboardData(UINT uFormat, HANDLE hMem) function. I derive uFormat empirically by dumping the raw contents of the clipboard and examining its format codes.
The problem is that for some apps, the format code seems to vary from one day to the next. I have observed it to be: 0xC10E, COFD, C0FE, C0FB, C10D, C11F, C0FC, C104, etc. MS Word accepts anything; Firefox and Thunderbird will reject anything other than the one specific code.
Is there a way of determining, from a program, what the format code du jour is?
I have reviewed SetClipboardData, Clipboard Formats and Using the Clipboard
Here's the code fragment:
OpenClipboard();
EmptyClipboard();
int length; // text length gets set elsewhere
HGLOBAL hglbCopy = GlobalAlloc(GMEM_MOVEABLE, length + 1);
LPSTR lpstr = (LPSTR)GlobalLock(hglbCopy);
memcpy(lpstr, source_text, length);
lpstr[length] = 0;
GlobalUnlock(hglbCopy);
// Place the handle on the clipboard.
HANDLE ret = SetClipboardData(0xC109, hglbCopy);
CloseClipboard();
Here's a typical clipboard dump. In order to get this, I have to explicitly select & copy text from the app, every time, so it's not a practical way to figure out the app's format code.
xC009
xC1B3
xC104
xC25F
xC269
CF_UNICODETEXT
CF_TEXT
xC26A
xC013
CF_LOCALE
CF_OEMTEXT
x0
--------------------------------
xC009:
u
--------------------------------
xC1B3:
C
--------------------------------
xC104:
Version:0.9
StartHTML:00000280
EndHTML:00000408
StartFragment:00000314
EndFragment:00000372
SourceURL:mailbox:///C:/Users/***/AppData/Roaming/Thunderbird/Profiles/5y3ow05s.default/Mail/Local%20Folders/Vendors.sbd/X.sbd/***?number=2454
<html><body>
<!--StartFragment-->Can your team be of assistance with the following problem?<!--EndFragment-->
</body>
</html>
--------------------------------
xC25F:
<
--------------------------------
xC269:
0
--------------------------------
CF_UNICODETEXT:
C
--------------------------------
CF_TEXT:
Can your team be of assistance with the following problem?
--------------------------------
xC26A:
m
--------------------------------
xC013:
--------------------------------
CF_LOCALE:
--------------------------------
CF_OEMTEXT:
Can your team be of assistance with the following problem?
--------------------------------
x0:
--------------------------------
Thanks to #Hans Passant's laconic yet incisive comment, I figured out what was missing from my code:
// Retrieve or define "HTML Format": if already defined, returns the format code, else defines a new one
UINT HTMLformat = RegisterClipboardFormat("HTML Format");
I did not realize that Clipboard formats had standard names as well as numeric values associated with them. These names are recognized by various apps.
Thank you also #IInspectable.

how can i find xpath or CSS selector for only ''Total Cases'' in the following table (url =this https://www.worldometers.info/coronavirus/ )

I tried several types of XPath but none of those working as I want to
Xpath : //td[#class='sorting_1'],
xpath: //tr[contains(#class,'even')]//td[#class='sorting_1'],
xpath : //tr[contains(#class,'odd')]//td[#class='sorting_1']
CSS: .even+ .odd .sorting_1 , .even .sorting_1
but the CSS selector does not work in the scrappy shell
can you please help me out of this situation??
To get total cases by country, just use :
//table[#id='main_table_countries_today']//td[contains(#style,'text-align:left;')][normalize-space()]/following-sibling::td[1]
To get the country names :
//table[#id='main_table_countries_today']//td[contains(#style,'text-align:left;')][normalize-space()]
Output (219 lines):
Side note : normalize-space is used to filter "the ghost" line present in the table (no country name and a value of 721). Probably a leftover of and old "Diamond Princess" record.
EDIT : In fact 721 corresponds to the total number of cases on the two ships ( Diamond Princess and MS Zaandam)
EDIT : If you want to get the data for each country (ships and World included) located on the first tab only (213 nodes) :
//table[#id='main_table_countries_today']//td[contains(#style,'text-align:left;')][parent::tr[not(#style="display: none")]]/following-sibling::td[1]
To exclude the ships (211 nodes) :
//table[#id='main_table_countries_today']//td[contains(#style,'text-align:left;')][parent::tr[not(#style="display: none")]][not(./span)]/following-sibling::td[1]
To exclude ships and World (210 nodes) :
//table[#id='main_table_countries_today']//td[contains(#style,'text-align:left;')][parent::tr[not(#style="display: none")]][./a[#href]]/following-sibling::td[1]
Hey try using this expression for xpath:
(//div[#class='maincounter-number']/span)[1]/text()
for css:
response.css('#maincounter-wrap:nth-child(7) span::text')

Translate parts of a string individually using Twig and the i18n extension?

I have a string that looks like
This is a list of all items with number 123456 in United States.
and I want to translate it to Swedish as
Detta är en lista över alla artiklar med nummer 123456 i USA.
The problem is that the number 123456 and the country name United States are generated dynamically, but the string is delivered in its final form to the Twig template (it's used for <meta name="description" ... />.
I already have a .po file with country names that I'm translating, including
English Swedish
United States USA
The generated meta description string can have any combination of numbers and country names, so I can't hardcode any translations for the entire string. Is there any way I can re-use my existing translations for the country names and have them translated inside the meta description string, and have the number just stay as it is? Or do I need to somehow split the string up first, and then translate each part individually?
I am not a PHP programmer, so I use pseude code:
num_items = 42;
country = "United States";
string = sprintf(gettext("... items with number %d in %s"),
num_items, gettext(country));
Is that what you are looking for?

Check if the node value exist

I want to check in a xml if there is a node with the value "Hotel Hafen Hamburg".
But I get the error.
SimpleXMLElement::xpath(): Invalid predicate on line 25
You can view the xml here.
http://de.sourcepod.com/dkdtrb22-19748
Until now I have written the following code.
$apiUmgebungUrl = "xml.xml";
$xml_umgebung = simplexml_load_file($apiUmgebungUrl);
echo $nameexist = $xml_umgebung->xpath('boolean(//result/name[#Hotel Hafen Hamburg');
It seems that your parantheses and brackets do not close properly at the end of your XPath expression - it should end on ]).
Also, what is Hotel Hafen Hamburg? If it is an attribute called value, your value check should look like this:
[#value="Hotel Hafen Hamburg"]
You cannot just write # and then a value, without specifying where that value is supposed to be.
EDIT: Looking at the Xml document, it seems that Hotel Hafen Hamburg is supposed to be the text content of the <name> element. Therefore, try looking for a text node with that value rather than an attribute:
boolean(//result/name[text() = "Hotel Hafen Hamburg"])

Resources