Skip to content

Commit

Permalink
5.1.0
Browse files Browse the repository at this point in the history
- Fixes #9 - can now do random blocks by tag
- Can now specify section type to return using `dice: [[Note]]|type` or `dice: #tag|type`
- Can now roll multiple sections of a note
  • Loading branch information
valentine195 committed Jul 19, 2021
1 parent 2738936 commit 9ae06fd
Show file tree
Hide file tree
Showing 12 changed files with 741 additions and 411 deletions.
73 changes: 69 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,77 @@ There is full order-of-operations support, so it can even nested into parenthese

### Random Blocks

The Dice Roller can be given a link to a note, and it will return a random block from the note.
The Dice Roller can be given a link to a note or a tag, and it will return a random block from the note/notes.

This feature is still under development and may not work as expected.

Usage:
`` `dice: [[Note]]` ``
| Example | Result |
| ----------------------------------------- | ----------------------------------------------- |
| `` `dice: [[Note]]` `` | Returns a single random block from `Note` |
| `` `dice: 3d[[Note]]` `` | Returns 3 random blocks from `Note` |

#### Tags

The Dice Roller can also be told to return results from a tag if the [Dataview](https://github.com/blacksmithgu/obsidian-dataview) plugin is installed.

By default, this will return 1 result from _every_ file that has the tag. You can change this behavior in settings, or by using the following optional `+` and `-` parameters as shown below.

If results from multiple files are returned, the result **from that file** can be re-rolled by clicking on the block. Clicking on the container or the dice icon will re-roll **all returned results**.

| Example | Result |
| --------------------- | -------------------------------------------------------------------------------------------------------- |
| `` `dice: #tag` `` | Return a single random block from notes with `#tag`, behavior depends on settings (default to **every**) |
| `` `dice: #tag\|-` `` | Return a single random block from **a single, random note** with `#tag` |
| `` `dice: #tag\|+` `` | Return a single random block from **every note** with `#tag` |

#### Block Types

Obsidian has several "types" of blocks. Currently, the default behavior of the plugin is to filter out **thematicBreak** and **yaml** from the returned results.

To return a specific block type, you may append `|<type>` to the end of any block roller.

Usage:

| Example | Result |
| -------------------------------------------- | ------------------------------------------------------------------------------ |
| `` `dice: [[Note]]\|paragraph` `` | Return `paragraph` blocks |
| `` `dice: #tag\|paragraph,header,yaml` `` | Return `paragraph`, `header`, and `yaml` blocks |
| `` `dice: #tag\|-\|paragraph,header,yaml` `` | Return `paragraph`, `header`, and `yaml` blocks from a **single, random note** |

I do not have any control over what Obsidian consider's each block (for instance, images may be returned as `paragraph`).

I _believe_ that this is a list of block types defined in Obsidian, but use this with a grain of salt.

| Type |
| -------------------- |
| `blockquote` |
| `break` |
| `code` |
| `delete` |
| `emphasis` |
| `footnoteReference` |
| `footnote` |
| `heading` |
| `html` |
| `imageReference` |
| `image` |
| `inlineCode` |
| `linkReference` |
| `link` |
| `listItem` |
| `list` |
| `paragraph` |
| `root` |
| `strong` |
| `table` |
| `text` |
| `thematicBreak` |
| `toml` |
| `yaml` |
| `definition` |
| `footnoteDefinition` |

### Random Tables

The Dice Roller may also be given a link to a table in a note, which it will read and return a random result from the table.
Expand Down Expand Up @@ -57,8 +122,6 @@ To return multiple elements, use:

Once in preview mode, you may <kbd>Ctrl</kbd> - click on the result to open the block reference in a new pane.

**Random tables cannot be used with modifiers. Any modifiers supplied will be ignored.**

#### Multiple Headers

If a table provided to the plugin has multiple headers, the plugin will return the entire row unless you specify the header to use:
Expand Down Expand Up @@ -97,6 +160,8 @@ Use `` `dice: 1dS` `` to roll a Fantasy AGE stunt dice. The result will show the

The parser supports several modifiers. If a die has been modified, it will display _how_ it has been modified in the tooltip.

**Modifiers are only supported on basic number dice.**

If a modifier has a parameter, it will default to 1 if not provided.

| Modifier | Syntax | Description |
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": "obsidian-dice-roller",
"name": "Dice Roller",
"version": "5.0.0",
"version": "5.1.0",
"minAppVersion": "0.12.0",
"description": "Inline dice rolling for Obsidian.md",
"author": "Jeremy Valentine",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-dice-roller",
"version": "5.0.0",
"version": "5.1.0",
"description": "Inline dice rolling for Obsidian.md",
"main": "main.js",
"scripts": {
Expand Down
6 changes: 6 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const TAG_REGEX =
/(?:(\d+)[Dd])?(#[\p{Letter}\p{Emoji_Presentation}\w/-]+)(?:\|([\+-]))?(?:\|([^\+-]+))?/u;
export const TABLE_REGEX =
/(?:(\d+)[Dd])?\[\[([\s\S]+?)#?\^([\s\S]+?)\]\]\|?([\s\S]+)?/;
export const SECTION_REGEX = /(?:(\d+)[Dd])?\[\[([\s\S]+)\]\]\|?([\s\S]+)?/;
export const MATH_REGEX = /[\(\^\+\-\*\/\)]/;
15 changes: 15 additions & 0 deletions src/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,28 @@
font-size: inherit;
margin-left: 0.25em;
}

.dice-roller.has-embed .dice-roller-button {
padding-top: 0.5rem;
}

.dice.tooltip {
max-width: unset !important;
}
.dice-roller.has-embed {
display: flex;
padding-right: 0.25rem;
}

.dice-no-results {
font-style: italic;
text-align: center;
}

.dice-roller.has-embed .internal-embed {
width: 100%;
}

.dice-roller.has-embed .dice-file-name {
font-style: italic;
}
Loading

0 comments on commit 9ae06fd

Please sign in to comment.