Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE]: Can add a plain text view? #73

Closed
2 tasks done
ZSkycat opened this issue Sep 15, 2024 · 17 comments · Fixed by #74
Closed
2 tasks done

[FEATURE]: Can add a plain text view? #73

ZSkycat opened this issue Sep 15, 2024 · 17 comments · Fixed by #74

Comments

@ZSkycat
Copy link

ZSkycat commented Sep 15, 2024

Contact details

No response

What the essence of your feature request

Plain text will be rendered as markdown in reading view.
I want it to be displayed as plain text.

In txt file:

Steam\userdata\*\*\remote
#Key

In reading view:

Steam\userdata**\remote
#Key (>> It becomes a nasty tag)

On what OS you want to maintain your request.

Windows

Code of conduct

  • I agree to follow this project's code of conduct

Issue policy

  • I agree to follow this project's issue policy
@Falcion
Copy link
Owner

Falcion commented Sep 15, 2024

Thanks for opening the issue!

This problem occurs because the extension system (which the plugin works on) reads the .TXT file into the .MD text renderer.

There is currently no solution for this issue, so I plan to integrate a full-fledged syntax highlighting system and a "code editor" based on "Monaco Editor" technology, since CM (Codemirrors) has long ceased to support the functionality of its own renderer.

In the near future, I plan to start developing this integration, the progress can be checked in the branch:
https://github.com/Falcion/UNITADE.md/tree/feature/syntax-highlighting

@pemre
Copy link

pemre commented Oct 24, 2024

Rendering "txt", "yml", "csv" and all file types as plain text in Obsidian, using UNITADE

I use a trick to render "txt", "yaml" (yml) and "csv" files as plain text.

Step 1

I installed UNITADE as usual, then defined txt, yml and csv as extensions:

image

At this point comments in yml files are rendered as H1/2/3 headers which we want to prevent...

Step 2

Then I created a CSS snippet file, put it under "snippets" folder, and enabled it in Appearance settings:

image

Here is snippet.css for "yml" extension, you can extend it to any other extension you want with copy/pasting the whole rule and replacing "yml" with your extension. If you know a bit CSS, you can reuse the CSS selectors and make it efficient too:

/* Note: This trick will not work when you have split view */

/* ============================ YML ============================ */

/* IF left menu (mod-left-split) has an active file with "yml" extension */
.mod-left-split:has( .nav-file-title.is-active[data-path$="yml"] )

/* THEN its sibling (mod-root) will have overriden CSS rules */
~ .mod-root .workspace-leaf-content .cm-content * {
    color: var(--code-normal);
    font-size: var(--font-text-size);
    font-family: var(--font-monospace);
    font-weight: normal;
}

/* IF left menu (mod-left-split) has an active file with "yml" extension */
.mod-left-split:has( .nav-file-title.is-active[data-path$="yml"] )

/* THEN its sibling (mod-root) will have overriden CSS rules */
~ .mod-root .workspace-leaf-content .cm-header {
    color: var(--text-accent);
}

End result

This is the result:

image

Notes:

  1. This trick will not work when you have split view. I didn't spend much time to make it work to be honest. While working on yml files I don't really need split view. If anyone finds a CSS way to improve it, you're welcome to share 🤗.
  2. I didn't test it much, so you may see weird behaviour. I override (cosmetically of course, CSS doesn't change the actual content) almost everything under content section. Use at your own risk.
  3. I use source mode when I edit yml files. So rendering in classic mode still hides "#" hashtags; I can't handle it with pure CSS (at least didn't check devTools, probably not possible).

@pemre
Copy link

pemre commented Oct 24, 2024

@ZSkycat for preventing #tags becoming a rounded chip, you can add:

/* IF left menu (mod-left-split) has an active file with "txt" extension */
.mod-left-split:has( .nav-file-title.is-active[data-path$="txt"] )

/* THEN its sibling (mod-root) will have overriden CSS rules */
~ .mod-root .workspace-leaf-content .cm-hashtag {
    padding: 0;
    background: none;
}

@Falcion
Copy link
Owner

Falcion commented Oct 25, 2024

Rendering "txt", "yml", "csv" and all file types as plain text in Obsidian, using UNITADE

I use a trick to render "txt", "yaml" (yml) and "csv" files as plain text.

Step 1

I installed UNITADE as usual, then defined txt, yml and csv as extensions:
...

Didn't expect to see such a unique use of my plugin, thanks for the help, @pemre!

The plugin once attempted to implement a custom renderer using Codemirrors and CSS styles, but was unsuccessful.

@ZSkycat, purely technically, the dev version of the plugin already has the ability to work with the source code, but it requires polishing and may be "broken" on other devices.

Thanks for waiting for the release.

@Falcion
Copy link
Owner

Falcion commented Nov 3, 2024

@pemre
Copy link

pemre commented Nov 3, 2024

Thanks for the update! JFYI, we can't update it. Update button gives "Failedd to install" error. I uninstalled, restarted app and tried to install; still having the same error. Now I lost the previous version too 😅 :/

@Falcion
Copy link
Owner

Falcion commented Nov 3, 2024

Thanks for the update! JFYI, we can't update it. Update button gives "Failedd to install" error. I uninstalled, restarted app and tried to install; still having the same error. Now I lost the previous version too 😅 :/

The mistake was that I made a release using standard normalized semantics (starting at v*), OBSIDIAN does not accept this.

The problem is fixed, please try again.

@Falcion Falcion pinned this issue Nov 3, 2024
@pemre
Copy link

pemre commented Nov 3, 2024

Thanks. I just installed. I observed some confusing issues:

image

But actually only ">" greater/closing-tag works. 😕

E.g. "txt> csv> yml"

Also: Any attempt of using comma or semicolon triggers not only one but tens of notifications in the system tray.

And I couldn't make it use any code editor yet. I still see bare markdown editor's view.

@Falcion
Copy link
Owner

Falcion commented Nov 3, 2024

In README, it says "comma" is needed: [...] “extensions” and type an array of extensions, separated by comma; [...]. Source: https://github.com/Falcion/UNITADE.md/tree/main?tab=readme-ov-file#usage

Forgot about README, will fix.

The plugin settings page says "semicolon" is needed:

Also would edit, my bad.

Also: Any attempt of using comma or semicolon triggers not only one but tens of notifications in the system tray.

This is a common problem, it is discussed in the issue #70, it occurs because OBSIDIAN doesn't allow me to read "input" of user as final and I have to "castrate" the input in such formations.

You can read wiki's page about silencing errors, it's functionality is down below in the settings page:
https://github.com/Falcion/UNITADE.md/wiki/Error-handling

And I couldn't make it use any code editor yet. I still see bare markdown editor's view.
Did you enable code editor module in the settings? If you so, did you tried to "insert" extensions in it's input: restart may help.

@Falcion
Copy link
Owner

Falcion commented Nov 3, 2024

Because I installed the plugin, set up, for example, this config (data.json):

{
  "markdown_overcharge": false,
  "extensions": "txt",
  "is_case_insensitive": false,
  "is_onload": false,
  "is_onload_unsafe": false,
  "forced_extensions": "",
  "is_ignore": false,
  "ignore_extensions": "",
  "ignore_masks": "",
  "is_grouped": false,
  "grouped_extensions": "",
  "mobile_settings": {
    "enable": false,
    "extensions": "txt",
    "stable": true
  },
  "barefiling": true,
  "stable": true,
  "errors": {
    "": "Error from UNITADE plugin: Error: Attempting to register an existing view type \"\""
  },
  "debug_mode": true,
  "silence_errors": true,
  "manifest_version": "",
  "compatibility_module": true,
  "code_editor_settings": {
    "enabled": true,
    "use_default_extensions": false,
    "extensions": "dart> txt> yaml",
    "folding": true,
    "line_numbers": true,
    "word_wrapping": false,
    "minimapping": true,
    "validation_semantic": true,
    "validation_syntax": true,
    "theme": "AUTO",
    "font_size": 14,
    "font_family": "'Cascadia Code', 'Fira Code', Consolas, 'Courier New', monospace",
    "font_ligatures": true
  },
  "SYS_FONTSIZE_MAX": 32,
  "SYS_FONTSIZE_MIN": 5
}

And everything works:
image

@pemre
Copy link

pemre commented Nov 3, 2024

It worked with your config, thanks! "use_default_extensions" was true... Making it false did the trick, I think... I also changed debug mode and silence errors, but I don't think that they are responsible.

@Falcion
Copy link
Owner

Falcion commented Nov 3, 2024

It worked with your config, thanks! "use_default_extensions" was true... Making it false did the trick, I think... I also changed debug mode and silence errors, but I don't think that they are responsible.

Last two are just for convenience, first one: it's an interesting problem related to OBSIDIAN and my settings, I'll also add it on my radar.

Thanks for "early-testing" my plugin!


From this dialog, we got:

  1. Fix README and settings tab about semantics of "splitting" extensions;
  2. Add comment about "error-spamming" in the extensions block, relate to "error silencing";
  3. Fix code editor's "extensions async" display mode;
  4. Add comment about how "use default extensions" work in short terms (because there are wiki for more advanced information):
  5. Add "warning" about case-insensitive, if user is too reckless it can forever crash vault until disabling this feature through JSON config of plugin.

Falcion added a commit that referenced this issue Nov 5, 2024
Information about semantics of plugin was stale (using comma as separated and other): updated this, also add link to the wikipedia.

Part of fixes from #73
Falcion added a commit that referenced this issue Nov 5, 2024
…s appear null

This things occurs because different language may not contain specified elements, for example, translation for code editor font size and etc.

Part of fixes from #73
Falcion added a commit that referenced this issue Nov 5, 2024
…d in settings tab

Error was defined by case, when "use default extensions" was enabled, but extensions input was NOT hidden.

Part of fixes from #73
Falcion added a commit that referenced this issue Nov 5, 2024
@Lexvox
Copy link

Lexvox commented Nov 23, 2024

Sorry for being a dunce but I have yet to understand what I have to do to view a .txt file without any formatting applied to it.

@Falcion
Copy link
Owner

Falcion commented Nov 23, 2024

@Lexvox,

Use "code editor module" from "v3.*" version of plugin, you can either turn on "use default extensions" (it would use extensions from "extensions" setting block) or type custom extensions in it.

It would open files as code files (like in any code editor), more advanced instruction:

  1. Download the latest version of the plugin;
  2. Write in "extensions" setting (at the start of settings page):
txt
  1. Go to "code editor module," and turn it on if it is disabled, find "use default extensions" toggle and turn it on also;
  2. Now plugin should treat any files with "txt" (and only "txt") extensions as code in your OBSIDIAN's vault.

More about extensions, code editor and etc. read at the wiki:
https://github.com/Falcion/UNITADE.md/wiki

@Lexvox
Copy link

Lexvox commented Nov 24, 2024

@Falcion iirc that was the default setup when I downloaded the extension, so there wasn't anything I could change.
'Code editor module' and 'use default extensions' was already enabled. Also I had already set txt in the 'extensions' setting, yet still there is some highlighting going on.
I think for context (bc maybe what I want is out of scope anyway) I have a file with a bunch of ascii art and rn the tab and () get highlighted and I want to get rid of that.

@Falcion
Copy link
Owner

Falcion commented Nov 24, 2024

@Falcion iirc that was the default setup when I downloaded the extension, so there wasn't anything I could change. 'Code editor module' and 'use default extensions' was already enabled. Also I had already set txt in the 'extensions' setting, yet still there is some highlighting going on. I think for context (bc maybe what I want is out of scope anyway) I have a file with a bunch of ascii art and rn the tab and () get highlighted and I want to get rid of that.

Now I understand what you are talking about, unfortunately I can't do anything about this problem: it is "installed" on the editor side of the Monaco Editor technology (the same one that VS Code uses, in which a similar problem occurs sometimes, I checked it myself).

Maybe in theory there really is a solution, but I don't know about it, unfortunately: you can try the solution proposed in this discussion by installing CSS styles (via snippet) and rendering the file via just OBSIDIAN.

image
image

Note

I know this is not the best solution, but you can use "PITCH-LIGHT" theme, it doesn't show any validations errors like this.

image

@Lexvox
Copy link

Lexvox commented Nov 24, 2024

Now I understand what you are talking about

Yeah I should've been clearer about what I was trying 2 do.
Thank you very much for the extensive reply, I highly appreciate it!
Gonna look into adding the css 2 my snippets then.
cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants