gotjoshua / atom-textual-velocity

:memo: Textual Velocity for Atom
MIT License
0 stars 0 forks source link

Enable Markdown in Preview Pane #1

Open gotjoshua opened 7 years ago

gotjoshua commented 7 years ago
gotjoshua commented 7 years ago

@viddo what do you think about giving the option to use a markdown preview package instead of html element?

viddo commented 7 years ago

First, sorry for this late reply. I have been busy these days.

I don't think it's a good idea for several reasons. The primary one is that conceptually this package has nothing to do with that markdown preview package.

Instead, I still think what I suggested in the referenced issue could work though, i.e. To me it sounds like you want to opt-out of the default preview editor this package uses. This way the markdown preview package would/should work out of the box. What I mean with that is something on the lines of:

// in https://github.com/viddo/atom-textual-velocity/blob/17c89d137493240daa091d0b7708f8e77d34712b/lib/side-effects.js#L163
_previewSelectedPath (presenter: PresenterType) {
  …
  .onValue((template: {path?: string, content?: string, searchRegex?: RegExp}) => {
    if (path && !atom.config.get('textual-velocity.usePreview')) {
      atom.workspace.open(path, {
        pending: true // see https://github.com/atom/atom/pull/10178
      })
      return
    }

  … // default preview behavior

This way the default text editor is used and the markdown editor would/should work by its default behavior. Although I'm skeptical about this too, because the default editor is slow, it takes several hundred ms to open. That was the main motivation for having a separate preview in the first place.

An alternative, or in addition to this kind of change, you could also listen to atom.workspace events in your init script and do any customizations there.

gotjoshua commented 7 years ago

@viddo, I totally agree that opening a full editor and markdown renderer would be too slow and not fitting. After your responses I started to look into the way that the markdown preview package is functioning, and I realized that what I would really like to do, is simply add an option to textual-velocity to pass the text of the file through a markdown render function (?somehow?) before displaying it (as quickly as possible in the current simple preview pane). Does this sound more reasonable to you?

viddo commented 7 years ago

… and I realized that what I would really like to do, is simply add an option to textual-velocity to pass the text of the file through a markdown render function (?somehow?) before displaying it (as quickly as possible in the current simple preview pane). Does this sound more reasonable to you?

Not really, with the same argument as before. Furthermore, not all notes are necessarily markdown files. Among my notes that's certainly the case.

I understand what you're aiming for though. I think we should be able to find a better way to achieve what you want. I think the most idiomatic approach would be to utilize the services mechanism Atom provides, see http://flight-manual.atom.io/behind-atom/sections/interacting-with-other-packages-via-services/

Although a bit experimental I already expose a service object (to allow registering new columns, file readers etc.), so would need a way to implement event hooks, something like:

  service.onDidPreview((path, file, preview) => {
    console.log(path) // => ~/notes/some-file.txt
    console.log(file.content) // => foo bar …
    // TODO preview if markdown
  })

  service.onDidClosePreview(…

That way you could extend this package with custom behavior, either as a separate package or from your init script (but would need to figure out how to consume the service from there though, there doesn't seem to a public API for that).

Makes sense?