In my current Asciidoctor document I have an atribute that I want to use in a codeblock. Is there a way to do String interpolation in a codeblock?
Attribute in header..
:api_version: 1.0
Codeblock
{
"api_version" : "{api_version}",
}
I seem unable to do String replacement, any hints or tips to do String replacement in code block?
You can apply substitutions like this:
.Example list of dependency RPMs:
[subs="verbatim,attributes"]
----
jdk-{java_version}-fcs.x86_64 <1>
jre-{java_version}-fcs.x86_64 <1>
sun-javadb-core-10.6.2-1.1.i386
sun-javadb-client-10.6.2-1.1.i386
sun-javadb-javadoc-10.6.2-1.1.i386
sun-javadb-demo-10.6.2-1.1.i386
sun-javadb-common-10.6.2-1.1.i386
sun-javadb-docs-10.6.2-1.1.i386
----
<1> Either the `jdk` or `jre` rpm must be installed.
Related
I am creating an asciidoc as described below:
Start of document
* R{counter:recom}: sentence1
...
* R{counter:recom}: sentence2
...
* R{counter:recom}: sentence3
End
Note: The R{counter:recom} from the asciidoc will be displayed as R1 R2 R3 in the resulting document.
I need to create a table at the start of the document which will refer the counters and text form the doc as described below:
Start of document
|Ref#|text from the document
|R1|sentence1
|R2|sentence2
|R3|sentence3
throughout the doc:
* R{counter:recom}: sentence1
...
* R{counter:recom}: sentence2
...
* R{counter:recom}: sentence3
End
Now, there are 2 unknown things here:
How do I refer the counter and sentence part from the asciidoc R1 sentence1 in the table together or separately so that, if I change it in the doc it will be changed in the table?
How do I refer the counter values in the table so that they work as links to the actual counter value R1 in the doc?
Not sure there is a readymade construct to achieve this and I haven't figured out how can I achieve it using an anchor or include statement.
What #ahus1 said.
Or, if you can convert your counter lines into section titles, then it's easy:
= Document
[cols="a"]
|===
| <<first>>
| <<second>>
| <<third>>
|===
...
[[first]]
== R{counter:recom}: sentence 1
...
[[second]]
== R{counter:recom}: sentence 2
...
[[third]]
== R{counter:recom}: sentence 3
...
End
The following is an experiment with attributes. It fulfills the following requirements:
if you change the sentence in the attribute, it will be changed in both the table and the doc
the table and the doc will contain the same number
the table to the item in the document
:ref-a: R{counter:recom}
:sen-a: sentence1
:ref-b: R{counter:recom}
:sen-b: sentence2
:ref-c: R{counter:recom}
:sen-c: sentence3
|===
|Ref#|text from the document
|<<link-a>>|{sen-a}
|<<link-b>>|{sen-b}
|<<link-c>>|{sen-c}
|===
throughout the doc:
* [[link-a,{ref-a}]]{ref-a}: {sen-a}
...
* [[link-b,{ref-b}]]{ref-b}: {sen-b}
...
* [[link-c,{ref-c}]]{ref-c}: {sen-c}
...
rendering this with either
Asciidoctor 2.0.10 [https://asciidoctor.org]
Runtime Environment (jruby 9.2.7.0 (2.5.3) 2019-04-09 8a269e3 Java HotSpot(TM) 64-Bit Server VM 25.161-b12 on 1.8.0_161-b12 +jit [mswin32-x86_64]) (lc:CP850 fs:Windows-1252 in:CP850 ex:CP850)
or
Asciidoctor PDF 1.5.0.beta.1 using Asciidoctor 2.0.10 [https://asciidoctor.org]
Runtime Environment (jruby 9.2.7.0 (2.5.3) 2019-04-09 8a269e3 Java HotSpot(TM) 64-Bit Server VM 25.161-b12 on 1.8.0_161-b12 +jit [mswin32-x86_64]) (lc:CP850 fs:Windows-1252 in:CP850 ex:CP850)
displays
Alternative to putting the sentence in an attribute: assuming that each chapter is described in a separate file, you can use an include statement that only includes the first line of the file for the table using include::filename.txt[lines=1], and later include the full file inside the document. See Include By Line Ranges in the Asciidoctor documentation for details (you can also use tags to specify the contents for the table).
I have a set like below.
php55MajorVersion=5.5
php55MinorVersion=5
php55Dir="${top_build_dir}/php/php-${php55MajorVersion}.${php55MinorVersion}-${ansdkBuild}"
php56MajorVersion=5.6
php56MinorVersion=6
php56Dir="${top_build_dir}/php/php-${php56MajorVersion}.${php56MinorVersion}-${ansdkBuild}"
php70MajorVersion=7.0
php70MinorVersion=4
php70Dir="${top_build_dir}/php/php-${php70MajorVersion}.${php70MinorVersion}-${ansdkBuild}"
Then I have the following input
phpVersion="php70"
phpMajorVersion="${phpVersion}MajorVersion"
phpMinorVersion="${phpVersion}MinorVersion"
phpDir="${phpVersion}Dir"
Now I want to print value associated with phpMajorVersion , which should be 7.0 (how -> phpMajorVersion -> ${phpVersion}MajorVersion -> php70->MajorVersion -> 7.0).
I have tried using $("${phpVersion}MajorVersion"), but am still getting , php70MajorVersion , but not 7.0 .
Any pointers on this?
You can get what you want using the getProperty method like this:
ext {
php55MajorVersion=5.5
php56MajorVersion=5.6
php70MajorVersion=7.0
phpVersion="php70"
}
println getProperty("${phpVersion}MajorVersion")
I believe it's not possible to achieve this using just braces, another StackOverflow answer suggests the same.
I've got a Java project build with Gradle and a property file that contains custom configuration for my testing framework (amount of thread to use, test environment url, custom username & password for those environments, etc...).
I'm facing an issue related to using properties from that file that I can't figure out:
if my Test task include '**/*Test.class', all tests are running as expected.
if my Test task include '**/MyTest.class', only that test is running as expected.
if my Test task include readProperty(), the task is skipped as NO-SOURCE. <- this is the part I can't understand - as the readProperty return the correct value.
Let's get into details:
This is how the property is defined in a my.property file:
testng.class.includes='**/MyTest.class'
This is what the build.gradle file looks like:
Properties props = new Properties()
props.load(new FileInputStream(projectDir.toString() + '/common.properties'))
def testsToRunWorking(p) {
String t = 'MyTest.class'
println "Tests = $t"
return t ? t : '**/*Test.class'
}
def testsToRunNotWorking(p) {
String t = getProperty(p, "testng.class.includes")
println "Tests = $t"
return t ? t : '**/*Test.class'
}
task testCustom(type: Test) {
outputs.upToDateWhen { false }
testLogging.showStandardStreams = true
classpath = configurations.customTest + sourceSets.customTest.output
include testsToRunNotWorking(props) ///< Does not work!
// include testsToRunWorking(props) ///< Works!
useTestNG()
}
In terms of debugging:
The println properly return the value I expect, even when the testCustom task doesn't do what I would expect.
I tried adding a dependsOn task just to print the content of testCustom.configure { println $includes } which looks correct as well.
--info
Tests = '**/MyTest.class'
:clean
:compileCustomTestJava - is not incremental (e.g. outputs have changed, no previous execution, etc.).
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
:processCustomTestResources
:customTestClasses
:testCustom NO-SOURCE
The core of the issue seems to be coming from the fact that I'm reading that value from property. I hard coded inside the build.gradle everything works as expected. If read from a property file - build stops with a NO-SOURCE statement.
Any idea?
Thanks!
You are using quotation marks in the values of your property files. Everything that comes after the assignment sign in a property file is used as value, so the quotation marks remain in the string. They are printed in your output Tests = '**/MyTest.class'. On the other hand, if you define a string in your (Groovy) code with quotation marks, they are not included in the string. Therefor, the passed strings are not the same.
Remove the quotation marks from your property file(s) and everything should work, since the class files will match your string without the quotation marks.
libxml2 (for C) is not preserving empty elements in their original form on a save. It replaces <tag></tag> with <tag/> which is technically correct but causes problems for us.
xmlDocPtr doc = xmlParseFile("myfile.xml");
xmlNodePtr root = xmlSaveFile("mynewfile.xml", doc);
I've tried playing with the various options (using xlmReadFile) but none seem to affect the output. One post here mentioned disabling tag compression but the example was for PERL and I've found no analog for C.
Is there an option to disable this behavior?
Just found this enum in the xmlsave module documentation:
Enum xmlSaveOption {
XML_SAVE_FORMAT = 1 : format save output
XML_SAVE_NO_DECL = 2 : drop the xml declaration
XML_SAVE_NO_EMPTY = 4 : no empty tags
XML_SAVE_NO_XHTML = 8 : disable XHTML1 specific rules
XML_SAVE_XHTML = 16 : force XHTML1 specific rules
XML_SAVE_AS_XML = 32 : force XML serialization on HTML doc
XML_SAVE_AS_HTML = 64 : force HTML serialization on XML doc
XML_SAVE_WSNONSIG = 128 : format with non-significant whitespace
}
Maybe you can refactor your application to use this module for serialization, and play a little with these options. Specially with XML_SAVE_NO_EMPTY.
Your code may look like this:
xmlSaveCtxt *ctxt = xmlSaveToFilename("mynewfile.xml", "UTF-8", XML_SAVE_FORMAT | XML_SAVE_NO_EMPTY);
if (!ctxt || xmlSaveDoc(ctxt, doc) < 0 || xmlSaveClose(ctxt) < 0)
//...deal with the error
What is the best way to handle the lack of a namespace on some of the nodes in an xml document using lxml? Should I first modify all None named nodes to add the "gmd" name and then change the tree attributes to name http://www.isotc211.org/2005/gmd as "gmd"? If so, is there a clean way to do this with lxml or something else that would be relatively clean/safe?
from lxml import etree
nsmap = charts_tree.nsmap
nsmap.pop(None) # complains without this on the xpath with
# TypeError: empty namespace prefix is not supported in XPath
len (charts_tree.xpath('//*/gml:Polygon',namespaces=nsmap))
# 1180
len (charts_tree.xpath('//*/DS_DataSet',namespaces=nsmap))
# 0 ... Bummer!
len (charts_tree.xpath('//*/DS_DataSet'))
# 0 ... Also a bummer
e.g. http://www.charts.noaa.gov/ENCs/ENCProdCat_19115.xml
<DS_Series xmlns="http://www.isotc211.org/2005/gmd" xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:gsr="http://www.isotc211.org/2005/gsr" xmlns:gss="http://www.isotc211.org/2005/gss" xmlns:gts="http://www.isotc211.org/2005/gts" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.isotc211.org/2005/gmd http://schemas.opengis.net/iso/19139/20070417/gmd/gmd.xsd">
<composedOf>
<DS_DataSet>
<has>
<MD_Metadata>
<parentIdentifier>
<gco:CharacterString>NOAA ENC Product Catalog</gco:CharacterString>
</parentIdentifier>
...
<EX_BoundingPolygon>
<polygon>
<gml:Polygon gml:id="US1AK90M_P1">
<gml:exterior>
<gml:LinearRing>
<gml:pos>67.61505 -178.99979</gml:pos>
<gml:pos>73.99999 -178.99979</gml:pos>
...
<gml:pos>64.99997 -178.99979</gml:pos>
<gml:pos>67.61505 -178.99979</gml:pos>
</gml:LinearRing>
I believe your DS_DataSet is by virtue of being within the DS_Series (implying a default namespace of "http://www.isotc211.org/2005/gmd") carrying a namespace.
Try and map that into your namespace dictionary (you can probably first test through a print to see if it's already in there, otherwise add it and refer to the namespace by your new key).
nsmap['some_ns'] = "http://www.isotc211.org/2005/gmd"
len (charts_tree.xpath('//*/some_ns:DS_DataSet',namespaces=nsmap))
Which becomes:
nsmap['gmd'] = nsmap[None]
nsmap.pop(None)
len(charts_tree.xpath('//*/gmd:DS_DataSet',namespaces=nsmap))