Skip to content

Commit

Permalink
Version 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
macrojd committed Feb 24, 2023
1 parent d69c2b7 commit cc2b6b7
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 56 deletions.
20 changes: 8 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,26 @@ After this, your note should include a code block like the examples above. The A

## Summary Configuration

The plugin includes three options for configuration.
The plugin includes the following three options to configure the style of the summary.

- Show Callouts: Shows each block of text inside a callout box (default). If disabled, the blocks are displayed as plain text.
- Show Link: Includes a link at the top to open the note where the paragraph was taken from.
- Remove Tags: Removes the original tags from the text.

There are also two more options to determine how the plugin will process lists. If the options are enabled, the plugin will process each item of a list independently and include in the summary only the items that match the tags. If you want the plugin to process the entire list as a block of text, you can disable this options.

- List Items: Include only the items of a list that contain the tag(s), not the entire list.
- Include Child Items: Include the child items of a list item that contains the tag(s).

## Usage

This plugin does not affect the way Obsidian, links, and tags work. You can still organize your notes the way you always do, but now you can assign tags to paragraphs or blocks of text and then create summaries with those that include a specific list of tags.
This plugin does not affect the way Obsidian, links, and tags work. You can still organize your notes the way you always do, but now you can assign tags to paragraphs, blocks of text, or items on a list, and then create summaries with those that include a specific list of tags.

When structuring your notes, please consider the following:

- The plugin considers a block of text to be all the text between empty lines. If you add an empty line in the middle of a paragraph or a block of text, the plugin will consider that as two different blocks.
- Tags can be specified in any position of the paragraph or block of text, even in a new line at the end, as long as there are no empty lines in between.

## Known Issues

The plugin only recognizes tags with letters and numbers from the Latin alphabet: a to z, A to Z, and 0 to 9.


## Safety

This plugin does not modify the original notes, it doesn't download or upload any information to the web, and doesn't store or retrieve any private information.
Expand All @@ -111,10 +111,6 @@ Use this plugin at your own risk.

## From the Author

I've created this plugin for personal use. I will try to post updates once in a while. If you find a bug, you can contact me from my website:
I created this plugin for personal use. I will try to post updates from time to time. If you find a bug, you can contact me through my website:
[www.jdgauchat.com](https://www.jdgauchat.com/)

If you enjoy this plugin and want to support my work, you can buy me a coffee!

<a href="https://www.buymeacoffee.com/JDGauchat" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>

139 changes: 98 additions & 41 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

import { Console } from 'console';
import { Editor, Plugin, MarkdownRenderer, getAllTags, TFile } from 'obsidian';
import { SummarySettingTab } from "./settings";
import { SummaryModal } from "./summarytags";
Expand All @@ -7,11 +8,15 @@ interface SummarySettings {
includecallout: boolean;
includelink: boolean;
removetags: boolean;
listparagraph: boolean;
includechildren: boolean;
}
const DEFAULT_SETTINGS: Partial<SummarySettings> = {
includecallout: true,
includelink: true,
removetags: false,
listparagraph: true,
includechildren: true,
};
export default class SummaryPlugin extends Plugin {
settings: SummarySettings;
Expand Down Expand Up @@ -54,13 +59,13 @@ export default class SummaryPlugin extends Plugin {
const rows = source.split("\n").filter((row) => row.length > 0);
rows.forEach((line) => {
// Check if the line specifies the tags (OR)
if (line.match(/^\s*tags:[a-zA-Z0-9_\-/# ]+$/g)) {
if (line.match(/^\s*tags:[\p{L}0-9_\-/# ]+$/gu)) {
const content = line.replace(/^\s*tags:/, "").trim();

// Get the list of valid tags and assign them to the tags variable
let list = content.split(/\s+/).map((tag) => tag.trim());
list = list.filter((tag) => {
if (tag.match(/^#[a-zA-Z]+[^#]*$/)) {
if (tag.match(/^#[\p{L}]+[^#]*$/u)) {
return true;
} else {
return false;
Expand All @@ -69,13 +74,13 @@ export default class SummaryPlugin extends Plugin {
tags = list;
}
// Check if the line specifies the tags to include (AND)
if (line.match(/^\s*include:[a-zA-Z0-9_\-/# ]+$/g)) {
if (line.match(/^\s*include:[\p{L}0-9_\-/# ]+$/gu)) {
const content = line.replace(/^\s*include:/, "").trim();

// Get the list of valid tags and assign them to the include variable
let list = content.split(/\s+/).map((tag) => tag.trim());
list = list.filter((tag) => {
if (tag.match(/^#[a-zA-Z]+[^#]*$/)) {
if (tag.match(/^#[\p{L}]+[^#]*$/u)) {
return true;
} else {
return false;
Expand All @@ -84,13 +89,13 @@ export default class SummaryPlugin extends Plugin {
include = list;
}
// Check if the line specifies the tags to exclude (NOT)
if (line.match(/^\s*exclude:[a-zA-Z0-9_\-/# ]+$/g)) {
if (line.match(/^\s*exclude:[\p{L}0-9_\-/# ]+$/gu)) {
const content = line.replace(/^\s*exclude:/, "").trim();

// Get the list of valid tags and assign them to the exclude variable
let list = content.split(/\s+/).map((tag) => tag.trim());
list = list.filter((tag) => {
if (tag.match(/^#[a-zA-Z]+[^#]*$/)) {
if (tag.match(/^#[\p{L}]+[^#]*$/u)) {
return true;
} else {
return false;
Expand Down Expand Up @@ -159,51 +164,103 @@ export default class SummaryPlugin extends Plugin {
const fileName = item[0].name.replace(/.md$/g, "");
const filePath = item[0].path;

// Get process each block of text
const block = item[1].split(/\n\s*\n/).filter((row) => row.trim().length > 0);
block.forEach((paragraph) => {
// Check if the paragraph is valid
// Get paragraphs
let listParagraphs: string[] = Array();
const blocks = item[1].split(/\n\s*\n/).filter((row) => row.trim().length > 0);

// Get list items
blocks.forEach((paragraph) => {
// Check if the paragraph is another plugin
let valid = false;
const listTags = paragraph.match(/#[a-zA-Z0-9_\-/#]+/g);
let listTags = paragraph.match(/#[\p{L}0-9_\-/#]+/gu);

if (listTags != null && listTags.length > 0) {
// Do not process plugins
if (!paragraph.contains("```")) {
valid = this.isValidText(listTags, tags, include, exclude);
}
}

// If valid, include the paragraph in the summary
if (valid) {
// Restore newline at the end
paragraph += "\n";

// Remove tags from blocks
if (this.settings.removetags) {
paragraph = paragraph.replace(/#[a-zA-Z0-9_\-/#]+/g, "");
}

// Add link to original note
if (this.settings.includelink) {
paragraph = "**Source:** [[" + filePath + "|" + fileName + "]]\n" + paragraph;
}

// Insert the text in a callout
if (this.settings.includecallout) {
// Insert the text in a callout box
let callout = "> [!" + fileName + "]\n";
const rows = paragraph.split("\n");
rows.forEach((row) => {
callout += "> " + row + "\n";
});
paragraph = callout + "\n\n";
if (!this.settings.listparagraph) {
// Add all paragraphs
listParagraphs.push(paragraph);
} else {
// No Callout
paragraph += "\n\n";
}
// Add paragraphs and the items of a list
let listText = "";

paragraph.split('\n').forEach((line) => {
let isList = false;
isList = line.search(/(\s*[\-\+\*]){1}|([0-9]\.){1}\s+/) != -1

if (!isList) {
// Add normal paragraphs
listParagraphs.push(line);
listText = "";
} else {
// Get the item's level
let level = 0;
const endIndex = line.search(/[\-\+\*]{1}|([0-9]\.){1}\s+/);
const tabText = line.slice(0, endIndex);
const tabs = tabText.match(/\t/g);
if (tabs) {
level = tabs.length;
}

// Add item
if (level == 0) {
if (listText != "") {
listParagraphs.push(listText);
listText = "";
}
listTags = line.match(/#[\p{L}0-9_\-/#]+/gu);
if (listTags != null && listTags.length > 0) {
if (this.isValidText(listTags, tags, include, exclude)) {
listText = listText.concat(line + "\n");
}
}
} else if (this.settings.includechildren && level > 0 && listText != "") {
listText = listText.concat(line + "\n");
}
}
});
if (listText != "") {
listParagraphs.push(listText);
listText = "";
}
}
}
})

// Process each block of text
listParagraphs.forEach((paragraph) => {
// Restore newline at the end
paragraph += "\n";

// Remove tags from blocks
if (this.settings.removetags) {
paragraph = paragraph.replace(/#[\p{L}0-9_\-/#]+/gu, "");
}

// Add to Summary
summary += paragraph;
// Add link to original note
if (this.settings.includelink) {
paragraph = "**Source:** [[" + filePath + "|" + fileName + "]]\n" + paragraph;
}

// Insert the text in a callout
if (this.settings.includecallout) {
// Insert the text in a callout box
let callout = "> [!" + fileName + "]\n";
const rows = paragraph.split("\n");
rows.forEach((row) => {
callout += "> " + row + "\n";
});
paragraph = callout + "\n\n";
} else {
// No Callout
paragraph += "\n\n";
}

// Add to Summary
summary += paragraph;
});
});

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "tag-summary-plugin",
"name": "Tag Summary",
"version": "1.2.0",
"version": "2.0.0",
"minAppVersion": "0.12.0",
"description": "This plugin creates summaries with paragraphs or blocks of text that share the same tag(s).",
"author": "J.D Gauchat",
Expand Down
26 changes: 25 additions & 1 deletion settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class SummarySettingTab extends PluginSettingTab {

new Setting(containerEl)
.setName("Show Callouts")
.setDesc("Show the text in callout blocks")
.setDesc("Show the text inside callout blocks")
.addToggle((toggle) =>
toggle
.setValue(this.plugin.settings.includecallout)
Expand Down Expand Up @@ -47,5 +47,29 @@ export class SummarySettingTab extends PluginSettingTab {
await this.plugin.saveSettings();
})
);

new Setting(containerEl)
.setName("List Items")
.setDesc("Include only the items of a list that contain the tag, not the entire list.")
.addToggle((toggle) =>
toggle
.setValue(this.plugin.settings.listparagraph)
.onChange(async (value) => {
this.plugin.settings.listparagraph = value;
await this.plugin.saveSettings();
})
);
new Setting(containerEl)
.setName("Include Child Items")
.setDesc("Include the child items of a list item that contains the tag.")
.addToggle((toggle) =>
toggle
.setValue(this.plugin.settings.includechildren)
.onChange(async (value) => {
this.plugin.settings.includechildren = value;
await this.plugin.saveSettings();
})
);
}
}

3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"1.0.0": "0.9.7",
"1.0.1": "0.12.0",
"1.1.0": "0.12.0",
"1.2.0": "0.12.0"
"1.2.0": "0.12.0",
"2.0.0": "0.12.0"
}

0 comments on commit cc2b6b7

Please sign in to comment.