Preserve Double-Space Line Endings in Snippets


#1

Here’s a video I made documenting this issue


  1. I’ve created a Snippet that creates MultiMarkdown 3-style metadata at the top of new Markdown documents:
'.source.gfm':
	'Post Metadata':
		'prefix': 'ppost'
		'body':
			"""
				Title: $1
				Date: $2
				Link: $3
				Description: $4
				Tags: $5
				Image: $6
			"""
  1. I’d like to include a double-space at the end of each line of metadata, to introduce a line-break (fairly common Markdown usage here)

  2. The problem is that when I save the snippets.cson file, Atom strips away the double-spaces at the end of each line of the body portion of the snippet

  3. The resultant population allows tabbing from field-to-filed, as we would expect, but I have to remember to double-space each line, otherwise each line gets parsed as part of the same paragraph (ruining the MultiMarkdown 3-friendlyness and plain-text niceness).

Any way to force Atom to preserve those spaces?


#2

See the README for the whitespace package:


#3

I can edit config.cson like so:

'.source.coffee':
  whitespace:
    removeTrailingWhitespace: false

… Which would then allow preservation of the whitespace in my snippet (in snippets.cson).

But the problem with this approach is that it will globally remove trailing whitespace from all CoffeeScript files, no?

(Can I target only snippets.cson for whitespace removal?)


#4

Ah … I misunderstood the question. No, there isn’t a way to target a specific file for exclusion from whitespace removal. If I needed to do something like this I would encode the snippet all on one line and use \n for ending the line. It would be ugly, but it should work:

'.source.gfm':
  'Post Metadata':
    'prefix': 'ppost'
    'body': "Title: $1  \nDate: $2  \nLink: $3  \nDescription: $4  \nTags: $5  \nImage: $6  \n"

#5

Ah. Nice suggestion!

I forgot about \n :smiley: