How can I show how to make code block in Markdown within a code block? - commonmark

I tried this:
```text
```bash
```
```
but in CommonMark (see http://spec.commonmark.org/dingus/?text=%60%60%60text%0A%60%60%60bash%0A%60%60%60%0A%60%60%60) it doesn't work.
What I want
<pre><code data-sourcepos="1:1-3:7" class="language-text">```bash
```
</code></pre>
What I get
<pre><code data-sourcepos="1:1-3:7" class="language-text">```bash
</code></pre>
<pre><code data-sourcepos="4:1-4:3"></code></pre>

Simply create an outer code block with more backticks than the inner one:
````text
```bash
```
````
commonmark.js dingus
From the CommonMark spec:
A code fence is a sequence of at least three consecutive backtick characters (`) or tildes (~). (Tildes and backticks cannot be mixed.) A fenced code block begins with a code fence, indented no more than three spaces.
[...]
The content of the code block consists of all subsequent lines, until a closing code fence of the same type as the code block began with (backticks or tildes), and with at least as many backticks or tildes as the opening code fence.
(Emphasis mine.)

Related

How to add a page break before header automatically in pandoc

I need to convert a markdown document into a Word document.
I need it so that before each header there is a page break.
For example, here, a page break would be inserted before # Heading 1 and before # Heading 2. I wouldn't mind if it skipped the very first one if there is no content before it in the document.
# Heading 1
Hello
# Heading 2
World
I have found this Lua filter, but, as far as I understand, it's just for Latex and it's not automatic.
I have tried to write a Lua script myself, but failed, because I do not understand well how pandoc works.
For example, I have tried returning a Para with the contents of the previous one + a page break from the Header function like this:
function Header(el)
if el.level == 1 then
local t = { pandoc.RawBlock('openxml', '<w:p><w:r><w:br w:type="page"/></w:r></w:p>'), el }
return pandoc.Para(t)
end
return el
end
However, it just ends up wiping all of the headers.
I have tried a few other alterations of the same idea, neither of which worked.
The trouble in Lua is mainly the fact that there is no static analysis and no Intellisense. I may be doing something completely inadequate in this code without any compiler errors and without even realising it.
I believe the following should fix that:
local pagebreak = '<w:p><w:r><w:br w:type="page"/></w:r></w:p>'
function Header(el)
if el.level == 1 then
-- return both the page break and the header as a list
return { pandoc.RawBlock('openxml', pagebreak), el }
end
-- No `return el` needed, as not returning any value is the same as
-- returning the original value.
end
The error reporting of pandoc during unmarshalling, i.e., while retrieving objects from Lua, is not great, to say the least. Ideally, pandoc should report the type error that comes from wrapping a list of "blocks" in a Para, as that constructor should only accept "inlines".
In case you are curious: I'm working on fixing this by switching to a different marshalling strategy, see this PR. It's taking a while, but we'll get there.

Issue in pexpect when text wraps within session

I am working on a pexpect script that is running populating an output file name and then a prompt for the file's parameters.
The program that the script runs asks for Device: then Parameters: always on the same line.... so if the file path-name that is entered for Device is long, sometimes the Parameters prompt wraps to the next line.
My code looks like..
child.expect_exact('Device:')
child.sendline('/umcfiles/ftp_dir/ftp_peoplesoft/discount/AES_DISCOUNT_15010.TXT')
child.expect_exact('Parameters:')
This times out.. and here is what is in child.before
' /umcfiles/ftp_dir/ftp_peoplesoft/discount/AES_DISCOUNT_15010.TXT Param\r\neters: "RWSN" => '
so the expect fails... (a child.expect('Parameters:') also fails)
How can I ignore the \r\n if it is there, because depending on the length of the path/filename I am using it may not be there at all, or be in a different position.
Thanks!
Actually... I found a way to calculate how much is left on the given line, and dynamically set my expect to how much of the Parameter prompt should be visible... seems to be working
#look for end of line and fix how much of 'Parameters:' we look for in pexpect
dlen = 80-len('Device: /umcfiles/ftp_dir/ftp_peoplesoft/discount/AES_DISCOUNT_15010.TXT')
pstr='Parameters:'
if dlen > len(pstr):
dlen=len(pstr)
else:
dlen=dlen-3 #remove the /r/n
child.expect(pstr[0:dlen])

code blocks don't work in Spyder (Anaconda3)

I am a beginner in Python using Spyder to code from Anaconda3.
I tried to enter such codes in Spyder (Python 3.7). I pressed "Enter" when trying to split the codes and the indents appear auto. But it always returns with "SyntaxError: invalid syntax" and "SyntaxError: 'return' outside function".
E.g. 1
data = {'state':['Ohio','Ohio','Ohio','Nevada','Nevada','Nevada'],
'year':[2000,2001,2002,2001,2002,2003],
'pop':[1.5,1.7,3.6,2.4,2.9,3.2]}
When I press F9 in either line, it returns "SyntaxError: invalid syntax".
E.g. 2
def f(x):
return pd.Series([x.min(),x.max()],index=['min','max'])
Press F9 to run the line, it returns "SyntaxError: unexpected EOF while parsing". If in the second line, it returns "SyntaxError: 'return' outside function".
In addition, I also tried to put "\"s at the end of each line. It doesn't work either. And find from webpages that if the lines end with : or , then you don't need \ to split.
But!!! if I deleted the 'Enters' and put everything in a single line without splits, it works well totally.
Why my python cannot work with code blocks? How can I fix it with Anaconda3?
Thank you so much~~~~
The problem is that you need to select the entire function before pressing F9, if you select only a part of it it will raise an error
You can use \ at the end of each line to tell Python that the line continues below:
data = {\
'state':['Ohio','Ohio','Ohio','Nevada','Nevada','Nevada'],\
'year':[2000,2001,2002,2001,2002,2003],\
'pop':[1.5,1.7,3.6,2.4,2.9,3.2]\
}
Having the dictionary split across multiple lines may look pretty, but it is not proper syntax. I've also been tripped up by tutorials that show their dictionaries like that :|
This may not work in interpreters other than IDLE.

How do I command the Rascal Shell not to truncate my output if it's quite long

This seems like a pretty basic question to me, but I don't seem to be able to find the answer anywhere. I need to get the full output of a command in the Rascal shell, however, Rascal seems to truncate long outputs automatically. Is there any way to tell the shell to always show the full output for a given command.
Example:
rascal>calculateCodeDuplication("smallsql0.21_src")
list[list[loc]]: [
[
|java+compilationUnit:///src/smallsql/database/NoFromResult.java|(1310,26,<34,0>,<34,26>),
|java+compilationUnit:///src/smallsql/database/NoFromResult.java|(1494,56,<43,1>,<43,57>),
|java+compilationUnit:///src/smallsql/database/NoFromResult.java|(1558,49,<46,1>,<48,2>),
|java+compilationUnit:///src/smallsql/database/NoFromResult.java|(1616,44,<51,1>,<53,2>),
|java+compilationUnit:///src/smallsql/database/NoFromResult.java|(1665,57,<55,1>,<57,2>),
|java+compilationUnit:///src/smallsql/database/NoFromResult.java|(1731,51,<59,1>,<61,2>),
|java+compilationUnit:///src/smallsql/database/NoFromResult.java|(1791,57,<63,1>,<66,2>),
|java+compilationUnit:///src/smallsql/database/NoFromResult.java|(1853,65,<68,1>,<71,2>),
|java+compilationUnit:///src/smallsql/database/NoFromResult.java|(1927,61,<74,1>,<77,2>),
|java+compilationUnit:///src/smallsql/database/NoFromResult.java|(1993,56,<79,1>,<82,2>),
|java+compilationUnit:///src/smallsql/database/NoFromResult.java|(2055,50,<84,1>,<86,2>),
|java+compilationUnit:///src/smallsql/database/NoFromResult.java|(2114,54,<88,1>,<90,2>),
|java+compilationUnit:///src/smallsql/database/NoFromResult.java|(2177,42,<92,1>,<94,2>),
|java+compilationUnit:///src/smallsql/database/NoFromResult.java|(2248,7,<96,24>,<96,31>),
|java+compilationUnit:///src/smallsql/database/NoFromResult.java|(2225,136,<96,1>,<101,2>),
|java+compilationUnit:///src/smallsql/database/NoFromResult.java|(2390,8,<103,24>,<103,32>),
|java+compilationUnit:///src/smallsql/database/NoFromResult.java|(2367,153,<103,1>,<107,2>),
|java+compilationUnit:///src/smallsql/database/NoFromResult.java|(2526,54,<109,1>,<111,2>),
|java+compilationUnit:///src/smallsql/database/NoFromResult.java|(2586,51,<113,1>,<115,2>),
|java+compilationUnit:///src/smallsql/database/NoFromResult.java|(2671,16,<118,27>,<118,43>),
|java+compilationUnit:///src/smallsql/database/NoFromResult.java|(2645,78,<118,1>,<120,2>),
|java+compilationUnit:///src/smallsql/database/NoFromResult.java|(2731,49,<123,1>,<125,2>),
|java+compilationUnit:///src/smallsql/database/NoFromResult.java|(2789,48,<128,1>,<130,2>),
|java+compilationUnit:///src/smallsql/database/NoFromResult.java|(2846,48,<133,1>,<135,2>),
|java+compilationUnit:///src/smallsql/database/NoFromResult.java|(2902,46,<138,1>,<140,2>),
|java+compilationUnit:///src/smallsql/database/NoFromResult.java|(2955,72,<143,1>,<143,73>),
|java+compilationUnit:///src/smallsql/database/NoFromResult.java|(3118,19,<149,43>,<149,62>),
|java+compilationUnit:///src/smallsql/database/NoFromResult.java|(3041,227,<146,4>,<152,5>),
|java+compilationUnit:///src/smallsql/database/NoFromResult.java|(1340,1931,<36,0>,<153,1>),
|java+compilationUnit:///src/smallsql/database/NoFromResult.java|(0,3273,<1,0>,<153,3>),
|java+compilationUnit:///src/smallsql/database/ExpressionFunctionLog.java|(1305,26,<33,0>,<33,26>),
|java+compilationUnit:///src/smallsql/database/ExpressionFunctionLog.java|(1418,51,<38,4>,<38,55>),
|java+compilationUnit:///src/smallsql/database/ExpressionFunctionLog.java|(1477,123,<40,4>,<43,5>),
|java+compilationUnit:///src/smallsql/database/ExpressionFunctionLog.java|(1337,266,<36,0>,<44,1>),
|java+compilationUnit:///src/smallsql/database/ExpressionFunctionLog.java|(0,1603,<1,0>,<44,1>),
|java+compilationUnit:///src/smallsql/junit/TestDBMetaData.java|(1298,23,<33,0>,<33,23>),
|java+compilationUnit:///src/smallsql/junit/TestDBMetaData.java|(1325,18,<35,...
(note that the console outputs cuts off in the middle of the line with ...)
There are a number of ways. Here are the two I use most frequently:
use iprintln or println from the IO module. The former does indentation which is nice for complex outputs. example: import IO; iprintln(calculateCodeDuplication("smallsql0.21_src")); The nice thing about this is that in the terminal values of loc type are hyperlinks
open an editor for the value using the util::ValueUI module (only in Eclipse), for example: import util::ValueUI; text(calculateCodeDuplication("smallsql0.21_src")); This will pop up an editor with the indented output value (nice to search in using CTRL+F, but the loc is not a hyperlink. Would love to have a contribution in that direction :-))
Caveat for the first one is that scrolling up and down in the Eclipse terminal is very slow on Mac's, and not really fast on Windows either.

#line and jump to line

Do any editors honer C #line directives with regards to goto line features?
Context:
I'm working on a code generator and need to jump to a line of the output but the line is specified relative to the the #line directives I'm adding.
I can drop them but then finding the input line is even a worse pain
If the editor is scriptable it should be possible to write a script to do the navigation. There might even be a Vim or Emacs script that already does something similar.
FWIW when I writing a lot of Bison/Flexx I wrote a Zeus Lua macro script that attempted to do something similar (i.e. move from input file to the corresponding line of the output file by search for the #line marker).
For any one that might be interested here is that particular macro script.
#line directives are normally inserted by the precompiler, not into source code, so editors won't usually honor that if the file extension is .c.
However, the normal file extension for post-compiled files is .i or .gch, so you might try using that and see what happens.
I've used the following in a header file occasionally to produce clickable items in
the VC6 and recent VS(2003+) compiler ouptut window.
Basically, this exploits the fact that items output in the compiler output
are essentially being parsed for "PATH(LINENUM): message".
This presumes on the Microsoft compiler's treatment of "pragma remind".
This isn't quite exactly what you asked... but it might be generally helpful
in arriving at something you can get the compiler to emit that some editors might honor.
// The following definitions will allow you to insert
// clickable items in the output stream of the Microsoft compiler.
// The error and warning variants will be reported by the
// IDE as actual warnings and errors... which means you can make
// them occur in the task list.
// In theory, the coding standards could be checked to some extent
// in this way and reminders that show up as warnings or even
// errors inserted...
#define strify0(X) #X
#define strify(X) strify0(X)
#define remind(S) message(__FILE__ "(" strify( __LINE__ ) ") : " S)
// example usage
#pragma remind("warning: fake warning")
#pragma remind("error: fake error")
I haven't tried it in a while but it should still work.
Use sed or a similar tool to translate the #lines to something else not interpreted by the compiler, so you get C error messages on the real line, but have a reference to the original input file nearby.

Resources