CSS only for .txt text files? Exclude .txt files from styling?

I’m wondering if there’s a way to:

  • either exclude .txt files from being styled at all
  • or include a CSS snippet that would only target certain elements if the file has a .txt file extension.

In particular, if there is a solution that can do either of things but requires a plugin, it would be important that the plugin can also be used on mobile.

Why I want to do this:

I have started using some completely plain-text (e.g. .txt) files in my vault, amongst my .md files. And I don’t want to style those files. For example, I am using -- in a plain text file to demarcate a section break. However, Obsidian recognizes this as an indication that the text on the prior line is a header, and increases the text size of that text accordingly, per the CSS file.

But for my .txt file, I don’t want this to occur. I don’t want any CSS styling to occur at all for my .txt files.

Is this possible?

1 Like

How are you viewing those files in Obsidian? Mine open in an external app.

Good question! Had to think about that for a sec. I’m using the plugin “txt as md”.

The reason I want to be able to do this is because I’m using Obsidian on mobile as my main text file reader and I’m syncing files between mobile and desktop. I would care less if that wasn’t the case.

I think the “Plaintext for Obsidian” plugin does what you want.

The “text as md” plugin is intended for Markdown files that have .txt extensions.

I wan’t questioning your desire for plain text — I have a bunch of text files myself and I’d rather edit them in Obsidian. Your post finally motivated me to do something about it, so thanks! :slight_smile:

Really? That was never my impression and I’ve been using it since it was written.
Allows files to be edited and seen. Doesn’t admit those files to the specific Obsidian ‘database’ functions which only parse .md files. So not included in tag pane, Outline pane, Graph, search etc. But all appearance related parsing (and sometimes folding) does occur. I’m sure that it would be possible for an add-on plugin to remove the CSS parsing only; or maybe a CSS snippet doing the same.

Obsidian has no way of knowing whether a file is markdown or not, and only recognises .md because of the extension.
I don’t know the new plugin well at all, having no need for it, but it does seem to do what the OP needs which is to allow an edit mode of these extensions with no further parsing of CSS.

The short summary on the plugin’s page is “Edit txt files in Obsidian.md as if they were markdown” and the developer says “The way this plugin specifically is written, … it will interpret them as markdown files” (https://github.com/deathau/txt-as-md-obsidian/issues/2#issuecomment-875998634). I read that as saying that it’s meant to work around the restriction you mention of Obsidian using the .md extension to recognize Markdown (other apps I’ve used assume or can be told to assume that .txt files contain Markdown).

The files not appearing in search, etc. is a bug: https://github.com/deathau/txt-as-md-obsidian/issues/1

Not a bug. A restriction imposed by Obsidian’s design. deathau said that he’d taken functionality as far as it could be done within the restrictions.

No. That’s about Obsidian nomenclature. It is to get around the restriction but without an expectation that the files will be markdown underneath. Some of the discussion was about markdown files using extensions other than md., but most was around being able to work with any plaintext file which most markdown editors can. Many users had plaintext files that they wanted to work with in Obsidian but didn’t want to convert because they needed compatibility with other programs. Of course, I can’t guarantee that was precisely what was in his mind, but that was the discussion. And he only enabled .txt rather than any of the other requested markdown forms such azs .rmd or .markdown.

Not that it matters, it enables editing of .txt files whether they be markdown in disguise, asciidoc, opml or bereft of anything other than pure text. So long as main.js is edited to include the extension of course.

Ah, thanks, this is useful info! This plugin would be perfect but unfortunately it won’t work with my Android phone (nor I assume with any mobile device?).

I have opened an issue on the plugin’s GitHub; thank you for surfacing this!

Confirmed it doesn’t work on iOS, either — le sigh. Sorry, I was on desktop when I checked it.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.