Following the Bookdown manual, I'm trying to create a two-level list for gitbook output. Bookdown says I should do this:
+ one
+ two
+ two-a
+ two-b
Which should look like
one
two
two-a
two-b
But instead Bookdown seems to be ignoring the + and seeing it as a code chunk because of the indent, and I get this:
one
two
two-a
two-b
If I just knit the chapter to HTML, the list renders properly. Any ideas what I'm doing wrong?
Depending on which bookdown/pandoc version you're using this may have changed to align with CommonMark.
Try indenting it with only two spaces:
+ one
+ two
+ two-a
+ two-b
From the current MANUAL:
List items may include other lists. In this case the preceding blank line is optional. The nested list must be indented to line up with the first non-space character after the list marker of the containing list item.
Related
I am trying to extract a (variable) substring from a longer result output string in a cell.
=SPLIT(TRIM(REGEXEXTRACT($Z3,“.(?s)+\([R][1][-][1][M]\)\s+\w+\s+\w+\s+\w+\s+[-]+\s+(.*)“)),1)
Typical content of cell Z3 is:
(F1-1D) Unique identifier schemes found [‘url’], (R1-1M) Resource type specified - webpage, (R1.2-1M) Found date-related picture information, (A1-2M) Access to metadata found: slurp
I want to extract the word between - and , following (R1-1M).
In this example it is webpage.
The string can contain any number of the comma-separated elements.
EDIT
Taking a better look at the OP's question
I want to extract the word between - and , following (R1-1M).
In this example it is webpage.
The string can contain any number of the comma-separated elements.
I believe the whole formula can be further simplified to
=REGEXEXTRACT($A$3, "- (\w+),")
Original answer
You can try the following
=REGEXEXTRACT($A$3, "(\w+),[ \(R1\.2\-1M\)]")
or even
=REGEXEXTRACT($A$3, "[\(R1\-1M\)] (\w+),")
(Do adjust ranges to your needs)
try:
=ARRAYFORMULA(TRIM(FLATTEN(QUERY(TRANSPOSE(IFNA(REGEXEXTRACT(
IFERROR(SPLIT(A1:A, ",")), "\(R1-1M\).+- (.+)"))),,9^9))))
I have a text in cell (A1) like this:
✌😋👅👅☝️😉🍌🍪💧💧
I want to extract the unique emojis from this cell into separate cells:
✌😋👅☝️😉🍌🍪💧
Is this possible?
You want to put each character of ✌😋👅👅☝️😉🍌🍪💧💧 to each cell by splitting using the built-in function of Google Spreadsheet.
Sample formula:
=SPLIT(REGEXREPLACE(A1,"(.)","$1#"),"#")
✌😋👅👅☝️😉🍌🍪💧💧 is put in a cell "A1".
Using REGEXREPLACE, # is put to between each character like ✌#😋#👅#👅#☝#️#😉#🍌#🍪#💧#💧#.
Using SPLIT, the value is splitted with #.
Result:
Note:
In your question, the value of ️ which cannot be displayed is included. It's \ufe0f. So "G1" can be seen like no value. But the value is existing. So please be careful this. If you want to remove the value, you can use ✌😋👅👅☝😉🍌🍪💧💧.
References:
REGEXREPLACE
SPLIT
Added:
From marikamitsos's comment, I could notice that my understanding was not correct. So the final result is as follows. This is from marikamitsos.
=TRANSPOSE(UNIQUE(TRANSPOSE(SPLIT(REGEXREPLACE(A1,"(.)","$1#"),"#"))))
or try:
=TRANSPOSE(UNIQUE(TRANSPOSE(REGEXEXTRACT(A1, REPT("(.)", LEN(A1))))))
Formula
Appears, one of the best formula solutions would be:
=SPLIT(REGEXREPLACE(A1,"(.)","$1#"),"#")
You may also add some additional checks like skin tones & intermediate chars:
=TRANSPOSE(SPLIT(REGEXREPLACE(A2,"(.[🏻🏼🏽🏾🏿"&CHAR(8205)&CHAR(65039)&"]*)","#$1"),"#"))
It will help to join some emojis as a single emoji.
Script
More precise way is to use the script:
https://github.com/orling/grapheme-splitter/blob/master/index.js
↑
Add the code to Script editor
Add code for sample usage:
function splitEmojis(string) {
var splitter = new GraphemeSplitter();
// split the string to an array of grapheme clusters (one string each)
var graphemes = splitter.splitGraphemes(string);
return graphemes;
}
Tests
Not 100% precise
1
Please note: some emojis are not correctly shown in sheets
🏴🏴🏴🏴
↑ emojis:
flag: England
flag: Scotland
flag: Wales
black flag
are the same for Google Sheets.
2
Vlookup function in #GoogleSheets and in #Excel thinks chars
#️⃣ and
*️⃣
are the same!
I have the following strings which indicate a hierarchy:
JHW/1/24/3/562 // child row
JHW/1/24/3 // parent of the above
JHW/1/24 // parent of the above
JHW/1 // parent of the above
JHW // parent of the above
What I'd like to do is to be able to pull out all of the "parent" rows with one regex.
The closest I've got conceptually (which isn't anywhere near) is #^([^/]*/)+# which just matches the second-last section [eg. 3].
I've never really tried to do something like this before, where I'm trying to get overlapping results - it is possible? It's not an issue if it brings back the child row as one of the matches.
You can't obtain several results from the same position (since the regex engine go to the next character after each try of the pattern), you can explode the string with / and build each path you need with the array items.
An other possible way consists to reverse the string:
preg_match_all('~(?=(?:\A|/)(.+))~', strrev($path), $m);
$result = array_map('strrev', $m[1]);
I have a file with long lines and need to see/ copy what the values are in a specic location(s) for the whole file but copy the rest of the line.
If the text width is small enough, ~184 columns, I can use :set colorcolumnnum to highlight the value. However over 184 characters it gets a bit unwieldy scrolling.
I tried :g/\%1237c/y Z, for one of the positions I needed, but that yanked the entire line.
eg for a smaller sample :g/\%49c/y Z will yank all of line 1 and 2 but I want to yank, or copy, the character at that column ie = on line 1 and x on line 2.
vim: filetype=help foldmethod=indent foldclose=all modifiable noreadonly
Table of Contents *sfcontents* *vim* *regex* *sfregex*
*sfsearch* - Search specific commands
|Ampersand-replaces-previous-pattern|
|append-a-global-search-to-a-register|
*sfHelp* Various Help related commands
There are two problems with your :g command:
For each matching line, the cursor is positioned on the first column. So even though you've matched at a particular column, that position is lost.
The \%c atom actually matches byte indices (what Vim somewhat confusingly names "columns"), so your measurement will be off for Tab and non-ASCII characters. Use the virtual column atom \%v instead.
Instead of :global, I would use :substitute with a replace-expression, in the idiom described at how to extract regex matches using vim:
:let t=[] | %s/\%49v./\=add(t, submatch(0))[-1]/g | let ## = join(t, "\n")
Alternatively, if you install my ExtractMatches plugin, I'd be that short command invocation:
:YankMatchesToReg /\%50v./
I decide to learn more about vim and its syntax highlighting.
Using examples for others, I am creating my own syntax file for Markdown. I have seen mkd.vim and it has this problem too.
My issue is between list items and code block highlighting.
Code Block definition:
first line is blank
second line begins with at least 4 spaces or 1 tab
block is finished with a blank line
Example:
Regular text
this is code, monospaced and left untouched by markdown
another line of code
Regular Text
My Vim syntax for code block:
syn match mkdCodeBlock /\(\s\{4,}\|\t\{1,}\).*\n/ contained nextgroup=mkdCodeBlock
hi link mkdCodeBlock comment
Unorder List item definition:
first line is blank
second line begins with a [-+*] followed by a space
the list is finished with a blank line then a normal (non-list) line
in between line items any number of blank lines can be added
a sub list is specified by indenting (4 space or 1 tab)
a line of normal text after a list item is include as a continuation of that list item
Example:
Regular text
- item 1
- sub item 1
- sub item 2
- item 2
this is part of item 2
so is this
- item 3, still in the same list
- sub item 1
- sub item 2
Regular text, list ends above
My Vim syntax for unorder list item definition (I only highlight [-+*]):
syn region mkdListItem start=/\s*[-*+]\s\+/ matchgroup=pdcListText end=".*" contained nextgroup=mkdListItem,mkdListSkipNL contains=#Spell skipnl
syn match mkdListSkipNL /\s*\n/ contained nextgroup=mkdListItem,mkdListSkipNL skipnl
hi link mkdListItem operator
I cannot get the highlighting to work with the last two rule for list and with a code block.
This is an example that breaks my syntax highlighting:
Regular text
- Item 1
- Item 2
part of item 2
- these 2 line should be highlighted as a list item
- but they are highlighted as a code block
I currently cannot figure out how to get the highlighting to work the way I want it too
Forgot to add a "global" syntax rule used in both rules listed below. It is to ensure a that they start with a blank line.
syn match mkdBlankLine /^\s*\n/ nextgroup=mkdCodeBlock,mkdListItem transparent
Another Note: I should have been more clear. In my syntax file, the List rules appear before the Blockquote Rules
Just make sure that the definition of mkdListItem is after the definition of mkdCodeBlock, like this:
syn match mkdCodeBlock /\(\s\{4,}\|\t\{1,}\).*\n/ contained nextgroup=mkdCodeBlock
hi link mkdCodeBlock comment
syn region mkdListItem start=/\s*[-*+]\s\+/ matchgroup=pdcListText end=".*" contained nextgroup=mkdListItem,mkdListSkipNL contains=#Spell skipnl
syn match mkdListSkipNL /\s*\n/ contained nextgroup=mkdListItem,mkdListSkipNL skipnl
hi link mkdListItem operator
syn match mkdBlankLine /^\s*\n/ nextgroup=mkdCodeBlock,mkdListItem transparent
Vim documentation says in :help :syn-define:
"In case more than one item matches at the same position, the one that was
defined LAST wins. Thus you can override previously defined syntax items by
using an item that matches the same text. But a keyword always goes before a
match or region. And a keyword with matching case always goes before a
keyword with ignoring case."
hcs42 was correct. I do remember reading that section now, but I forgot about it until hcs24 reminded me about it.
Here is my updated syntax (few other tweaks) that works:
"""""""""""""""""""""""""""""""""""""""
" Code Blocks:
" Indent with at least 4 space or 1 tab
" This rule must appear for mkdListItem, or highlighting gets messed up
syn match mkdCodeBlock /\(\s\{4,}\|\t\{1,}\).*\n/ contained nextgroup=mkdCodeBlock
"""""""""""""""""""""""""""""""""""""""
" Lists:
" These first two rules need to be first or the highlighting will be
" incorrect
" Continue a list on the current line or next line
syn match mkdListCont /\s*[^-+*].*/ contained nextgroup=mkdListCont,mkdListItem,mkdListSkipNL contains=#Spell skipnl transparent
" Skip empty lines
syn match mkdListSkipNL /\s*\n/ contained nextgroup=mkdListItem,mkdListSkipNL
" Unorder list
syn match mkdListItem /\s*[-*+]\s\+/ contained nextgroup=mkdListSkipNL,mkdListCont skipnl
Tao Zhyn, that maybe covers your use cases but it doesn't cover the Markdown syntax. In Markdown a list item could contain a code block. You could take a look at my solution here
TL;DR; the problem is that vim doesn't let you say something like: a block that have the same indentation as its container + 4 spaces. The only solution I found is to generate rules for each kind of blocks that could be contained in a list items for each level of indentation (actually I support 42 level of indentation but it's an arbitrary number)
So I have markdownCodeBlockInListItemAtLevel1 that must be contained in a markdownListItemAtLevel1 and it needs to have at least 8 leading spaces, an then markdownCodeBlockInListItemAtLevel2 that must be contained in a markdownListItemAtLevel2 that must be contained in a markdownListItemAtLevel1 ant needs to have at least 10 leading spaces, ecc...
I know that a few years have passed but maybe someone would consider this answer helpful since all syntax based on indentation suffers of the same problem