Skip to content

Commit

Permalink
Minor fixes v0.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
martinkorelic committed Apr 14, 2021
1 parent 70847a5 commit 54f12cf
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 22 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
This Joplin plugin allows you to create cards with title and extendable body.

**Note**: Requires Joplin 1.7.0+
**Version**: 0.3.0

**Version**: 0.3.1

![](./docs/cards-plugin-preview.gif)

## Usage

In order to create a card, you need to write in this format:

```
:[
Card name here...
Expand All @@ -18,8 +20,8 @@ Card body text here...
]:
```
Please note, that the empty line above and below card body text is **needed**.

Please note, that the empty line above and below card body text is **needed**.
Card body supports markdown formatting as well.

### Example
Expand All @@ -44,6 +46,7 @@ hero.toString; // => function() {...}
hero.hasOwnProperty('toString'); // => false
~~~
* * *
....
]:
```
Expand All @@ -52,6 +55,7 @@ hero.hasOwnProperty('toString'); // => false

If you would like to style the spoiler cards to your preference, use the following in your `userstyle.css` file:


```css
/* Styling of the card title */
.summary-title {
Expand All @@ -67,6 +71,6 @@ If you would like to style the spoiler cards to your preference, use the followi
## Notes

- I have not thoroughly tested the plugin, so note that **there might be bugs**.
- I might have to change formatting in the future to improve highlighting in text editor, but nothing significant from now on.
- I might have to change formatting in the future to be more convenient, but nothing significant from now on.

> Created on 12th April 2021
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "joplin-plugin-spoiler-cards",
"version": "0.3.0",
"version": "0.3.1",
"description": "Joplin plugin allows you to create cards with title and extendable body.",
"author": "martinkorelic",
"homepage": "https://github.com/martinkorelic/joplin-plugin-spoiler-cards",
Expand Down
23 changes: 7 additions & 16 deletions src/cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ module.exports = {

markdownIt.block.ruler.after('fence', 'spoiler_card', spoiler_card, {alt: ['paragraph', 'reference', 'blockquote', 'list']});

//markdownIt.renderer.rules.spoiler_card = spoiler_card_renderer;
/*
markdownIt.renderer.rules.text = function (tokens, idx, options, env, self) {
const defaultRender = markdownIt.renderer.rules.fence || function(tokens, idx, options, env, self) {
return self.renderToken(tokens, idx, options, env, self);
};
markdownIt.renderer.rules.fence = function (tokens, idx, options, env, self) {
let token = tokens[idx];
// We detect if card block
if (token.tag !== "p") return defaultRender(tokens, idx, options, env, self);
if (token.info !== 'card') return defaultRender(tokens, idx, options, env, self);
// Split the card title and body by :[]:
let card = token.content.match(/(?<title>.+)\n:\[(?<body>(?:.|\n)*?)\]:/i);
Expand Down Expand Up @@ -58,10 +60,7 @@ function spoiler_card(state, start, end, silent) {
var token;
let curLine = start;

let firstLine;
if (pos + 2 > max) {
return false;
}
if (pos + 2 > max) return false;

// Check when it starts with ':['
if (state.src.slice(pos, pos+2) !== ':[') return false;
Expand All @@ -71,9 +70,6 @@ function spoiler_card(state, start, end, silent) {
if (state.src.slice(pos, pos+2) == ']:') return false;
pos += 2;

// Check if line is not empty
firstLine = state.src.slice(pos, max);

if (silent) return true;

curLine++;
Expand All @@ -88,10 +84,7 @@ function spoiler_card(state, start, end, silent) {

curLine++;
// Now there needs to be atleast some content before we render the card
if (state.isEmpty(curLine)) {

return false;
}
if (state.isEmpty(curLine)) return false;

// If the formatting is okay, we create new tokens
/*
Expand All @@ -102,8 +95,6 @@ function spoiler_card(state, start, end, silent) {

state.push('details_open', 'details', 1);

console.log(state);

token = state.push('summary_open', 'summary', 1);
token.attrs = [[ 'class', 'summary-title' ]];

Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 1,
"id": "joplin.plugin.spoiler.cards",
"app_min_version": "1.7",
"version": "0.3.0",
"version": "0.3.1",
"name": "Spoiler cards",
"description": "Create spoiler cards with title and extendable body.",
"author": "Martin Korelič",
Expand Down

0 comments on commit 54f12cf

Please sign in to comment.