How to insert hard line break in Quarto document - quarto

I'm working with the Quarto document preparation system to programmatically generate large documents using Python. That is I am not using the RStudio or similar editor. All text must be generated as Python strings.
I have a simple table where one cell has several lines worth of content and I figure that I can add line-breaks within the cell. I understand that simple tables cannot include standard line breaks (\n) but I'm wondering if there is a way to insert so-called "hard-line-breaks" in cells. The user manual mentions them but states that only the editor can insert them. Is it possible to do this using string operations in the markdown source text?
Barring that is there a simple way to break lines within a cell in a table?

Quarto tables generated by RStudio visual Markdown editor
There's not much magic involved when it comes to hard line breaks, just lines that end with a \.
QMD file created in RStudio with visual mode enabled, a (Grid) table with both regular and hard line breaks looks like this:
---
title: "tbl"
format: html
editor: visual
---
+-------+-------------+
| Col1 | Col2 |
+=======+=============+
| press | press\ |
| | shift+enter |
| enter | |
+-------+-------------+
| | |
+-------+-------------+
With all the whitespace and linefeeds next to rendered output:
While RStudio visual editor starts with simple pipe tables, it switches automatically to grid tables when it encounters a line break or anything else in a cell that's not supported by simple pipe tables.
Python and grid-style Markdown tables
For generating Markdown grid tables in Python, tabulate with tablefmt="grid" is quite handy. Or pandas.DataFrame.to_markdown() in case of pandas, also built on top of tabulate.
from tabulate import tabulate
td = [["press\n\nenter","press\\\nshift+enter"],["no\nbackslash","",]]
hdr = ["Col1", "Col2"]
print(tabulate(td,headers=hdr, tablefmt="grid"))
Result:
+-----------+-------------+
| Col1 | Col2 |
+===========+=============+
| press | press\ |
| | shift+enter |
| enter | |
+-----------+-------------+
| no | |
| backslash | |
+-----------+-------------+
Rendered with Quarto:
Pandoc multiline tables
For whatever reason this is not mentioned in Quarto docs, but Pandoc also supports multiline_tables and rendering it with Quarto & Pandoc that are bundled with RStudio works fine, though for hard line breaks it still needs \ before a break.
Slighty modified sample from Pandoc documentation:
-------------------------------------------------------------
Centered Default Right Left
Header Aligned Aligned Aligned
----------- ------- --------------- -------------------------
First row 12.0 Example of\
a row that
spans multiple lines.
Second row 5.0 Here's another one. Note
the blank line between
rows.
-------------------------------------------------------------
Table: Here's the caption. It, too, may span\
multiple lines.
Renders as:

Related

How to add the vertical pipes we see in Examples feature of the Scenario Outline in SpecFlow

I would like to add the vertical pipes so that I can have my data table down there under "Examples" feature in Specflow. Anyone to give me any tip so I can go through it?. My scenario outline looks like:
#mytag
Scenario Outline: Check Noun Words
Given Access the AnalyzeStateless URL
And language code
And content of <Sentence>
And the Expected KeyWord <Expected KeyWords>
And the Expected Family ID <Expected FID>
And the index <Index>
When return the XML response
Then the keyword should contain <FamilyID>
Examples:
| Index | Sentence | Expected KeyWords | Expected FID |
| 1 | I need a personal credit card | personal | 92289 |
The "Examples" feature has been manually entered in above case. I have a thousand of rows on an excel file, any appropriate way to get all of the values in one go?
Have you looked at Specflow.Excel which allows you to keep your examples in your excel files?

How to shift table in markdown file?

I have a table in README.md file in TFS like this:
| Tables | Are | Cool |
| ------------- |:-------------:| -----:|
| col 3 is | right-aligned | $1600 |
| col 2 is | centered | $12 |
| zebra stripes | are neat | $1 |
It's work. But I need to shift this table to the right by tab character. And if I place tab (or space character) before table rows it's not recognize as table and just print as plain text. HTML tag also doesn't work in TFS.
How I can move table?
Unfortunately shift table is not supported in Markdown.
Markdown does not provide any special syntax for tables.
Please see Syntax guidance for Markdown files, widgets, wikis, and pull request comments for details.
I can think of is that you can capture a screenshot for the table, render the captured image, check in the image, then Add image to your Markdown file.
But please note that just as Waylan mention in below comments : For screenshot of a table, the text will no longer be searchable and cannot be copy and pasted by the user. And any future edits will require recreating the entire table.

Repeating steps with different values in BDD test case

I am new to BDD specflow.
I have to write a scenario wherein after I capture an image, i have to select a value for each defined attribute for that image from a selection list
For Eg:
|Body Part |Location |Group |
| Leg | Left | Skin |
| Hand | Upper | Burn |
| Arm | Right | Ulcer |
I need a way in which i can select a different value for each attribute, every time.
Thanks in advance!
You are looking for Scenario Outline;
Scenario outlines allow us to more concisely express these examples through the use of a template with placeholders, using Scenario Outline, Examples with tables and < > delimited parameters.
Specflow takes each line in the Example table and create from the line a scenario to execute.

cannot find "for loop" keyword in robot framework

I am currently connecting SQL server to robot framework, so i can read my data table name in robot. and I want to use for loop to check table name, somehow, ":FOR" loop keyword cannot found, but I have installed libraries such as operating-system, collections, string, built-in, diff-library and so on. anyone can help me why i cannot use for loop? any help will be appreciated.
The robot framework users guide has a whole section on how to use the for loop. From that section:
The syntax starts with :FOR, where colon is required to separate the
syntax from normal keywords. The next cell contains the loop variable,
the subsequent cell must have IN, and the final cells contain values
over which to iterate. These values can contain variables, including
list variables.
Here's an example from the user's guide, reformatted to use pipes (for clarity):
*** Test Cases ***
| Example 1
| | :FOR | ${animal} | IN | cat | dog
| | | log | ${animal}
| | | log | 2nd keyword
| | Log | Outside loop
Maybe you are not escaping indented cells; as the Tip in the documentation says. Try writing loops like this:
:FOR ${index} IN RANGE ${start} ${stop}
\ log to console index: ${index}
\ Call a Keyword

markdown -> pandoc -> PDF | chokes on rendering tables

I am using Pandoc to generate a PDF from markdown, but am having trouble producing a table. The terminal command used is:
$ pandoc -s -o foo.pdf --latex-engine=xelatex --filter pandoc-citeproc bar.md
The grid table used in my markdown document looks like this:
+---------------+---------------+--------------------+
| Fruit | Price | Advantages |
+===============+===============+====================+
| Bananas | $1.34 | - built-in wrapper |
| | | - bright color |
+---------------+---------------+--------------------+
| Oranges | $2.10 | - cures scurvy |
| | | - tasty |
+---------------+---------------+--------------------+
I've tried switching the LaTeX engine, using different forms of markdown tables, everything I can think of. Infuriatingly, I got this to work once and have spent the past few hours trying to reproduce the results, but with no success. Instead, I just keep getting the following error message:
pandoc: Error producing PDF from TeX source.
! Undefined control sequence.
\y ->\LT#array
l.7128 }{}
Any ideas? I'm using Pandoc v. 1.12.0.2.
This doesn't look like a Pandoc issue per se. The error you are getting is a TeX error and what it says is that your TeX interpreter doesn't recognize the longtable environment. Maybe you are using a document class that doesn't use the longtablepackage by default...
If you are using a tex template, try to add the longtable package manually:
\usepackage{longtable}
This must be added right after the line that defines the document class:
\documentclass[some options]{some class}
This will solve the current issue, although TeX may then complain about other stuff.
By the way, you might be better off asking this kind of question on TeX StackExchange.

Resources