generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add code syntax highlighting and copy code (#520)
- Loading branch information
1 parent
d8acc24
commit 0191f66
Showing
6 changed files
with
86 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# .husky/pre-commit | ||
prettier $(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g') --write --ignore-unknown | ||
git update-index --again | ||
|
||
# Add linting | ||
npm run lint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,23 @@ | ||
import { FC, memo } from 'react'; | ||
import ReactMarkdown, { Options } from 'react-markdown'; | ||
import React, { FC, memo } from "react"; | ||
import ReactMarkdown, { Options } from "react-markdown"; | ||
import CodeBlock from "./CodeBlock"; // Adjust the import path as necessary | ||
|
||
const MemoizedReactMarkdown: FC<Options> = memo((props) => ( | ||
<ReactMarkdown | ||
{...props} | ||
components={{ | ||
code({ node, inline, className, children, ...props }) { | ||
const match = /language-(\w+)/.exec(className || ""); | ||
return !inline && match ? ( | ||
<CodeBlock language={match[1]} value={String(children).replace(/\n$/, "")} /> | ||
) : ( | ||
<code className={className} {...props}> | ||
{children} | ||
</code> | ||
); | ||
}, | ||
}} | ||
/> | ||
)); | ||
|
||
const MemoizedReactMarkdown: FC<Options> = memo(ReactMarkdown); | ||
export default MemoizedReactMarkdown; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters