1.0.5 • Published 12 days ago

obsidian-callouts-markdown v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
12 days ago

obsidian-callouts-markdown

en ko

Try the library at playground site 🚀 2024-03-039 39 59-ezgif com-video-to-gif-converter

This library is for parsing Obsidian callout syntax in MDX. Transform your markdown syntax into callouts just like in Obsidian!

What is this library?

I write blog posts using Obsidian, and analyze markdown syntax using @mdx-js/react to operate my personal blog with Gatsby. Writing markdown posts with Obsidian allows you to post conveniently as if you were using services like velog or tistory. However, since Obsidian's callout syntax is not standard markdown syntax, callouts written in Obsidian just get parsed as blockquotes in the Gatsby blog. To alleviate this inconvenience, I created a library to help use the same callout syntax as Obsidian in Markdown.

Quick Start

  1. Install the obsidian-callouts-markdown package.
npm install obsidian-callouts-markdown
yarn add obsidian-callouts-markdown
  1. In the MDXProvider's components setting, map blockquote to ObsidianCallout.

    It can be used in the same way in react-markdown. However, an additional rehype-raw plug-in is required to recognize the html tag inside the markdown.

import Post from '@/tests/posts.mdx';
import {MDXProvider} from '@mdx-js/react';
import {ObsidianCallout} from '@/package';

function App() {
  return (
    <MDXProvider
      components={{
        blockquote: ObsidianCallout,
      }}>
      <Post />
    </MDXProvider>
  );
}
  1. You can now use callouts in markdown with the same syntax as in Obsidian. result

Configuration

Types of Callouts

callout list

Types of Callout
normal ,note, abstract, summary, tldr, info, todo, tip, hint, important, success, check, done, question, help, faq, warning, caution, attention, danger, error, bug, example, quote, cite, normal

Supports all types of callouts that can be used in Obsidian. If you have not created a callout type, it is recognized as a normal type.

Customizing Callout Options

  const components = {
    blockquote: (props: HTMLAttributes<HTMLElement>) => (
      <ObsidianCallout
        {...props}
        options={{
          note: {
            icon: ErrorIcon,
            backgroundColor: '#fff',
            color: '#000',
          },
        }}
      />
    ),
  };

You can customize the icon, background color, and title text color of the callout using ObsidianCallout's options. The icon type is React.SVGProps<SVGSVGElement>.

Customizing Callout Components

  const components = {
    blockquote: (props: HTMLAttributes<HTMLElement>) => (
      <ObsidianCallout
        {...props}
        components={{
          note: CustomCallout,
        }}
      />
    ),
  };

You can define custom callout components using ObsidianCallout's components. Callout components can receive the following props.

propstyperequiredescription
typestringfalseThe string in the !type part when writing a callout.
titlestringfalseThe title string written next to the type (!type title).
childrenReactNodetrueThe main body of the callout.

|

Additional explanation image for props

callout props

Custom Callout Example

  • code
const CustomCallout: React.FC<CustomCalloutComponentProps> = ({
                                                               type,
                                                               title,
                                                               children,
                                                            }) => {
   return (
           <div className="bg-teal-100 p-4 rounded-md">
              <div className="flex gap-2 text-teal-700 font-semibold mb-4">
                 <p>
                    [{type}] {title}
                 </p>
              </div>
              {children}
           </div>
   );
};
  • result custom callout result

Adding Custom Callout Types

  const components = {
    blockquote: (props: HTMLAttributes<HTMLElement>) => (
      <ObsidianCallout
        {...props}
        components={{
          black: CustomCallout,
        }}
        options={{
           bigError: {
            icon: ErrorIcon,
            backgroundColor: 'red',
            color: 'yellow',
          },
        }}
      />
    ),
  };

When defining components or options, specifying a type key that does not exist adds that type of callout. In the code example above, new callout formats of type black and bigError are added. For callout types, any string except newline characters (\n) can be specified. If you customize the same callout type in both components and options, the settings applied in components will take effect.

Support

If you encounter any issues with the library, feel free to open an issue.

1.0.5

12 days ago

1.0.4

13 days ago

1.0.3

2 months ago

1.0.2

2 months ago

1.0.1

2 months ago

1.0.0

2 months ago