Skip to content

chore(deps): update dependency marked to v15.0.6 #802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,10 @@
"@jsamr/counter-style": "2.0.2",
"@jsamr/react-native-li": "2.3.1",
"html-entities": "2.5.2",
"marked": "5.0.5",
"marked": "15.0.6",
"react-native-table-component": "1.2.2",
"svg-parser": "2.0.4"
"svg-parser": "2.0.4",
"github-slugger": "^2.0.0"
},
"engines": {
"node": ">=18"
Expand Down
11 changes: 8 additions & 3 deletions src/hooks/useMarkdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@ import Parser from "../lib/Parser";
import Renderer from "../lib/Renderer";
import getStyles from "./../theme/styles";
import type { ColorSchemeName } from "react-native";
import type { CustomToken, RendererInterface } from "../lib/types";
import type { RendererInterface } from "../lib/types";

export interface useMarkdownHookOptions {
colorScheme?: ColorSchemeName;
renderer?: RendererInterface;
theme?: UserTheme;
styles?: MarkedStyles;
baseUrl?: string;
tokenizer?: Tokenizer<CustomToken>;
tokenizer?: Tokenizer;
extensions?: {
inline?: Tokenizer[];
block?: Tokenizer[];
};
}

const useMarkdown = (
Expand All @@ -38,7 +42,8 @@ const useMarkdown = (
const elements = useMemo(() => {
const tokens = marked.lexer(value, {
gfm: true,
tokenizer: options?.tokenizer as Tokenizer<never>,
tokenizer: options?.tokenizer as Tokenizer,
extensions: options?.extensions,
});
return parser.parse(tokens);
}, [value, parser, options?.tokenizer]);
Expand Down
2 changes: 2 additions & 0 deletions src/lib/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const Markdown = ({
renderer,
styles,
tokenizer,
extensions,
}: MarkdownProps) => {
const colorScheme = useColorScheme();

Expand All @@ -26,6 +27,7 @@ const Markdown = ({
colorScheme,
styles,
tokenizer,
extensions,
});

const renderItem = useCallback(({ item }: { item: ReactNode }) => {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/Parser.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ReactNode } from "react";
import type { TextStyle, ViewStyle, ImageStyle } from "react-native";
import type { marked } from "marked";
import type { marked, Tokens } from "marked";
import { decode } from "html-entities";
import type { MarkedStyles } from "../theme/types";
import type { RendererInterface, ParserOptions, Token } from "./types";
Expand Down Expand Up @@ -85,7 +85,7 @@ class Parser {
const children = item.tokens.flatMap((cItem) => {
if (cItem.type === "text") {
/* getViewNode since tokens could contain a block like elements (i.e. img) */
const childTokens = (cItem as marked.Tokens.Text).tokens || [];
const childTokens = (cItem as Tokens.Text).tokens || [];
const listChildren =
this.getNormalizedSiblingNodesForBlockAndInlineTokens(
childTokens,
Expand Down Expand Up @@ -273,7 +273,7 @@ class Parser {
if (t.type === "image") {
siblingNodes.push(this._parseToken(t));
} else if (t.type === "link") {
const imageToken = t.tokens[0] as marked.Tokens.Image;
const imageToken = t.tokens[0] as Tokens.Image;
const href = getValidURL(this.baseUrl, t.href);
siblingNodes.push(
this.renderer.linkImage(
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import MarkedList from "@jsamr/react-native-li";
import Disc from "@jsamr/counter-style/presets/disc";
import Decimal from "@jsamr/counter-style/presets/decimal";
import { Slugger } from "marked";
import Slugger from 'github-slugger';
import { Table, Cell, TableWrapper } from "react-native-table-component";
import MDImage from "./../components/MDImage";
import { onLinkPress } from "../utils/handlers";
Expand Down
26 changes: 2 additions & 24 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
ImageStyle,
} from "react-native";
import type { MarkedStyles, UserTheme } from "./../theme/types";
import type { Tokenizer as MarkedTokenizer, marked } from "marked";
import type { Tokenizer as MarkedTokenizer, marked, MarkedToken } from "marked";

export interface ParserOptions {
styles?: MarkedStyles;
Expand Down Expand Up @@ -92,26 +92,4 @@ export interface CustomToken {
args?: Record<string, unknown>;
}

export type Token =
| marked.Tokens.Space
| marked.Tokens.Code
| marked.Tokens.Heading
| marked.Tokens.Table
| marked.Tokens.Hr
| marked.Tokens.Blockquote
| marked.Tokens.List
| marked.Tokens.ListItem
| marked.Tokens.Paragraph
| marked.Tokens.HTML
| marked.Tokens.Text
| marked.Tokens.Def
| marked.Tokens.Escape
| marked.Tokens.Tag
| marked.Tokens.Image
| marked.Tokens.Link
| marked.Tokens.Strong
| marked.Tokens.Em
| marked.Tokens.Codespan
| marked.Tokens.Br
| marked.Tokens.Del
| CustomToken;
export type Token = MarkedToken | CustomToken;