In Quarto, I'd like to change the default behavior of a single callout block type so that it will
always automatically have the same caption (e.g. "Additional Resources")
always be folded (collapse="true")
Let's say I want this for the tip callout block type while the others (note, warning, caution, and important) should not be affected.
In other words, I want the behavior/output of this:
:::{.callout-tip collapse="true"}
## Additional Resources
- Resource 1
- Resource 2
:::
by only having to write this:
:::{.callout-tip}
- Resource 1
- Resource 2
:::
Update:
I have actually converted the following lua filter into a quarto filter extension collapse-callout, which allows specifying default options for specific callout blocks more easily. See the github readme for detailed instructions on installation and usage.
As #stefan mentioned, you can use pandoc Lua filter to do this more neatly.
quarto_doc.qmd
---
title: "Callout Tip"
format: html
filters:
- custom-callout.lua
---
## Resources
:::{.custom-callout-tip}
- Resource 1
- Resource 2
:::
## More Resources
:::{.custom-callout-tip}
- Resource 3
- Resource 4
:::
custom-callout.lua
local h2 = pandoc.Header(2, "Additional Resources")
function Div(el)
if quarto.doc.isFormat("html") then
if el.classes:includes('custom-callout-tip') then
local content = el.content
table.insert(content, 1, h2)
return pandoc.Div(
content,
{class="callout-tip", collapse='true'}
)
end
end
end
Just make sure that quarto_doc.qmd and custom-callout.lua files are in the same directory (i.e. folder).
After a look at the docs and based on my experience with customizing Rmarkdown I would guess that this requires to create a custom template and/or the use of pandoc Lua filters.
A more lightweight approach I used in the past would be to use a small custom function to add the code for your custom callout block to your Rmd or Qmd. One drawback is that this requires a code chunk. However, to make your life a bit easier you could e.g. create a RStudio snippet to add a code chunk template to your document.
---
title: "Custom Callout"
format: html
---
```{r}
my_call_out <- function(...) {
cat(":::{.callout-tip collapse='true'}\n")
cat("## Additional Resources\n")
cat(paste0("- ", ..., collapse = "\n\n"))
cat("\n:::\n")
}
```
```{r results="asis"}
my_call_out(paste("Resource", 1:2))
```
Blah blah
```{r results="asis"}
my_call_out("Resource 3", "Resource 4")
```
Blah blah
I have an XML file (SOME.XML), the contents of which I would like to embed in an .RMD document.
If I was content with having the XML reside directly within the .RMD, I'm aware that I could simply do:
```xml
---some xml here---
```
My embarassing attempts so far are:
```{xml code=readr::read_file('SOME.XML')}
```
...which failed as there is no XML engine.
I have also tried:
````{r results='asis'}
cat('```xml')
cat(readr::read_file('SOME.XML'))
cat('```')
````
...for which, although the knitting completes, the output is not at all correct.
Is this possible? (No doubt there is some trick here that I am missing!)
If needed, I could have a pre-knit stage where the content of the XML file is substituted in before subsequently passing a modified version of the .RMD to rmarkdown::render. However, I'd like to avoid this if possible.
Update:
Using readLines as proposed by the answer is complaining about ...incomplete final line found on 'SOME.XML'. Using readr::read_file() avoids this for me. For my particular project, I am now using:
```xml
`r readr::read_file("SOME.XML")`
```
Thank you to #user2554330 for the elegant solution!
Here's one way to do it:
```xml
`r paste(readLines("SOME.XML"), collapse = "\n")`
```
The idea is to put the XML into inline R code. I think knitr ignores the chunk wrappers because they aren't in the {xml ... format it looks for, but it will see the inline code and expand it. Then Pandoc will handle the formatting.
Here's how to modify your approach to get it to work:
````{r results='asis', echo = FALSE}
cat('```xml\n')
cat(readr::read_file('SOME.XML'), sep = "\n")
cat('\n```\n')
````
Custom Keyword written in python 2.7:
#keyword("Update ${filename} with ${properties}")
def set_multiple_test_properties(self, filename, properties):
for each in values.split(","):
each = each.replace(" ", "")
key, value = each.split("=")
self.set_test_properties(filename, key, value)
When we send paremeters in a single line as shown below, its working as expected:
"Update sample.txt with "test.update=11,timeout=20,delay.seconds=10,maxUntouchedTime=10"
But when we modify the above line with a new lines (for better readability) it's not working.
Update sample.txt with "test.update = 11,
timeout=20,
delay.seconds=10,
maxUntouchedTime=10"
Any clue on this please?
I am not very sure whether it will work or not, but please try like this
Update sample.txt with "test.update = 11,
... timeout=20,
... delay.seconds=10,
... maxUntouchedTime=10"
Your approach is not working, cause the 2nd line is considered a call to a keyword (called "timeout=20,"), the 3rd another one, and so on. The 3 dots don't work cause they are "cell separators" - delimiter b/n arguments.
If you are going for readability, you can use the Catenate kw (it's in the Strings library):
${props}= Catenate SEPARATOR=${SPACE}
... test.update = 11,
... timeout=20,
... delay.seconds=10,
... maxUntouchedTime=10
, and then call your keyword with that variable:
Update sample.txt with "${props}"
btw, a) I think your keyword declaration in the decorator is without the double quotes - i.e. called like that ^ they'll be treated as part of the argument's value, b) there seems to be an error in the py method - the argument's name is "properties" while the itterator uses "values", and c) you might want to consider using named varargs (**kwargs in python, ${kwargs} in RF syntax) for this purpose (sorry, offtopic, but couldn't resist :)
I am using kitchen with ec2 driver. I would like to add Name tag to ec2 instances based on the instance name kitchen creates. If I had a 'default' suite and was using centos7.2, kitchen list would name the instance 'default-centos-72'.
I could hard code something like this:
suites:
- name: default
driver_config:
tags: { "Name": "kitchen-default-centos-72" }
But what I'd really like is something like this:
suites:
- name: default
driver_config:
tags: { "Name": <%= figure out instance name and prepend kitchen- %> }
My example suggests using ERB which seems like the way to go to me. But I can't seem to figure out what code to use to get the name of the instance. I tried using a bit of Kitchen::Config.new... but couldn't figure out something that worked. Any suggestions would be much appreciated.
Took me a while but I finally ran across an example that may have showed me the light. While looking through the InSpec options for kitchen I found you can have it output a results file with the platform and suite name that was used during the test run. The below syntax in your platforms: block nested under the driver: option should work. I haven't tested this by examining the instance during a run but hopefully I can find some time to do that soon. If it doesn't work let me know and we can tweak it until it does.
platforms:
- name: ubuntu
driver:
tags:
Name: test-kitchen-%{platform}-%{suite}
How this should work is that the .kitchen.yml file gets run through an ERB pre-processor so the %{platform} resolves to an instance variable during the loop across the platforms and suites arrays.
As far as I can tell there seems to be no straightforward way to include instance properties in the kitchen YAML. I added the following snippet to my kitchen.yml to check what is available in the kitchen YAML's ERB namespace:
<%
puts "Instance vars: #{instance_variables}"
puts "Local vars: #{local_variables}"
puts "Global vars: #{global_variables}"
puts "Methods: #{methods}"
%>
The results when running kitchen create for a specific instance were disappointing, containing nothing that looks like instance specification data:
Instance vars: []
Local vars: [:_erbout, :spec, :bin_file]
Global vars: [:$-0, :$\, :$DEBUG, :$-W, :$0, :$-d, :$-p, :$PROGRAM_NAME, :$:, :$-I, :$LOAD_PATH, :$", :$LOADED_FEATURES, :$,, :$/, :$INPUT_LINE_NUMBER, :$-l, :$-a, :$INPUT_RECORD_SEPARATOR, :$ORS, :$OUTPUT_RECORD_SEPARATOR, :$PROCESS_ID, :$NR, :$#, :$!, :$DEFAULT_INPUT, :$PID, :$PREMATCH, :$CHILD_STATUS, :$LAST_MATCH_INFO, :$LAST_READ_LINE, :$DEFAULT_OUTPUT, :$MATCH, :$fileutils_rb_have_lchown, :$POSTMATCH, :$LAST_PAREN_MATCH, :$IGNORECASE, :$ARGV, :$fileutils_rb_have_lchmod, :$stdin, :$stdout, :$stderr, :$>, :$<, :$., :$FILENAME, :$-i, :$*, :$SAFE, :$thor_runner, :$_, :$~, :$;, :$-F, :$?, :$$, :$ERROR_INFO, :$&, :$`, :$', :$+, :$=, :$KCODE, :$-K, :$ERROR_POSITION, :$FS, :$FIELD_SEPARATOR, :$OFS, :$OUTPUT_FIELD_SEPARATOR, :$RS, :$VERBOSE, :$-v, :$-w]
Methods: [:inspect, :to_s, :to_yaml, :to_json, :instance_variable_defined?, :remove_instance_variable, :instance_of?, :kind_of?, :is_a?, :tap, :methods, :instance_variable_set, :protected_methods, :instance_variables, :instance_variable_get, :private_methods, :public_methods, :method, :define_singleton_method, :public_send, :singleton_method, :public_method, :extend, :to_enum, :enum_for, :<=>, :===, :=~, :!~, :eql?, :respond_to?, :freeze, :object_id, :send, :display, :class, :nil?, :hash, :dup, :singleton_class, :clone, :then, :itself, :yield_self, :untaint, :taint, :tainted?, :untrusted?, :trust, :frozen?, :untrust, :singleton_methods, :equal?, :!, :__id__, :==, :instance_exec, :!=, :instance_eval, :__send__]
The local variable spec looked hopeful at first, but turned out to be a GemSpec object.
All things considered, you will probably have to create a convention to always specify the instance in some external way. You could use for example an environment variable of your choice, which you could then access in the template as <%= ENV['<VARNAME>'] %> (where you replace <VARNAME> with the name of your environment variable). There are probably other ways of getting the information in there, but you will still have to specify it in more places than just the Test Kitchen command.
I was using QuasiQuotations in Yesod, and everything worked fine. BUT my file became very large and not nice to look at. Also, my TextEditor does not highlight this syntax correctly. That is why is split my files like so:
getHomeR :: Handler Html
getHomeR = do
webSockets chatApp
defaultLayout $ do
$(luciusFile "templates/chat.lucius")
$(juliusFile "templates/chat.julius")
$(hamletFile "templates/chat.hamlet")
If this is wrong, please do tell. Doing runghc myFile.hs throws many errors like this:
chat_new.hs:115:9:
Couldn't match expected type ‘t0 -> Css’
with actual type ‘WidgetT App IO a0’
The lambda expression ‘\ _render_ajFK
-> (shakespeare-2.0.7:Text.Css.CssNoWhitespace . (foldr ($) ...))
...’
has one argument,
but its type ‘WidgetT App IO a0’ has none
In a stmt of a 'do' block:
\ _render_ajFK
...
And this.
chat_new.hs:116:9:
Couldn't match type ‘(url0 -> [(Text, Text)] -> Text)
-> Javascript’
with ‘WidgetT App IO a1’
Expected type: WidgetT App IO a1
Actual type: JavascriptUrl url0
Probable cause: ‘asJavascriptUrl’ is applied to too few arguments
...
And also one for the HTML (Hamlet).
Thus, one per template.
It seems that hamletFile and others treat templates as self-contained, while yours are referencing something from each other. You can play with order of *File calls, or use widgetFile* from Yesod.Default.Util module:
$(widgetFileNoReload def "chat")
The Reload variant is useful for development - it would make yesod devel to watch for file changes and reload them.