From 7191a62a1c934c26107ad6469b1ea1a30d767765 Mon Sep 17 00:00:00 2001 From: Dirk Holtwick Date: Fri, 1 Dec 2023 23:57:58 +0100 Subject: [PATCH] feat: support `markers: '*'` and custom inline title (#1) --- README.md | 16 ++++++++++++++++ src/index.ts | 13 +++++-------- test/fixtures.test.ts | 4 +++- test/input/1.basic.md | 8 ++++++++ test/output/1.basic.html | 5 +++++ 5 files changed, 37 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index db56e84..269ed60 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,22 @@ You might change `github-colors-dark-media.css` to `github-colors-dark-class.css Refer to the [source code](./styles) for more details. +### Customization + +In order to also support [Obsidian callouts syntax](https://help.obsidian.md/Editing+and+formatting/Callouts) it is possible to allow any type of markers with the following setting: + +```js +md.use(MarkdownItGitHubAlerts, { + markers: '*' +}) +``` +Alternative titles are also supported, by appending it to the marker like this: + +```markdown +> [!note] Nota bene +> The custom title will replace the regular title. +``` + ## Sponsors

diff --git a/src/index.ts b/src/index.ts index 7b4d9d9..54b0a3e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,7 +5,7 @@ export interface MarkdownItGitHubAlertsOptions { * List of markers to match. * @default ['TIP', 'NOTE', 'IMPORTANT', 'WARNING', 'CAUTION'] */ - markers?: string[] + markers?: string[] | '*' /** * If markers case sensitively on matching. @@ -54,7 +54,8 @@ const MarkdownItGitHubAlerts: MarkdownIt.PluginWithOptions { const tokens = state.tokens @@ -72,13 +73,9 @@ const MarkdownItGitHubAlerts: MarkdownIt.PluginWithOptions { xhtmlOut: true, }) - md.use(MarkdownItGitHubAlerts) + md.use(MarkdownItGitHubAlerts, { + markers: '*', + }) const rendered = [ md.render(content), diff --git a/test/input/1.basic.md b/test/input/1.basic.md index 679a078..320fe2e 100644 --- a/test/input/1.basic.md +++ b/test/input/1.basic.md @@ -14,3 +14,11 @@ > [!CAUTION] > Negative potential consequences of an action. + +# Custom + +> [!nOtE] My title +> With `markers: '*'` case of chars is not required and titles are supported. + +> [!custom] +> Also any other alert name is allowed. diff --git a/test/output/1.basic.html b/test/output/1.basic.html index 105e633..db7cb3c 100644 --- a/test/output/1.basic.html +++ b/test/output/1.basic.html @@ -9,6 +9,11 @@

Hello

Caution

Negative potential consequences of an action.

+

Custom

+

My title

With markers: '*' case of chars is not required and titles are supported.

+
+

Custom

Also any other alert name is allowed.

+