cristianvasquez / obsidian-prettify

A markdown prettifier for obsidian
GNU General Public License v3.0
130 stars 12 forks source link

List Intend doesn't work As espected #31

Closed empik-foto-it closed 2 years ago

empik-foto-it commented 3 years ago

It doesn't work As espected: (Obsidian 0.10.2 plugin 0.0.6) (Obsidian 0.10.4 plugin 0.0.8)

  1. one space:

image

afer - one space -> ok, but intend has two spaces (two dots)

Expected results:

  1. mixed image

    • first inted has 3- space after a - char , secound has 4 spaces which make an intend and 1 space after a -

Expected results:

  1. tab image

    • first inted has 3- space after a - char , secound has 4 spaces which make an intend and 3 spaces after a - . there is no a TAB char at all

Expected results:

Originally posted by @dariuszkowalski-com in https://github.com/cristianvasquez/obsidian-prettify/issues/24#issuecomment-750026911

cristianvasquez commented 3 years ago

What would be the use case?

dariuszkowalski-com commented 3 years ago
  1. I don't know how each option should work. image

espetialy tab -> where is no Tab at all -> thera are spaces

  1. Tabs are useful because I can use CSS Snippet which will help me to show level of intend in lists image

  2. For me this option could be synchronized or repleaced by reading the Obsidian parameters: image

When I set Use tabs it means that I prefer to have tabs then `spaces'

cristianvasquez commented 3 years ago

Definitely open to a Pull Request since I'm not sure when I'd be able to get to this.

jjspace commented 3 years ago

Instead of creating a new issue I'll tag onto this one. To me the List Indent setting should only affect what's before the bullet character. It seems to be appropriately following what I have set in Obsidian regarding point 3 of @dariuszkowalski-com's comment above regarding inserting spaces instead of tabs when I have List Indent to tabs. However, the problem I'm running into is that it puts extra spaces after the bullet character. Regardless which option I have set for List Indent every line should always be [indent characters] [bullet] [ONE space] TEXT

ivan-lednev commented 3 years ago

I might get to fixing this, but for now I don't see any way of doing this except copying & modifying the list-item handler from here, the way @cristianvasquez did it before this commit

Not sure if it's worth doing it this way. Any comments & ideas are welcome.

rodrigo-rufino commented 3 years ago

Any plans to fix this one? 👀

tuan3w commented 3 years ago

Hi all, I find this workaround solution. Just update runPrettifier function in main.ts

 runPrettifier() {
    const view = this.app.workspace.activeLeaf.view;
    if (view instanceof MarkdownView) {
      // Do work here
      const editor = view.sourceMode.cmEditor;

      // Remember the cursor
      const cursor = editor.getCursor();

      editor.execCommand("selectAll");
      let text = editor.getSelection();

      prettifier(text, this.settings, { today: moment(), tags: [] })
        .then((data) => {
          let output = String(data || '');
          // modify the output generated by remark
          // support image link. ![[imagefile]]
          //@ts-ignore
          output = output.replaceAll('!\\[\\[', '![[');
         // fix indentation issue
          output = output.replace(/- {2,}/g, '- ');
          //@ts-ignore
          output = output.replaceAll('    ', '\t');

          try {
            // Calculate difference of lines and provide feedback
            const n_before = String(data).split(/\r\n|\r|\n/).length;
            const n_after = String(text).split(/\r\n|\r|\n/).length;
            const lines_changed = n_before - n_after;
            if (lines_changed != 0) {
              if (lines_changed > 0) {
                new Notice("Prettifier: added " + lines_changed + " lines.");
              } else {
                new Notice("Prettifier: removed " + lines_changed + " lines.");
              }
            }
            // Update the cursor
            if (cursor.line) {
              cursor.line = cursor.line + lines_changed;
            }
          } catch (err) {
            console.error(err);            
          }

          editor.replaceSelection(output, "start");
          editor.setCursor(cursor);
        }).catch((err) => {
          console.error(err);
          if (err.message) {
            new Notice(err.message);
          }
        });
    }
  }
rodrigo-rufino commented 3 years ago

@tuan3w Ohhh nice! What do you think of opening a Pull Request with this code?

rodrigo-rufino commented 3 years ago

@cristianvasquez I noticed that the code @tuan3w code was removed in the 0.1.0 release, breaking the indentation again. Do you have any plans to implement this fix again?

EEE8D commented 3 years ago

Please fix this again

cristianvasquez commented 2 years ago

I updated the plugin to accept one space or a tab :)