Skip to content

Commit

Permalink
fix(article-md): Instantiate once markdownit
Browse files Browse the repository at this point in the history
  • Loading branch information
WaDadidou committed Dec 16, 2024
1 parent 28d91d1 commit 015b7de
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import { useMaxResolution } from "@/hooks/useMaxResolution";
import { Toolbar } from "@/screens/FeedNewArticle/components/ArticleContentEditor/Toolbar/Toolbar";
import {
ContentMode,
initializeArticleMd,
markdownTagStyles,
} from "@/screens/FeedNewArticle/components/ArticleContentEditor/utils";
articleMd as md,
} from "@/utils/feed/markdown";
import { ARTICLE_MAX_WIDTH } from "@/utils/social-feed";
import { neutral00, neutralA3, neutralFF } from "@/utils/style/colors";
import { layout, RESPONSIVE_BREAKPOINT_S } from "@/utils/style/layout";
Expand Down Expand Up @@ -50,7 +50,6 @@ export const ArticleContentEditor: FC<Props> = ({ width }) => {
const message = watch("message");

// ========== Markdown
const md = initializeArticleMd();
const html = md.render(message);

// ========== JSX
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { View } from "react-native";
import { BrandText } from "@/components/BrandText";
import { CustomPressable } from "@/components/buttons/CustomPressable";
import { SpacerRow } from "@/components/spacer";
import { ContentMode } from "@/screens/FeedNewArticle/components/ArticleContentEditor/utils";
import { ContentMode } from "@/utils/feed/markdown";
import { neutral1A } from "@/utils/style/colors";
import { fontSemibold12 } from "@/utils/style/fonts";
import { layout } from "@/utils/style/layout";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ import { useIsMobile } from "@/hooks/useIsMobile";
import { useMaxResolution } from "@/hooks/useMaxResolution";
import { useNSUserInfo } from "@/hooks/useNSUserInfo";
import { parseUserId } from "@/networks";
import {
initializeArticleMd,
markdownTagStyles,
} from "@/screens/FeedNewArticle/components/ArticleContentEditor/utils";
import { markdownTagStyles, articleMd as md } from "@/utils/feed/markdown";
import { zodTryParseJSON } from "@/utils/sanitize";
import {
ARTICLE_MAX_WIDTH,
Expand Down Expand Up @@ -102,7 +99,6 @@ export const FeedPostArticleMarkdownView: FC<{
ZodSocialFeedArticleMetadata,
post.metadata,
);
const md = initializeArticleMd();
const message = articleMetadata?.message;
const html = message ? md.render(message) : null;
const title = articleMetadata?.title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,8 @@ export const markdownTagStyles: MixedStyleRecord = {
},
};

// Used to get the same parameters at Article creation and consultation
export const initializeArticleMd = () => {
return markdownit({
linkify: true,
breaks: true,
}).use(emoji);
};
// The markdownit instance. Used to get the same parameters at Article creation and consultation.
export const articleMd = markdownit({
linkify: true,
breaks: true,
}).use(emoji);

0 comments on commit 015b7de

Please sign in to comment.