Auto-detect Markdown as language for .txt files?

Dear all,

Can Atom auto-detect and set Markdown as the language for .txt files that contain Markdown markup?



There isn’t a way to do exactly what you’re asking built-in. But you could use this feature to assume that .txt files are Markdown and you could manually change files that aren’t back to plain text:

I think the hard part in what you’re asking is determining whether a block of text is Markdown or not. For example, is this Markdown?

# Some code to do some stuff

a = b*c*d

Or is this Markdown?

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore
magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat
nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim
id est laborum.
1 Like

Thanks for your elaborative post, @leedohm!

I do see the point that it’s potentially impossible to achieve what I had asked.

I will continue to switch manually.



1 Like

If it’s something that you do all the time, it would be child’s play to set it up as a keybinding. You can add the following to your If you’re using @burodepeper’s language-markdown package, then replace source.gfm with

atom.commands.add 'atom-text-editor', 'user:switch-to-markdown', ->
  return unless editor = atom.workspace.getActiveTextEditor()

Then in your keymap, you can add something like this.

  'ctrl-m': 'user:switch-to-markdown'

You can also set up a toolbar with this command as a convenient button.


I had a similar suggestion for @orschiro : )

I already thanked @burodepeper and now I want to thank you personally as well for this great solution. Thank you @DamnedScholar! :slight_smile:


1 Like