How to mark code in GitHub bug report? - github

When creating a bug report on GitHub, is there any way one can easily mark a block of code as a code? I.e. it would indent the marked block by four spaces. Ideally something similar to {} icon on StackExchange. Is there something like that? Indenting every single row can of copy-pasted code can be pretty annoying.

Three back ticks ``` on the line above and below the code create a "fenced code block" in GitHub.
You can also do syntax highlighting, ex ```ruby
Documentation here:
https://help.github.com/articles/github-flavored-markdown#fenced-code-blocks

Related

Why does VS Code break my Markdown fenced code blocks?

I'm creating a markdown document with some CSharp code blocks. Here's a sample:
Next, it feeds the strings to the regular expression matcher to produce a sequence of matches.
```csharp
let patternMatch = azimuthEncoderRegex.Match(message)
```
In the editor, this seems to be working nicely, like so:
As you can see, the code is formatted as expected and shows up correctly formatted in the preview window (not shown).
Now, when I save my file, the above text instantly changes to this:
If I use search-and-replace to change all the code specifiers back, the same thing happens. This breaks the code formatting!! The entire file is also re-flowed to remove all the line breaks I put in (that may be a clue).
UPDATE: I noticed that all of the reference-style hyperlinks were also removed from the end of the document, causing data loss.
WTF? Why is VS-Code doing this? I've tried disabling the Markdown extensions and the same thing happens. Any ideas, please?
Resolved by a change in settings.json for VS Code:
{
"pandocFormat.command": "pandoc --standalone --atx-headers --wrap=auto --columns=80 -f markdown-auto_identifiers -t markdown-simple_tables-multiline_tables-grid_tables-auto_identifiers-fenced_code_attributes --reference-links"
}
Thanks and credit to monofon (the author of the VS Code extension, based on Pandoc) for steering me to this solution.

Visual Code, Fold Comments

Visual Studio Code 1.24.1
While I was working on something today. It prompted me to do an update which I did (Update was to 1.24.1). I'm not sure if I hit a shortcut accidentally at about this same time or if this was caused by the update.
But I seem to no longer be able to use comments as a fold point.
However again, I'm not sure if I hit a shortcut of some sort, or if this was caused by the patch.
and my googlefu did not help me find an answer for visual studio code. Found many old topics about visual studio (prof not code) and for other editors. but couldn't find a topic specific to VSC.
I liked to use comments as fold points \ section headers.
Example of comments I used to use as fold points
Is this a bug in VSC 1.24.1 or did I hit a shortcut I'm unaware of?
VS Code has a method of marking the start and end of a region that can be folded and expanded easily. And also provide it a name/short description that'll always be visible.
I've tried this on Javascript code and I believe it'll work on any language in VS Code. And you can have anything in between the start and end of region - comments, few lines or code, entire functions.
In the absence of proper code folding, this is a pretty good work around that'll work for all languages on VS Code.
//#region <REGION NAME>
< You can put any type of code in here - some lines of code, functions or single or multi-line comments.
//#endregion
For python, simply omit the // in the demarcation lines, since # is a valid comment indicator:
#region <REGION NAME>
...
# any code goes here, including multiple comment lines
...
#endregion
A kind of hack I found for react is using empty tags for example
<>
{/*
Your commented code
*/}
</>
This allows you to fold the commented code between the empty tags. You can go a step further and add regions as mentioned in the other answer to add some kind of description to it

Code Indentation is Off When Pushing to Github from Atom

I am using Atom as an editor and pushed my code up to Github, but some of the indentation is randomly off. This is super embarrassing. Anyone know the fix?
For example, in Atom, one line looks like:
render() {
if (this.state.error)
return <p>Please enter a valid user.</p>
if (!this.state.userData) return <p>Loading</p>
And on Github, same line looks like:
render() {
if (this.state.error)
return <p>Please enter a valid user.</p>
if (!this.state.userData) return <p>Loading</p>
When I copied and pasted the second snippet of code from github, it pasted properly, the same as the first snippet, but is looking ugly in github. I recently reset my tabs from 4 spaces back to default 2, if that info is any help in resolving this.
Try never using the tab button to do the auto 2-space or 4-space thing, go back through the code, change all tabs to spaces, and try again.
This is a bug commonly found when cross-contaminating Python 2 and Python 3 code with non-matching workspaces, text editors, IDEs, and the like.
It's probably that you need to either use tabs ALL THE TIME or use spaces ALL THE TIME.

how to freely format comments in cc-mode

I'm quite new to cc-mode and I'd like to configure it to allow me to freely format and use tabs in multiline comments. This is important to me because I want to use cog.py in my source file and need to be able to format the python source in the comment correctly. I'd be ok with comments not beeing autoindented at all, however I'd like to keep auto indenting the rest of the source code.
Example:
...
/*
[[[cog
import cog
for x in ['a','b','c']:
>cog.outl(x)
]]]
*/
...
In the line marked with > I'd like to press TAB to indent the line. cc-mode simply does nothing at all if i do so. I could use spaces there (which is inconvenient) but every (semi-)automatic re-indentation of this block would cause the spaces to vanish and therefore the python code to be incorrectly indented (which is what happens if i happen to press tab somewhere on this line after indenting it with spaces).
I tried to start emacs without my .init to be sure this is default behavior and not modified by my configuration so far. I've done google searches and read the documentation of the cc-mode variables / functions I stumbled upon (cc-mode online docs) while searching for a solution (i.e. c-indent-comments-syntactically-p, c-indent-command, c-tab-always-indent,...) but none of these seemed to solve my question.
EDIT1:
Thanks to abo-abo's idea of a "multi-major-mode" setup i've stumbled upon mmm-mode and have set up automatic switching to python mode for a cog section, which fixes most of my problems.
The only remaining problem is reindenting the whole file or a region containing a cog section. Can I somehow tell cc-mode to not change anything in comments while reindenting the file? mmm-mode + that would be a perfect solution for me.
You can use M-i to force a tab indent on the lines that you want, so you can use it to indent your comments.
You can also change your comments to use // instead. Just select your python code snippet, and do M-x comment-region:
// def foo(x):
// print 'hi'
Then the autoindent won't mess up your indentation.

Highlight specific line in markdown

I'm pretty new in markdown, and I wonder if it's possible to highlight a specific line of a block of source code, like explained in this page
http://en.support.wordpress.com/code/posting-source-code/
Thanks in advance for your answers,
Edit :
To be clearer, with the wordpress plugin, you can write something like this :
[code highlight="2,3"]
This line won't be highlighted.
This line will be highlighted.
This line will be highlighted.
This line won't be highlighted.
[/code]
But obviously, this isn't a markdown syntax.
It can be done, but there is no Markdown syntax for it, at least not on the most common flavors. Fortunately, also on the most common flavors you can embed HTML.
My solution:
Example
function main() {
__config_bash
__config_xdg_dirs
}
Code
<pre><code>
function main() {
__config_bash
<strong>__config_xdg_dirs</strong>
}
</code></pre>
On SO, langauge highlighting is possible as explained in Advanced Help but not formatting within code blocks.
This is a code block
Markdown is **not** processed
You might mimic what you want by using quote:
This line won't be highlighted.
This line will be highlighted.
This line will be highlighted.
This line won't be highlighted.
You might also mimic what you want by using two spaces at end of each line:
This line won't be highlighted.
This line will be highlighted.
This line won't be highlighted.
But of course, these are not then rendered in monospaced font nor do you get syntax highlighting.