From 54f12cfa7e401e4783a602db4d8d2a681b981a3e Mon Sep 17 00:00:00 2001 From: martinkorelic Date: Wed, 14 Apr 2021 13:03:11 +0200 Subject: [PATCH] Minor fixes v0.3.1 --- README.md | 10 +++++++--- package-lock.json | 2 +- package.json | 2 +- src/cards.js | 23 +++++++---------------- src/manifest.json | 2 +- 5 files changed, 17 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index a588538..dfa7ef1 100644 --- a/README.md +++ b/README.md @@ -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... @@ -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 @@ -44,6 +46,7 @@ hero.toString; // => function() {...} hero.hasOwnProperty('toString'); // => false ~~~ * * * +.... ]: ``` @@ -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 { @@ -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 \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 3ecbdaf..a29d239 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "joplin-plugin-spoiler-cards", - "version": "0.2.0", + "version": "0.3.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 0a52b90..9b0c995 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/cards.js b/src/cards.js index c33027c..e83d68c 100644 --- a/src/cards.js +++ b/src/cards.js @@ -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(/(?.+)\n:\[(?<body>(?:.|\n)*?)\]:/i); @@ -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; @@ -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++; @@ -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 /* @@ -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' ]]; diff --git a/src/manifest.json b/src/manifest.json index 5e97be0..7038fe6 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -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č",