Skip to content

Commit

Permalink
feat: configure non-strict line breaks
Browse files Browse the repository at this point in the history
suggested in #9
  • Loading branch information
aviskase committed Nov 17, 2020
1 parent 75c3c31 commit 6550c55
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ Command will create an index note (check path in settings) with the content:
1 [[X]]
```

### Output options

**Strict line breaks** corresponds to the same Editor setting: "off" = one line break, "on" = two line breaks.

| on | off |
| -- | -- |
| 2 [[B]]<br><br>2 [[C]]<br><br>1 [[X]] | 2 [[B]]<br>2 [[C]]<br>1 [[X]] |


## Compatibility
v0.0.1 was developed against Obsidian v0.9.12, but it may work in earlier versions (v0.9.7+).

Expand Down
17 changes: 15 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export default class LinkIndexer extends Plugin {
});
});
const sortedLinks = Object.entries(uniqueLinks).sort((a, b) => b[1].count - a[1].count);
const content = sortedLinks.map((l) => `${l[1].count} ${l[1].link}`).join('\n\n');
const separator = this.settings.strictLineBreaks ? '\n\n' : '\n';
const content = sortedLinks.map((l) => `${l[1].count} ${l[1].link}`).join(separator);
const exist = await this.app.vault.adapter.exists(normalizePath(this.settings.allUsedLinksPath), false);
if (exist) {
const p = this.app.vault.getAbstractFileByPath(normalizePath(this.settings.allUsedLinksPath));
Expand All @@ -59,6 +60,7 @@ export default class LinkIndexer extends Plugin {

class LinkIndexerSettings {
allUsedLinksPath = './all_used_links.md';
strictLineBreaks = true;
}

class LinkIndexerSettingTab extends PluginSettingTab {
Expand All @@ -82,6 +84,17 @@ class LinkIndexerSettingTab extends PluginSettingTab {
await plugin.saveData(plugin.settings);
})
);


new Setting(containerEl)
.setName('Strict line breaks')
.setDesc('Corresponds to the same Editor setting: "off" = one line break, "on" = two line breaks.')
.addToggle((value) =>
value
.setValue(plugin.settings.strictLineBreaks)
.onChange(async (value) => {
plugin.settings.strictLineBreaks = value;
await plugin.saveData(plugin.settings);
})
);
}
}

0 comments on commit 6550c55

Please sign in to comment.