Skip to content
Merged
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
21 changes: 17 additions & 4 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
"organizeImports": {
"enabled": false
"$schema": "https://biomejs.dev/schemas/2.0.5/schema.json",
"assist": {
"actions": {
"source": {
"organizeImports": "on"
}
}
},
"linter": {
"enabled": true,
Expand All @@ -19,7 +23,16 @@
"enabled": true
},
"files": {
"ignore": ["node_modules/", "coverage/", "dist/"]
"includes": [
"src/**",
"examples/**",
"dangerfile.ts",
"biome.json",
"package.json",
"renovate.json",
"tsconfig.json",
"babel.config.js"
]
},
"javascript": {
"jsxRuntime": "reactClassic"
Expand Down
8 changes: 4 additions & 4 deletions examples/react-native-marked-sample/App.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import React, { type ReactNode } from "react";
import {
SafeAreaView,
StyleSheet,
StatusBar,
useColorScheme,
StyleSheet,
Text,
type TextStyle,
useColorScheme,
} from "react-native";
import Markdown, {
Renderer,
MarkedTokenizer,
Renderer,
type RendererInterface,
type Tokens,
} from "react-native-marked";
import { MD_STRING } from "./const";

class CustomTokenizer extends MarkedTokenizer {
codespan(this: MarkedTokenizer, src: string): Tokens.Codespan | undefined {
const match = src.match(/^\$+([^\$\n]+?)\$+/);
const match = src.match(/^\$+([^$\n]+?)\$+/);
if (match?.[1]) {
return {
type: "codespan",
Expand Down
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
"test:updateSnapshot": "jest --updateSnapshot",
"reassure": "reassure"
},
"keywords": ["react-native", "markdown", "react-native markdown"],
"keywords": [
"react-native",
"markdown",
"react-native markdown"
],
"repository": "https://github.com/gmsgowtham/react-native-marked",
"author": "Gowtham G <[email protected]> (https://github.com/gmsgowtham)",
"license": "MIT",
Expand All @@ -50,7 +54,7 @@
"@babel/core": "7.27.4",
"@babel/helper-explode-assignable-expression": "7.18.6",
"@babel/preset-env": "7.27.2",
"@biomejs/biome": "1.9.4",
"@biomejs/biome": "2.0.5",
"@commitlint/config-conventional": "19.8.1",
"@evilmartians/lefthook": "1.11.14",
"@react-native/babel-preset": "0.78.2",
Expand Down Expand Up @@ -93,7 +97,9 @@
]
},
"commitlint": {
"extends": ["@commitlint/config-conventional"],
"extends": [
"@commitlint/config-conventional"
],
"rules": {
"type-enum": [
2,
Expand Down
10 changes: 5 additions & 5 deletions src/components/MDImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import React, {
} from "react";
import {
ActivityIndicator,
ImageBackground,
Image,
ImageBackground,
type ImageStyle,
} from "react-native";

Expand All @@ -34,10 +34,6 @@ const MDImage: FunctionComponent<MDImageProps> = ({
aspectRatio: undefined,
});

useEffect(() => {
fetchOriginalSizeFromRemoteImage();
}, []);

/**
* Fetches image dimension
* Sets aspect ratio if resolved
Expand All @@ -63,6 +59,10 @@ const MDImage: FunctionComponent<MDImageProps> = ({
);
};

useEffect(() => {
fetchOriginalSizeFromRemoteImage();
});

return (
<ImageBackground
source={{ uri: uri }}
Expand Down
8 changes: 4 additions & 4 deletions src/components/MDSvg.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, {
memo,
type FunctionComponent,
memo,
useEffect,
useState,
useRef,
useState,
} from "react";
import { ActivityIndicator, View, type LayoutChangeEvent } from "react-native";
import { ActivityIndicator, type LayoutChangeEvent, View } from "react-native";
import { SvgFromXml } from "react-native-svg";
import { getSvgDimensions } from "./../utils/svg";

Expand Down Expand Up @@ -55,7 +55,7 @@ const MDSvg: FunctionComponent<MDSvgProps> = ({ uri, alt = "image" }) => {
error: false,
aspectRatio: width / height,
});
} catch (e) {
} catch (_e) {
setSvgState((state) => ({
...state,
error: true,
Expand Down
6 changes: 3 additions & 3 deletions src/components/MDTable.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { memo, type FunctionComponent, type ReactNode } from "react";
import { View, ScrollView, type ViewStyle } from "react-native";
import { Table, TableWrapper, Cell } from "react-native-reanimated-table";
import React, { type FunctionComponent, memo, type ReactNode } from "react";
import { ScrollView, View, type ViewStyle } from "react-native";
import { Cell, Table, TableWrapper } from "react-native-reanimated-table";

type MDTableProps = {
header: ReactNode[][];
Expand Down
8 changes: 4 additions & 4 deletions src/hooks/useMarkdown.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useMemo, type ReactNode } from "react";
import { lexer, type Tokenizer } from "marked";
import type { MarkedStyles, UserTheme } from "./../theme/types";
import { type ReactNode, useMemo } from "react";
import type { ColorSchemeName } from "react-native";
import Parser from "../lib/Parser";
import Renderer from "../lib/Renderer";
import getStyles from "./../theme/styles";
import type { ColorSchemeName } from "react-native";
import type { RendererInterface } from "../lib/types";
import getStyles from "./../theme/styles";
import type { MarkedStyles, UserTheme } from "./../theme/types";

export interface useMarkdownHookOptions {
colorScheme?: ColorSchemeName;
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Tokenizer as MarkedTokenizer, marked } from "marked";
import type { Token, Tokens } from "marked";
import { Tokenizer as MarkedTokenizer, marked } from "marked";
import useMarkdown, { type useMarkdownHookOptions } from "./hooks/useMarkdown";
import Markdown from "./lib/Markdown";
import Renderer from "./lib/Renderer";
import useMarkdown, { type useMarkdownHookOptions } from "./hooks/useMarkdown";
import type {
MarkdownProps,
ParserOptions,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Markdown.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useCallback, type ReactElement, type ReactNode } from "react";
import React, { type ReactElement, type ReactNode, useCallback } from "react";
import { FlatList, useColorScheme } from "react-native";
import type { MarkdownProps } from "./types";
import useMarkdown from "../hooks/useMarkdown";
import type { MarkdownProps } from "./types";

const Markdown = ({
value,
Expand Down
10 changes: 5 additions & 5 deletions src/lib/Parser.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { ReactNode } from "react";
import type { TextStyle, ViewStyle, ImageStyle } from "react-native";
import type { Token, Tokens } from "marked";
import { decode } from "html-entities";
import type { Token, Tokens } from "marked";
import type { ReactNode } from "react";
import type { ImageStyle, TextStyle, ViewStyle } from "react-native";
import type { MarkedStyles } from "../theme/types";
import type { RendererInterface, ParserOptions } from "./types";
import { getValidURL } from "./../utils/url";
import { getTableColAlignmentStyle } from "./../utils/table";
import { getValidURL } from "./../utils/url";
import type { ParserOptions, RendererInterface } from "./types";

class Parser {
private renderer: RendererInterface;
Expand Down
22 changes: 11 additions & 11 deletions src/lib/Renderer.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import Decimal from "@jsamr/counter-style/presets/decimal";
import Disc from "@jsamr/counter-style/presets/disc";
import MarkedList from "@jsamr/react-native-li";
import Slugger from "github-slugger";
import React, { type ReactNode } from "react";
import {
Dimensions,
type ImageStyle,
ScrollView,
View,
Text,
TouchableHighlight,
type TextStyle,
TouchableHighlight,
View,
type ViewStyle,
type ImageStyle,
Dimensions,
} from "react-native";
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 "github-slugger";
import MDImage from "./../components/MDImage";
import { onLinkPress } from "../utils/handlers";
import type { RendererInterface } from "./types";
import { getTableWidthArr } from "../utils/table";
import MDSvg from "./../components/MDSvg";
import MDTable from "./../components/MDTable";
import { onLinkPress } from "../utils/handlers";
import { getTableWidthArr } from "../utils/table";
import type { RendererInterface } from "./types";

class Renderer implements RendererInterface {
private slugPrefix = "react-native-marked-ele";
Expand Down
4 changes: 2 additions & 2 deletions src/lib/__perf__/Markdown.perf-test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { screen } from "@testing-library/react-native";
import React from "react";
import { StyleSheet } from "react-native";
import { screen } from "@testing-library/react-native";
import { measureRenders } from "reassure";
import Markdown from "../Markdown";
import type { MarkedStyles, UserTheme } from "../../theme/types";
import Markdown from "../Markdown";

const mdString = `Markdown Quick Reference
========================
Expand Down
6 changes: 3 additions & 3 deletions src/lib/__tests__/Markdown.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { type ReactNode } from "react";
import { render, screen, waitFor } from "@testing-library/react-native";
import { Tokenizer, type Tokens } from "marked";
import React, { type ReactNode } from "react";
import { Text, type TextStyle } from "react-native";
import Markdown from "../Markdown";
import Renderer from "../Renderer";
import type { RendererInterface } from "../types";
import { Tokenizer, type Tokens } from "marked";

// https://www.markdownguide.org/basic-syntax/#headings
describe("Headings", () => {
Expand Down Expand Up @@ -826,7 +826,7 @@ describe("Tokenizer", () => {

class CustomTokenizer extends Tokenizer {
codespan(src: string): Tokens.Codespan | undefined {
const match = src.match(/^\$+([^\$\n]+?)\$+/);
const match = src.match(/^\$+([^$\n]+?)\$+/);
if (match?.[1]) {
return {
type: "codespan",
Expand Down
6 changes: 3 additions & 3 deletions src/lib/__tests__/Renderer.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Linking, type ColorSchemeName } from "react-native";
import {
fireEvent,
render,
screen,
waitFor,
} from "@testing-library/react-native";
import Renderer from "../Renderer";
import type { ReactElement } from "react";
import { type ColorSchemeName, Linking } from "react-native";
import getStyles from "../../theme/styles";
import type { MarkedStyles } from "../../theme/types";
import type { ReactElement } from "react";
import Renderer from "../Renderer";

jest.mock("react-native/Libraries/Linking/Linking", () => ({
openURL: jest.fn(() => Promise.resolve("mockResolve")),
Expand Down
6 changes: 3 additions & 3 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { Tokenizer } from "marked";
import type { ReactNode } from "react";
import type {
FlatListProps,
ViewStyle,
TextStyle,
ImageStyle,
TextStyle,
ViewStyle,
} from "react-native";
import type { MarkedStyles, UserTheme } from "./../theme/types";
import type { Tokenizer } from "marked";

export interface ParserOptions {
styles?: MarkedStyles;
Expand Down
2 changes: 1 addition & 1 deletion src/theme/__tests__/styles.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import colors from "../colors";
import type { MarkedStyles } from "../types";
import getStyles from "./../styles";
import type { MarkedStyles } from "../types";

describe("getStyles", () => {
it("light scheme", () => {
Expand Down
4 changes: 2 additions & 2 deletions src/theme/styles.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { StyleSheet, type ColorSchemeName } from "react-native";
import spacing from "./spacing";
import { type ColorSchemeName, StyleSheet } from "react-native";
import colors, { type ColorsPropType } from "./colors";
import spacing from "./spacing";
import type { MarkedStyles, UserTheme } from "./types";

const getFontStyles = (mdColors: ColorsPropType) => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/__tests__/table.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getTableWidthArr, getTableColAlignmentStyle } from "./../table";
import { getTableColAlignmentStyle, getTableWidthArr } from "./../table";

describe("getTableWidthArr", () => {
const windowWidth = 360;
Expand Down
Loading