Pasting source code

discourse

#1

There should be a way for us to paste source code without the other formatting symbols taking over. I wasn’t able to paste a config file because it had comments the other day. Thoughts?


#2

let’s test

# this is a comment
actionban = curl -s -X POST "https://api.cloudflare.com/client/v4/user/firewall/access_rules/rules" \
            -H "X-Auth-Email: <cfuser>" \
            -H "X-Auth-Key: <cftoken>" \
            -H "Content-Type: application/json" \
            --data '{"mode":"block","configuration":{"target":"ip","value":"<ip>"},"notes":"Fail2Ban"}'

#3

It’s not convenient when you have to put a symbol in front of every line. For large config files it can take a long time.


#4

sublimetext editor can automatically do this and work on multiple lines at same time so basically if you have 10 lines, sublimetext editor - select all lines hit CTRL+SHIFT+L and then you can just go to front of all 10 lines and add 4 spaces

or just paste code into editor and highlight it and then hit the </> editor button which does it for you


#5

You can:

a) Paste code and use the “code” button on the formatting bar to auto-format the entire block
b) Wrap a word or sentence in backticks to format just that word - e.g. function getURL(url: string)
c) Wrap your code with three backticks - ` x3 - e.g.

func (api *API) CreateDNSRecord(zoneID string, rr DNSRecord) (*DNSRecordResponse, error) {
	uri := "/zones/" + zoneID + "/dns_records"
	res, err := api.makeRequest("POST", uri, rr)
	if err != nil {
		return nil, errors.Wrap(err, errMakeRequestError)
	}

	var recordResp *DNSRecordResponse
	err = json.Unmarshal(res, &recordResp)
	if err != nil {
		return nil, errors.Wrap(err, errUnmarshalError)
	}

	return recordResp, nil
}