How can I get pandoc multiline table cells to work when outputting to docx? - multiline

I have the latest version of pandoc installed. I have created a test.txt file with the following multiline table copied directly from the pandoc user guide section on multiline tables:
-------------------------------------------------------------
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.
-------------------------------------------------------------
I then use the following pandoc command with the multiline_tables extension to output to docx:
pandoc -f markdown_mmd+multiline_tables -o text.docx test.txt
The test.docx file is created, but only shows the first line of the multiline cells. No subsequent lines of the multiline cells appear. So it appears as this (but in a microsoft word table):
-------------------------------------------------------------
Centered Default Right Left
Header Aligned Aligned Aligned
----------- ------- --------------- -------------------------
First row 12.0 Example of a row that
Second row 5.0 Here's another one. Note
-------------------------------------------------------------
Anyone no how to remedy this?

The multiline_tables-extension is enabled by default in Pandoc's markdown. So no need to use the Multi Markdown flavour. So this should work:
pandoc -o text.docx test.txt
p.s. most people name their files test.md of test.markdown
p.p.s. On rereading your question, the thought crossed my mind that your problem might have more to do with how Word displays the generated docx file. Have your tried different versions of Word, or tried outputting to HTML instead? (the docx format is quite brittle)

Step 1:
Type the command line: pandoc --print-default-data-file reference.docx > myref.docx
./ shall be added before pandoc,if your OS is linux.
You will get a document named myref.docx.
1) Open myref.docx
2) Select (or click anywhere inside) the Table
3) Click the "Table Design" tab
4) Click the little down-arrow icon on the Quick Styles list (which annoyingly only appears when you hover your mouse over the styles)
5) Click "Modify Table Style" on the popup menu
6) Make style changes that subsequent lines present.
7) Save the reference doc to the same folder
Step 2:
Type the command line: pandoc anyTypeOfYourInput.html -s --reference-doc=myref.docx -o resultOutput.docx
./ shall be added before pandoc,if your OS is linux.
Above answer is based on Mr.Iansco's answer on github. https://github.com/jgm/pandoc/issues/3275.
You can search key word 'iansco' find original answer qickly.

Related

how to enter multiple spaces in .md (markdown) file so that the converted html shows same amout of spaces?

I've seen a couple of quetion/answers in SO but couldn't understand any of it because they all didn't explain how I can inserted the " " characters, etc. I'm editing an .md file in which I want to insert some spaces to show directory structure. By the way, those lines are wrapped by ``` lines at the top and bottom but when converted to html by markdown, the spaces are just collapsed. This is the sample code(? it's not code actually).
directoies
----qemu-5.1.0
----qemu_test
----test_app
| ----include
----test_ldd
| ----linux-5.4.0
----test_ubuntu
When converted into html, it looks like this.
directoies
----qemu-5.1.0
----qemu_test
----test_app
| ----include
----test_ldd
| ----linux-5.4.0
----test_ubuntu
How should I do it?? (I'm doing it on ubuntu 20.04 using vnc on windows 10 machine)

html items share same xpath in robot

I would like to read a sibling of a text in my html code.
This text can be once or more times in my html
using inspector, this works:
xpath://*[angular-parent//div[text()='Text to find']/following-sibling::div//angular-child//span]
but when I try to read from html:
${value} Get text ${signal}
it only give me the first value. How can I get all of them?
With the assumption that you desire a list of values, I created the below example that uses the Get Text keyword but can easily be adapted to suit your needs:
*** Settings ***
Library SeleniumLibrary
Library Collections
*** Test Cases ***
Get Multiple Element Values
Open Browser https://www.w3schools.com/default.asp chrome
#{webelements} Get WebElements xpath://a[#class='w3-bar-item w3-button']
#{webelements_text} Create List
:FOR ${webelement} IN #{webelements}
\ ${text} Get Text ${webelement}
\ Append To List ${webelements_text} ${text}
Log List ${webelements_text}
[Teardown] Close Browser

Ignore any blank space or line break in git-diff

I have the same HTML file rendered in two different ways and want to compare it using git diff, taking care of ignoring every white-space, tab, line-break, carriage-return, or anything that is not strictly the source code of my files.
I'm actually trying this:
git diff --no-index --color --ignore-all-space <file1> <file2>
but when some html tags are collapsed all on one line (instead of one per line and tabulated) git-diff detect is as a difference (while for me it is not).
<html><head><title>TITLE</title><meta ......
is different from
<html>
<head>
<title>TITLE</title>
<meta ......
What option do I miss to accomplish what I need and threat as if it was the same?
git diff supports comparing files line by line or word by word, and also supports defining what makes a word. Here you can define every non-space character as a word to do the comparison. In this way, it will ignore all spaces including white-spcae, tab, line-break and carrige-return as what you need.
To achieve it, there's a perfect option --word-diff-regex, and just set it --word-diff-regex=[^[:space:]]. Refer to doc for detail.
git diff --no-index --word-diff-regex=[^[:space:]] <file1> <file2>
Here's an example. I created two files, with a.html as follows:
<html><head><title>TITLE</title><meta>
With b.html as follows:
<html>
<head>
<title>TI==TLE</title>
<meta>
By running
git diff --no-index --word-diff-regex=[^[:space:]] a.html b.html
It highlights the difference of TITLE and TI{+==+}TLE in the two files in plain mode as follows. You can also specify --word-diff=<mode> to display results in different modes. The mode can be color, plain, porcelain and none, and with plain as default.
diff --git a/d.html b/a.html
index df38a78..306ed3e 100644
--- a/d.html
+++ b/a.html
## -1 +1,4 ##
<html>
<head>
<title>TI{+==+}TLE</title>
<meta>
Executing command git diff --help gives some options like
--ignore-cr-at-eol
Ignore carriage-return at the end of line when doing a comparison.
--ignore-space-at-eol
Ignore changes in whitespace at EOL.
-b, --ignore-space-change
Ignore changes in amount of whitespace. This ignores whitespace at line end, and considers all other sequences of one or more whitespace
characters to be equivalent.
-w, --ignore-all-space
Ignore whitespace when comparing lines. This ignores differences even if one line has whitespace where the other line has none.
--ignore-blank-lines
Ignore changes whose lines are all blank.
Which you can combine according to your need, Below command worked for me
git diff --ignore-blank-lines --ignore-all-space --ignore-cr-at-eol
This does the trick for me:
git diff --ignore-blank-lines
git-diff compares files line by line
It checks the first line of your file1 with that in file2, since they are not same it reports an error.
Ignoring white space means that foo bar will match foobar if on the same line. Since your files span multiple lines in one and only one line in other, the files will always differ
If you really want to check that the files contain the exact same non-whitespace characters, you could try something like this:
diff <(perl -ne 's/\s*//xg; print' file1) <(perl -ne 's/\s*//g; print' file2)
Hope it solves your problem!

Unexpected link behavior after exporting Org-mode file to HTML

I am running Org-mode 8.2.6 in Emacs 24.3.1 on Windows 7 Ultimate and have encountered a peculiarity with how links work in HTML exported from Org-mode. I have used org-id extensively to assign unique IDs to headings in Org-mode files (stored in the :PROPERTIES: drawer of the heading).
Before the new exporter framework was introduced in Org-mode 8.0 all of these links worked without issue. No matter the level of the heading's hierarchy, exported-HTML ID-based links worked fine. However, using the new exporter framework produces different results. Now, ID-based links always fail when the target heading lies at a level below the headline level defined in the export settings, which defaults to level 3 (H:3). Note: This is true only for the exported HTML; ID-based links work perfectly within Emacs.
Here is a minimal example that demonstrates this behavior when I export it to HTML (see annotations for details):
* Headline Level 1
** Headline Level 2
*** Headline Level 3
:PROPERTIES:
:ID: 307db49e-e001-4a7b-9541-96eee2ae6f06
:END:
**** <<heading-level-4>>Non-headline level
:PROPERTIES:
:ID: 3be9179d-f838-4052-93ca-6c76c9aff12d
:END:
** Headline Level 2
*** Headline Level 3
Now I want to link to information that appears elsewhere in the file. Links work as
expected within Emacs. When exported to HTML, however, links do not work as they
did before the new exporter framework was introduced in Org-mode 8.0.
**** ID-based link: [[id:307db49e-e001-4a7b-9541-96eee2ae6f06][Headline Level 3]]
This link /does/ work. Using IDs always works for links to any headline level. By
"headline level" I mean any Org-mode heading that is defined as a headline
(default H:3).
**** ID-based link: [[id:3be9179d-f838-4052-93ca-6c76c9aff12d][Non-headline level]]
This link using the ID /doesn't/ work when exported to HTML using the new exporter
framework. Now, using IDs as the target for links /always/ fails for links to any
headline lower than the headline level defined in the export settings.
**** Non-ID-based link: [[heading-level-4][Non-headline level]]
Using an internal link works, but I have /many/ existing files that depend on IDs
for links at heading levels lower than the levels I want treated as (numbered)
headlines, and I also sometimes link to targets in other files, in which case,
using ID's creates a much simpler workflow.
If the file above is named demo-links.org the default output file is demo-links.html. The HTML for the target of the first working link looks like this:
<h4 id="sec-1-1-1"><a id="ID-307db49e-e001-4a7b-9541-96eee2ae6f06" name="ID-307db49e-e001-4a7b-9541-96eee2ae6f06"></a><span class="section-number-4">1.1.1</span> Headline Level 3</h4>
and the HTML for the link to it looks like this:
Headline Level 3
The link ID is part of the target code but isn't used in the linking code.
The HTML for the target of the non-working link looks like this:
<ul class="org-ul"><li><a id="heading-level-4" name="heading-level-4"></a>Non-headline level<br /><div class="outline-text-5" id="text-1-1-1-1"></div></li></ul>
Notice that the code that is generated does NOT contain the ID (3be9179d-f838-4052-93ca-6c76c9aff12d). Neither does it contain a section ID like the previous link did.
The HTML for the link to it looks like this:
Non-headline level
I believe the relevant code in ox-html.el appears following the comment "Links pointing to a headline" but I'm a novice (at best) with elisp.
My question is this: Is this behavior by design, or is there some setting I can alter that will make the export work the way it did before the new export framework was introduced?
I encounter the problem too. What's more, text enclosed between "<<" and ">>" can be showed in the exported HTML in org-7.9 while it can't be showed in org-8.2
With limited reputations, I can't vote the item up, so I just answer it without a correct answer here. (=_=)
Looking at the code of the org-html-headline function, it seems that the "standard headline" case (whatever is exported to hN) is handling the custom IDs specially:
(let* (...
(ids (remove nil
(list (org-element-property :CUSTOM_ID headline)
(concat "sec-" section-number)
(org-element-property :ID headline))))
(preferred-id (car ids)) ;; <- here, id for the header is sec-XXX
(extra-ids (cdr ids))
...)
(format ...
(format "outline-container-%s"
(or (org-element-property :CUSTOM_ID headline)
(concat "sec-" section-number)))
...
(format "\n<h%d id=\"%s\">%s%s</h%d>\n"
level1
preferred-id
(mapconcat
(lambda (x)
(let ((id (org-export-solidify-link-text
(if (org-uuidgen-p x) (concat "ID-" x)
x))))
(org-html--anchor id))) ;; <- generate a list of <a id=ID-XXX></a>
extra-ids "")
full-text
level1)
...))
That's where those <a id="ID-XXX" name="ID-XXX"></a> snippets come from (placeholder anchor, just to expose an additional ID)
Unfortunately, in the case of headlines that translate into list items, there is no such handling of ID/CUSTOM_ID, which quite frankly looks like a bug to me.
So while it is possible to rewrite org-html-headline to do the same treatment for list items, it's unfortunately not as easy as modifying a setting (and code modification would pretty fragile)
I would suggest opening a bug report, after all it seems to be a regression.

How to fold/unfold HTML tags with Vim

Is there some plugin to fold HTML tags in Vim?
Or there is another way to setup a shortcut to fold or unfold html tags?
I would like to fold/unfold html tags just like I do with indentation folding.
I have found zfat (or, equally, zfit) works well for folding with HTML documents. za will toggle (open or close) an existing fold. zR opens all the folds in the current document, zM effectively re-enables all existing folds marked in the document.
If you find yourself using folds extensively, you could make some handy keybindings for yourself in your .vimrc.
If you indent your HTML the following should work:
set foldmethod=indent
The problem with this, I find, is there are too many folds. To get around this I use zO and zc to open and close nested folds, respectively.
See help fold-indent for more information:
The folds are automatically defined by the indent of the lines.
The foldlevel is computed from the indent of the line, divided by the
'shiftwidth' (rounded down). A sequence of lines with the same or higher fold
level form a fold, with the lines with a higher level forming a nested fold.
The nesting of folds is limited with 'foldnestmax'.
Some lines are ignored and get the fold level of the line above or below it,
whichever is lower. These are empty or white lines and lines starting
with a character in 'foldignore'. White space is skipped before checking for
characters in 'foldignore'. For C use "#" to ignore preprocessor lines.
When you want to ignore lines in another way, use the 'expr' method. The
indent() function can be used in 'foldexpr' to get the indent of a line.
Folding html with foldmethod syntax, which is simpler.
This answer is based on HTML syntax folding in vim. author is #Ingo Karcat.
set your fold method to be syntax with the following:
vim command line :set foldmethod=syntax
or put the setting in ~/.vim/after/ftplugin/html.vim
setlocal foldmethod=syntax
Also note so far, the default syntax script only folds a multi-line
tag itself, not the text between the opening and closing tag.
So, this gets folded:
<div
class="foo"
id="bar"
>
And this doesn't
<div>
<b>text between here</b>
</div>
To get folded between tags, you need extend the syntax script, via
the following, best place into ~/.vim/after/syntax/html.vim
The syntax folding is performed between all but void html elements
(those which don't have a closing sibling, like <br>)
syntax region htmlFold start="<\z(\<\(area\|base\|br\|col\|command\|embed\|hr\|img\|input\|keygen\|link\|meta\|para\|source\|track\|wbr\>\)\#![a-z-]\+\>\)\%(\_s*\_[^/]\?>\|\_s\_[^>]*\_[^>/]>\)" end="</\z1\_s*>" fold transparent keepend extend containedin=htmlHead,htmlH\d
Install js-beautify command(JavaScript version)
npm -g install js-beautify
wget --no-check-certificate https://www.google.com.hk/ -O google.index.html
js-beautify -f google.index.html -o google.index.bt.html
http://www.google.com.hk orignal html:
js-beautify and vim fold:
Add on to answer by James Lai.
Initially my foldmethod=syntax so zfat won't work.
Solution is to set the foldemethod to manual
:setlocal foldmethod=manual
to check which foldmethod in use,
:setlocal foldmethod?
Firstly set foldmethod=syntax and try zfit to fold start tag and zo to unfold tags, It works well on my vim.