In MediaWiki (wikipedia's) wiki syntax, is there a way to have a numbered list with a code block in the middle?
For example:
# Number 1
# Number 2
Indented section that will become a code block
# Number 3
# Number 4
What happens in MediaWiki is you end up with something like this:
1. Number 1
2. Number 2
Indented section that will become a code block
1. Number 3
2. Number 4
(Note how "Number 3" and "Number 4" are reset as 1 and 2... It looks like StackOverflow is much smarter than MediaWiki, i had to put my example in PRE tags to make it screw up!)
I know you can indent text using "#:" syntax...
# Number 1
# Number 2
#: Indented section that will merely be indented
# Number 3
# Number 4
...but I really would like to get the same visual CSS class for my code even if it's in a numbered list.
It gets even more entertaining with nested lists. This syntax...
# MainEntry 1
## Number 1
## Number 2
# MainEntry 2
## Number 1
## Number 2
Indented section that will become a code block
## Number 3
## Number 4
...becomes...
1. MainEntry 1
1. Number 1
2. Number 2
2. MainEntry 2
1. Number 1
2. Number 2
Indented section that will become a code block
1. 1. Number 3
2. Number 4
(Note how "Number 3" is now "1. 1.")
You could try the following wiki syntax, it works for me on 1.17
# one
#:<pre>
#::some stuff
#::some more stuff</pre>
# two
It is not perfect, because you end up with a more indent but it does allow one to use the wiki syntax for correctly formatted pre blocks over multiple lines.
As previously mentioned, the other proper way would be to use HTML mark up.
<ol>
<li>one</li>
<li>two</li>
<pre>some stuff
some more stuff</pre>
<li>three</li>
</ol>
Use html:
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
it will work in mediawiki.
Note from the example that I posted below, it is the </li> that makes it work properly.
This works fine in MediaWiki 1.17.0:
===Alternative way of using pre in numbered lists.===
# Numbered line 1.
# Numbered line 2.<pre>code line 1
code line 2</pre>
# Numbered line 3.
The secret is to replace the newlines with the
entity and write everything in one line.
Your issue is the subject of two bugs filled in the MediaWiki bug tracker in late 2004 and 2005 :
Bug 1115 - Newline as list item terminator is troublesome
Bug 1584 - Need method for multiparagraph list items, continuing numbered lists, and assigning specific numbers to list items
By reading them, you will find the solution is to not use the MediaWiki syntax but to rely on "pure" HTML.
I'm suggesting a different answer: don't do it.
I've attempted to use all the workarounds for this basic Mediawiki issue and found that they are all very imperfect. I've learned to live without numbers, and instead:
Use the splat (*) instead of (#) for all my lists
Continue to use the leading space for all my code blocks
This is far far simpler and maintainable than any workaround. Besides, use of any reference to a number is subject to change as the steps are edited - and this then becomes another maintenance issue.
In the above example the second indentation (::) is not necessary.
Just one indentation works fine (:) as follows:
# one
#:<pre>
#:some stuff
#:some more stuff</pre>
# two
Produces:
1. one
some stuff (just one indent level, not two)
some more stuff
2. two
You can also try adding a "blockquote" tag surrounding the "pre" tag, makes it look a little more polished.
== HAProxy Configuration ==
#'''File:''' /etc/haproxy/haproxy.cfg
<blockquote>
<pre>
global
log 127.0.0.1 local1 notice
maxconn 4096
#daemon
debug
crt-base /usr/local/haproxy/ssl
</pre>
</blockquote>
Which will indent the gray box in line with your bullets/numbers without using colons.
Related
I have 8 images in a directory.
the path is /blabla.com/img.
I need to access this path and choose 3 out of 8 randomly and display those.
If 3 pics are the same, it should echo "yeeey".
Otherwise, "neeey" and record these responses in a text file.
I am not going to do your homework for you!
However I can give you some insight:
store your 8 file names in an array
call $RANDOM % 8 3 times and store the value in 3 index variables
use the 3 index variables to extract your 3 files
use sha256sum, sha512sum or md5sum to compute the signature of your images and store the result in 3 variables
compare the values of the 3 variables if they are the same echo "yeeey" else echo "neeey"
if on top of that you want to display the picture as written in your post you could call eog or other similar tool with the finename as parameter and of course in background, with a & at the end of the command call.
Good luck with your assignment and let me know if you need help!
let's array an array of distinct elements (for example 8):
array=({A..H})
(1) use RANDOM special variable modulo the number of elements to get a random number between 0 and number-1 inclusive
number=$((RANDOM%${#array[#]}))
the first random element is
first=${array[number]}
remove the element from array and reassign the array to reindex without gap (declare -p array to see)
unset array[number]
array=("${array[#]}")
restart from (1)
Basically, what I want to do is look at the range information of a unified diff and know exactly which lines of code I should pay attention to.
For instance, this:
## -1827,7 +1827,7 ##
This tells me that in total only 1 line has changed, because the diff shows 3 lines above and below the change (so 7 - 6 = 1), and it also points me to the line 1830 (i.e. 1827 + 3).
To be more pedantic, this particular range information actually tells me that at line 1830, a line was removed (-), and at line 1830 a line was added (+).
Or to make that more obvious consider this range information for another diff:
## -878,15 +878,13 ##
What this is telling me is that at line 881 (878 + 3) 9 lines were deleted (15 - 6), but at line 881 only 7 lines were added (13 - 6).
So the question is, using a regex or some other Ruby string method, how do I pull out the above information easily?
i.e. how do I easily pull out this info:
Both The line numbers (i.e. just the 1827 or 878), which I can then add + 3 to determine the actual inline number I care about. It has to be both because both lines may not always be identical.
The number of lines affected (aka the 7, 15 or 13 right after the , in the above examples)
While I do that, how do I make sure to track the operation (addition or deletion) for each of the operations.
I tried slicing the string and going directly for a character -- e.g. myString[3] which gives me -, but that's the only character it reliably works for because the line numbers can be 1, 10, 100, 1000, 10000, etc. So the only way is to just scan the string and then parse it.
Edit 1
To add some code to show what I have tried.
Assume I have the contents of a diff in a variable called #diff_lines:
#diff_lines.each do |diff_line|
if diff_line.start_with?("##")
del_line_num_start = diff_line.split(/## /).second.split.first.split(/-/).second.split(/,/).first.to_i + 3
num_deleted_lines = diff_line.split(/## /).second.split.first.split(/-/).second.split(/,/).second.to_i - 6
add_line_num_start = diff_line.split(/## /).second.split.second.split(/\+/).second.split(/,/).first.to_i + 3
num_added_lines = diff_line.split(/## /).second.split.second.split(/\+/).second.split(/,/).second.to_i - 6
As you can see, the above works....but it is quite horrendous to look at and is OBVIOUSLY not very DRY.
Ideally I would like to be able to achieve the same thing, but just cleaner.
The general idea is to write a regular expression that has capture groups in it ((...)) to pick apart that string into something useful. For example:
diff_line.match(/\A##\s+\-(\d+),(\d+)\s+\+(\d+),(\d+)\s+##/)
This yields a MatchData object on a successful match. You can then apply this to some variables like:
if (m = diff_line.match(...))
a_start, a_len, b_start, b_len = m[1..4].map(&:to_i)
end
Then you can do whatever computations you need to do with these numbers.
If you're ever having trouble visualizing what a regular expression does, try a tool like Rubular to better illustrate the internals.
I am making a series of design documents in Sphinx and I would like to include them together in a toctree and have the sections within the documents numbered. I know that I can use .. sectnum:: to number all sections in the child pages. However, Sphinx/rst numbers the title of the page (which is really just the first section) and the table of contents ends up looking like:
Table of Contents
1 Design the First
2 Design the Second
and each child page looks like:
1 Design the First
1.1 First Section
1.2 Second Section
What I want is a table of contents on my index page that just lists the title
Table of Contents
Design The First
Design the Second
and child page that look like
Design the First
1 First Section
2 Second Section
Is there a way to have a title that shows up in the TOC as well as on the top of a child page which does not end up being a numbered section?
I don't know what you ended up doing, but I wanted to do the exact same thing! I had the following setup:
index.rst
.. toctree::
assignment
library_api
I only wanted the assignment part to have numbers, so either could have done two separate toctree with one using :numbered:, or put at the top of the file
.. sectnum::
:start: 0
Giving of course the exact problem you mention -- my top-level title was Assignment Writeup, so that was 0 and everything below it in subsections was 0.x e.g.
Assignment Writeup
==================
First Task
----------
Second Task
-----------
gives
0. Assignment Writeup
0.1 First Task
0.2 Second Task
as it turns out, there's an easy hack you can do. It makes things more modular than probably desired, but "add a layer of indirection".
So now I have assignment.rst and assignment_writeup.rst. assignment.rst just basically has a title and a toctree:
Assignment Writeup
==================
.. toctree::
:maxdepth: 4
assignment_writeup
then take all sub-sections and put them in assignment_writeup and "upcast" their heading level. So I now take all subsections and make them sections, and subsub and make them sub.
.. sectnum::
:start: 0
First Task
==========
^^^ === instead of --- now
Second Task
===========
and we now finally have
Assignment Writeup
0. First Task
1. Second Task
kind of dubious, but this was the only way I could achieve it x0 I wonder what you did between asking this and now? Hopefully somebody will see this and benefit one day!
Note: this has undesireable side-effects. The Assignment Writeup shows up on its own page, with just Links to the indirect document. Not sure which is worse honestly...
I have a scenario outline table that looks like the following:
Scenario Outline: Verify Full ad details
Given I am on the xxx classified home page
And I have entered <headline> in the search field & clicked on search
When I click on full details
Then I should see <headline> <year> <mileage> <price> displaying correctly and successfully
Examples:
|headline |year |mileage |price |
|alfa romeo 166 |2005 |73,000 |6,990 |
When I run my scenario it spits out that I have 6 args.
But what I thought, I should only have 4 args: headline, year, mileage and price.
I am thinking that it is taking the comma's and what is before and after it as two seperate args.
Is there any way that I can make cucumber think that there are only 4 args with the example below?
I have looked at messing around with regex but I dont seem to be getting anywhere.
Any help would be greatly appreciated.
I assume it is the last step that you are having issues with.
When I tried the last step, the default Cucumber step given was:
Then /^I should see alfa romeo (\d+) (\d+) (\d+),(\d+) (\d+),(\d+) displaying correctly and successfully$/ do |arg1, arg2, arg3, arg4, arg5, arg6|
pending # express the regexp above with the code you wish you had
end
I am not sure how Cucumber determines the suggest step definition, but this is not one that will work for you. As you said, there are incorrectly 6 arguments. As well, the step will only match examples where the headline starts with 'alfa romeo'.
Changing the step definition to the following will solve your current scenario example:
Then /^I should see (.+) (\d+) ([\d|,]+) ([\d|,]+) displaying correctly and successfully$/ do |arg1, arg2, arg3, arg4|
puts arg1 #=> alfa romeo 166
puts arg2 #=> 2005
puts arg3 #=> 73,000
puts arg4 #=> 6,990
end
Two changes:
1) The comma formatted numbers were changed to:
([\d|,]+)
which means that it will matching any number or comma character. If your numbers can also include decimals, you'll want something like:
([\d|,|.]+)
2) The heading was also changed so that it to get the entire headline rather than just the ending number.
As 73,000/6,990 is just an int, can you just enter it as 73000/6990 (without the commas)? I dont see this causing a problem, unless you require this format for some reason?
A good way of formatting numbers in this case is to use underscores instead of commas or periods. You avoid locale issues (1.000 vs 1,000) and keep some formatting.
|headline |year |mileage |price |
|alfa romeo 166 |2005 |73_000 |6_990 |
I'm trying to read files and create a hashmap of the contents, but I'm having trouble at the parsing step. An example of the text file is
put 3
returns 3
between
3
pargraphs 1
4
3
#foo 18
****** 2
The word becomes the key and the number is the value. Notice that the spacing is fairly erratic. The word isn't always a word (which doesn't get picked up by /\w+/) and the number associated with that word isn't always on the same line. This is why I'm calling it not well-formed. If there were one word and one number on one line, I could just split it, but unfortunately, this isn't the case. I'm trying to create a hashmap like this.
{"put"=>3, "#foo"=>18, "returns"=>3, "paragraphs"=>1, "******"=>2, "4"=>3, "between"=>3}
Coming from Java, it's fairly easy. Using Scanner I could just use scanner.next() for the next key and scanner.nextInt() for the number associated with it. I'm not quite sure how to do this in Ruby when it seems I have to use regular expressions for everything.
I'd recommend just using split, as in:
h = Hash[*s.split]
where s is your text (eg s = open('filename').read. Believe it or not, this will give you precisely what you're after.
EDIT: I realized you wanted the values as integers. You can add that as follows:
h.each{|k,v| h[k] = v.to_i}