How to prevent Markdown's list from eating spaces? - list

I have:
- `foo`: some text Default: false
- `barThatIsTooLong`: again some text Default: true
but in Bitbucket README, whitespaces will be eaten automatically, and this will be displayed as:
foo: some text Default: false
barThatIsTooLong: again some text Default: true
I would like to have the default values vertically aligned.
How to tell Bitbucket's markdown to not eat my spaces? Is it even possible?

You probably can't, unless you use tables instead of lists.
| Variable | Description | Default |
| -------------------|---------------- | ------- |
| `foo` | some text | false |
| `barThatIsTooLong` | again some text | true |
If you are using a site which doesn't strip out raw HTML and/or style attributes, then inline floats might work:
- `foo`: some text <span style="float:right; width:10em;">Default: false</span>
- `barThatIsTooLong`: again some text <span style="float:right; width:10em;">Default: true</span>
The long answer
Collapsing whitespace is a "feature" of HTML, of which Markdown is a subset. The "feature" is often referred to as "insignificant whitespace." The idea is that all whitespace (spaces, tabs, newlines, etc.) is collapsed into a single space (see a summary of whitespace behavior options). Note that this collapse of whitespace is being done by your browser, not the Markdown parser. If you use your browser's "view source" of "inspect" feature, you will see that the HTML list retains the whitespace:
<ul>
<li><code>foo</code>: some text Default: false</li>
<li><code>barThatIsTooLong</code>: again some text Default: true</li>
</ul>
In other words, Markdown is not eating your whitespace, your browser is. So the next question is how to preserve whitespace in HTML and how that can be incorporated into your Markdown. There are a number of different ways to do that, but, in the end, they will not work as you desire.
The <pre> tag preserves whitespace, but is a block-level tag and not for inline use. As you only want some inline whitespace, preserved, not the entire block of text, this is not useful.
The whitespace:pre CSS rule could be used to get that effect, but will look ugly in your Markdown. Also, Bitbucket may strip your style tags for security reasons (SO does).
- `foo`: some text<span style="white-space:pre"> </span>Default: false
- `barThatIsTooLong`: again some text<span style="white-space:pre"> </span>Default: true
As non-breaking spaces are not collapsed, you could use them rather than regular spaces. In fact, you only need every other space to be a non-breaking space. But, again, it is ugly. Even worse, as non-breaking spaces are entered as HTML entities, one displayed character is 6 characters long in your Markdown, so the columns don't line up properly in the source document.
- `foo`: some text Default: false
- `barThatIsTooLong`: again some text Default: true
But even if you get one of the above to work, the browser probably still won't display your list as you desire. Bitbucket, like most websites do not use monospace fonts for their website (except in code blocks). Therefore, the width of each letter in a line is not equal and your columns still won't line up. Notice that the same situation exists here on SO. The last example above renders like this:
foo: some text Default: false
barThatIsTooLong: again some text Default: true
You can see the same effect in your editor. If you change the font from a monospace font to a proportional font you will notice that the columns will misalign. And that misalignment will vary with each different proportional font. Therefore, simply adjusting the number of spaces won't guarantee proper alignment. You may even end up with a half-width misalignment.
Of course, websites have columns all the time. But those columns are not "faked" with inline text. Each column is wrapped in its own block-level element and CSS rules position and size the containing box appropriately as demonstrated in this answer. But again, that requires raw HTML and CSS which Bitbucket is likely to not allow for security reasons.
One other option might be to use inline floats:
- `foo`: some text <span style="float:right; width:10em;">Default: false</span>
- `barThatIsTooLong`: again some text <span style="float:right; width:10em;">Default: true</span>
This causes the <span> to be floated to the far right edge of the containing block (the list item). To avoid the floated items appearing right aligned, we have included the width which ensures that each <span> is the same width. The actual width needs to be at least as wide as the largest text within the span. However, there is still the fact that Bitbucket will likely strip out the raw HTML for security reasons.
However, Bitbucket's Markdown implementation does support simple tables. So if you really want columns, you could implement them as tables. Of course, you would need to have table rows rather than list items in addition to column headers, which you may or may not want.
| Variable | Description | Default |
| -------------------|---------------- | ------- |
| `foo` | some text | false |
| `barThatIsTooLong` | again some text | true |

Related

RegEx to format Wikipedia's infoboxes code [SOLVED]

I am a contributor to Wikipedia and I would like to make a script with AutoHotKey that could format the wikicode of infoboxes and other similar templates.
Infoboxes are templates that displays a box on the side of articles and shows the values of the parameters entered (they are numerous and they differ in number, lenght and type of characters used depending on the infobox).
Parameters are always preceded by a pipe (|) and end with an equal sign (=). On rare occasions, multiple parameters can be put on the same line, but I can sort this manually before running the script.
A typical infobox will be like this:
{{Infobox XYZ
| first parameter = foo
| second_parameter =
| 3rd parameter = bar
| 4th = bazzzzz
| 5th =
| etc. =
}}
But sometime, (lazy) contributors put them like this:
{{Infobox XYZ
|first parameter=foo
|second_parameter=
|3rd parameter=bar
|4th=bazzzzz
|5th=
|etc.=
}}
Which isn't very easy to read and modify.
I would like to know if it is possible to make a regex (or a serie of regexes) that would transform the second example into the first.
The lines should start with a space, then a pipe, then another space, then the parameter name, then any number of spaces (to match the other lines lenght), then an equal sign, then another space, and if present, the parameter value.
I try some things using multiple capturing groups, but I'm going nowhere... (I'm even ashamed to show my tries as they really don't work).
Would someone have an idea on how to make it work?
Thank you for your time.
The lines should start with a space, then a pipe, then another space, then the parameter name, then a space, then an equal sign, then another space, and if present, the parameter value.
First the selection, it's relatively trivial:
^\s*\|\s*([^=]*?)\s*=(.*)$
Then the replacement, literally your description of what you want (note the space at the beginning):
| $1 = $2
See it in action here.
#Blindy:
The best code I have found so far is the following : https://regex101.com/r/GunrUg/1
The problem is it doesn't align the equal signs vertically...
I got an answer on AutoHotKey forums:
^i::
out := ""
Send, ^x
regex := "O)\s*\|\s*(.*?)\s*=\s*(.*)", width := 1
Loop, Parse, Clipboard, `n, `r
If RegExMatch(A_LoopField, regex, _)
width := Max(width, StrLen(_[1]))
Loop, Parse, Clipboard, `n, `r
If RegExMatch(A_LoopField, regex, _)
out .= Format(" | {:-" width "} = {2}", _[1],_[2]) "`n"
else
out .= A_LoopField "`n"
Clipboard := out
Send, ^v
Return
With this script, pressing Ctrl+i formats the infobox code just right (I guess a simple regex isn't enough to do the job).

EOLs in a string from a form

Mostly a logical question, not about a code.
I decided to make a 'bulleted list trimmer': some kind of a script which deletes things like 2.1.1 from the beginning of list elements. In a text like the following:
Federal law № 296-FR «Carbon emission restrictions» from 02.07.2021.
President's executive order № 176 from 19.04.2017 «Approval of ecological safety strategy 2020-2025».
You paste it in a form, click 'submit' and then get a list stripped of numbers. Thought it was easy.
I wrote a code:
if (isset($_POST['textinput']))
{$textinput = $_POST['textinput'];}
$textoutput = preg_replace('#^\s*\d+\.?\d*#','__PHP_EOL__',$textoutput);
Then mated it to a form with $textinput textarea. It had to find spaces/tabs, then 1+ digits, then ., then 0+ digits again in the beginning of a line. So here it comes, the problem.
There are no EOLs in input textarea and corresponding $_POST element, so the '^' symbol helps only once.
If I remove '^' in regexp, it will cut out all the parts with a \s*\d+.?\d* pattern, including federal regulations numbers and dates.
I suggest I need to get EOLs in a $textinput string somehow but I still don't know whether it is possible or not. So I ask everyone for a correct ideas how to make my 'bullet list trimmer'

Splunk - check logs that are equal to any string I provide

I want to capture only the logs that hold the values of "Zero tolerance", "bolt from the blue", "A change is as good as a rest" inside. I've tried with this but it doesn't work it only captures the first one. /description=(?Zero tolerance | bolt from the blue | A change is as good as a rest)
Have in mind that the strings to check needs to be provided by me.
code = random05, description=bird in the hand is worth two in the bush, level=5
code = random02, description=bolt from the blue, level=8
code = random09, description=bunch of fives, level=3
code = random05, description=A chain is only as strong as its weakest link, level=0
code = random08, description=A change is as good as a rest, level=3```
There are more logs but they are not showing.
It looks like you want to match anything after description that contains one of the strings you specified. You can then use
description=(?<des>.*(?:Zero tolerance|bolt from the blue|A change is as good as a rest).*)
So, here, "des" group will match any zero or more chars other than line break chars as many as possible, then one of the specified strings (note the spaces around | are removed) and then again any zero or more chars other than line break chars as many as possible.
If you need to limit the match by the first comma, replace . with [^,].

Extract Regex Values (Regex Match) in Blue Prism

In Blue Prism, I need to identify specific elements of a Data Item (text), in order to use the information later in my process.
The text string reads:
REKVISITION_NR: 1234567 Dato: 23-07-2018 Rekvirent: ABC, DEF GHI, JKL 60, 8600 MNO Sted: JKL 60, 8600 MNO, Kl.:14:00:00, Bestilt_tid: 60 min Tolkensnavn: PQR STU Koert_fra: VXY , 8600 Silkeborg Vedr.: Z CPR: 123456-7890 Sprog: Arabisk Type: Personlig fremmøde Godkendt: 24-07-2018
As you can see, each element has these traits (e.g. Kl.:14:00:00 or Sprog: Arabisk):
A string name (starting with an uppercase letter)
Optionally, a period character (.)
A colon character (:)
Optionally, a space character ( )
The value part of the string
A space character ( ), which is followed by the next element.
I believe I should use the Business Object Utility - Strings' action Extract Regex Values, but have not sucessfully been able to match any data that can be copied into the Named Values-collection.
However, I have found that ([A-Z])\w+\.?: ?(\w(\d\-){0,3})+ brings me some of the way in terms of matching.
I want the solution to copy the field names and values into the Named Values collection generated by the action.
Final notes: I am using Blue Prism 6.2.1, and the action's underlying code is based on VB.net's Regex.Match method.
What you seem to be missing are the actual Named Groups. To capture the values in a Blue Prism collection, you need to make sure that you assign proper group names like this:
(?<YourGroupName>[A-Z])
Here's the regex pattern that you may use, although you need to verify if it really works for your case in all possible scenarios.
(?<Name>\b\S*?):\s(?<Value>.*?)\s*(?=(?:\b\S*?:\s)|$)
You can also check and test it here.
EDIT: But please be aware that Blue Prism's original code for extracting multiple values to a collection is barely usable, you may be better off at modifying it or creating your own. For example, what I would expect from such an action is a collection where each row will be a pattern match, with each column being a named group. Sadly, that's not how the default action works.
EDIT:

Copying only the value at column n Vim

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./