Observed since 20 Oct, 22:00 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
@03balogun/react-native-marked
Markdown renderer for React Native powered by marked.js
react-native-marked without FlatList
Markdown renderer for React Native powered by marked.js with built-in theming support
yarn add react-native-marked react-native-svg
import * as React from "react";
import Markdown from "react-native-marked";
const ExampleComponent = () => {
return (
<Markdown
value={`# Hello world`}
flatListProps={{
initialNumToRender: 8,
}}
/>
);
};
export default ExampleComponent;
| Prop | Description | Type | Optional? |
|---|---|---|---|
| value | Markdown value | string | false |
| flatListProps | Props for customizing the underlying FlatList used | Omit<FlatListProps<ReactNode>, 'data' | 'renderItem' | 'horizontal'>( 'data', 'renderItem', and 'horizontal' props are omitted and cannot be overridden.) | true |
| styles | Styles for parsed components | MarkedStyles | true |
| theme | Props for customizing colors and spacing for all components,and it will get overridden with custom component style applied via 'styles' prop | UserTheme | true |
| baseUrl | A prefix url for any relative link | string | true |
| renderer | Custom component Renderer | RendererInterface | true |
useMarkdown hook will return list of elements that can be rendered using a list component of your choice.
import React, { Fragment } from "react";
import { ScrollView, useColorScheme } from "react-native";
import { useMarkdown, type useMarkdownHookOptions } from "react-native-marked";
const CustomComponent = () => {
const colorScheme = useColorScheme();
const options: useMarkdownHookOptions = {
colorScheme
}
const elements = useMarkdown("# Hello world", options);
return (
<ScrollView>
{elements.map((element, index) => {
return <Fragment key={`demo_${index}`}>{element}</Fragment>
})}
</ScrollView>
);
};
| Option | Description | Type | Optional? |
|---|---|---|---|
| colorScheme | Device color scheme ("dark" or "light") | ColorSchemeName | false |
| styles | Styles for parsed components | MarkedStyles | true |
| theme | Props for customizing colors and spacing for all components,and it will get overridden with custom component style applied via 'styles' prop | UserTheme | true |
| baseUrl | A prefix url for any relative link | string | true |
| renderer | Custom component Renderer | RendererInterface | true |
| tokenizer | Generate custom tokens | MarkedTokenizer | true |
Ref: CommonMark
HTML will be treated as plain text. Please refer issue#290 for a potential solution
Custom components can be used to override elements, i.e. Code Highlighting, Fast Image integration
import React, { ReactNode, Fragment } from "react";
import { Text, ScrollView } from "react-native";
import type { ImageStyle, TextStyle } from "react-native";
import Markdown, { Renderer, useMarkdown } from "react-native-marked";
import type { RendererInterface } from "react-native-marked";
import FastImage from "react-native-fast-image";
class CustomRenderer extends Renderer implements RendererInterface {
constructor() {
super();
}
codespan(text: string, _styles?: TextStyle): ReactNode {
return (
<Text key={this.getKey()} style={{ backgroundColor: "#ff0000" }}>
{text}
</Text>
);
}
image(uri: string, _alt?: string, _style?: ImageStyle): ReactNode {
return (
<FastImage
key={this.getKey()}
style={{ width: 200, height: 200 }}
source={{ uri: uri }}
resizeMode={FastImage.resizeMode.contain}
/>
);
}
}
const renderer = new CustomRenderer();
const ExampleComponent = () => {
return (
<Markdown
value={"`Hello world`"}
flatListProps={{
initialNumToRender: 8,
}}
renderer={renderer}
/>
);
};
// Alternate using hook
const ExampleComponentWithHook = () => {
const elements = useMarkdown("`Hello world`", { renderer });
return (
<ScrollView>
{elements.map((element, index) => {
return <Fragment key={`demo_${index}`}>{element}</Fragment>
})}
</ScrollView>
)
}
export default ExampleComponent;
Please refer to RendererInterface for all the overrides
Note:
For
keyproperty for a component, you can use thegetKeymethod from Renderer class.
Refer marked
The tokenizer defines how to turn markdown text into tokens. If you supply a tokenizer object to the Marked options, it will be merged with the built-in tokenizer and any functions inside will override the default handling of that token type.
The implementation requires you to return a token of type 'custom' (ref: CustomToken) and the same needs to be implemented in the Renderer
Overriding default codespan tokenizer to include LaTeX.
import React, { ReactNode } from "react";
import Markdown, { Renderer, MarkedTokenizer, MarkedLexer } from "react-native-marked";
import type { RendererInterface, type CustomToken, } from "react-native-marked";
class CustomTokenizer extends MarkedTokenizer<CustomToken> {
// Override
codespan(this: MarkedTokenizer<CustomToken>, src: string) {
const match = src.match(/^\$+([^\$\n]+?)\$+/);
if (match?.[1]) {
const text = match[1].trim();
const token: CustomToken = {
type: 'custom',
raw: match[0], // should be the exact regex pattern match
identifier: "latex", // Uniq identifier for the token
tokens: MarkedLexer(text), // optional, can be used if the markdown contains children
args: { // optional, can be used to send more information to the renderer
text: text,
}
};
return token;
}
return super.codespan(src)
}
}
class CustomRenderer extends Renderer implements RendererInterface {
// Custom Token implementation
custom(identifier: string, _raw: string, _children?: ReactNode[], args?: Record<string, unknown>): ReactNode {
if (identifier === "latex") {
const styles = {
padding: 16,
minWidth: "100%",
backgroundColor: "#f6f8fa"
};
return this.code(text.trim(), "latex", styles);
}
return null;
}
}
const renderer = new CustomRenderer();
const tokenizer = new CustomTokenizer();
const ExampleComponent = () => {
return (
<Markdown
value={"$ latex code $\n\n` other code `"}
flatListProps={{
initialNumToRender: 8,
}}
renderer={renderer}
tokenizer={tokenizer}
/>
);
};
| Dark Theme | Light Theme |
|---|---|
![]() | ![]() |
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT
Made with create-react-native-library
Download counts and popularity will appear here as the collector receives them.
| Package / target | Requirement | Relationship |
|---|---|---|
svg-parserEnvironment{
"local_name": "svg-parser",
"alias": false,
"peer_metadata": null
} | 2.0.4 | runtime |
html-entitiesEnvironment{
"local_name": "html-entities",
"alias": false,
"peer_metadata": null
} | 2.5.2 | runtime |
@03balogun/markedEnvironment{
"local_name": "@03balogun/marked",
"alias": false,
"peer_metadata": null
} | ^5.0.6 | runtime |
@jsamr/counter-styleEnvironment{
"local_name": "@jsamr/counter-style",
"alias": false,
"peer_metadata": null
} | 2.0.2 | runtime |
@jsamr/react-native-liEnvironment{
"local_name": "@jsamr/react-native-li",
"alias": false,
"peer_metadata": null
} | 2.3.1 | runtime |
react-native-table-componentEnvironment{
"local_name": "react-native-table-component",
"alias": false,
"peer_metadata": null
} | 1.2.2 | runtime |
jestEnvironment{
"local_name": "jest",
"alias": false,
"peer_metadata": null
} | 29.7.0 | development |
reactEnvironment{
"local_name": "react",
"alias": false,
"peer_metadata": null
} | 18.3.1 | development |
dangerEnvironment{
"local_name": "danger",
"alias": false,
"peer_metadata": null
} | 11.3.1 | development |
reassureEnvironment{
"local_name": "reassure",
"alias": false,
"peer_metadata": null
} | 0.11.0 | development |
commitlintEnvironment{
"local_name": "commitlint",
"alias": false,
"peer_metadata": null
} | 19.3.0 | development |
release-itEnvironment{
"local_name": "release-it",
"alias": false,
"peer_metadata": null
} | 17.1.1 | development |
typescriptEnvironment{
"local_name": "typescript",
"alias": false,
"peer_metadata": null
} | 5.4.5 | development |
@babel/coreEnvironment{
"local_name": "@babel/core",
"alias": false,
"peer_metadata": null
} | 7.24.4 | development |
@types/jestEnvironment{
"local_name": "@types/jest",
"alias": false,
"peer_metadata": null
} | 29.5.12 | development |
@types/nodeEnvironment{
"local_name": "@types/node",
"alias": false,
"peer_metadata": null
} | 20.12.7 | development |
pod-installEnvironment{
"local_name": "pod-install",
"alias": false,
"peer_metadata": null
} | 0.2.2 | development |
@types/reactEnvironment{
"local_name": "@types/react",
"alias": false,
"peer_metadata": null
} | 18.3.2 | development |
react-nativeEnvironment{
"local_name": "react-native",
"alias": false,
"peer_metadata": null
} | 0.72.6 | development |
@types/markedEnvironment{
"local_name": "@types/marked",
"alias": false,
"peer_metadata": null
} | 5.0.0 | development |
@biomejs/biomeEnvironment{
"local_name": "@biomejs/biome",
"alias": false,
"peer_metadata": null
} | 1.3.3 | development |
@babel/preset-envEnvironment{
"local_name": "@babel/preset-env",
"alias": false,
"peer_metadata": null
} | 7.24.4 | development |
@types/svg-parserEnvironment{
"local_name": "@types/svg-parser",
"alias": false,
"peer_metadata": null
} | ^2.0.3 | development |
@types/react-nativeEnvironment{
"local_name": "@types/react-native",
"alias": false,
"peer_metadata": null
} | 0.72.6 | development |
react-test-rendererEnvironment{
"local_name": "react-test-renderer",
"alias": false,
"peer_metadata": null
} | 18.3.1 | development |
@evilmartians/lefthookEnvironment{
"local_name": "@evilmartians/lefthook",
"alias": false,
"peer_metadata": null
} | 1.6.10 | development |
jest-environment-jsdomEnvironment{
"local_name": "jest-environment-jsdom",
"alias": false,
"peer_metadata": null
} | 29.7.0 | development |
postinstall-postinstallEnvironment{
"local_name": "postinstall-postinstall",
"alias": false,
"peer_metadata": null
} | 2.1.0 | development |
react-native-builder-bobEnvironment{
"local_name": "react-native-builder-bob",
"alias": false,
"peer_metadata": null
} | 0.23.2 | development |
@testing-library/jest-nativeEnvironment{
"local_name": "@testing-library/jest-native",
"alias": false,
"peer_metadata": null
} | 5.4.3 | development |
@testing-library/react-nativeEnvironment{
"local_name": "@testing-library/react-native",
"alias": false,
"peer_metadata": null
} | 12.5.0 | development |
@commitlint/config-conventionalEnvironment{
"local_name": "@commitlint/config-conventional",
"alias": false,
"peer_metadata": null
} | 19.2.2 | development |
metro-react-native-babel-presetEnvironment{
"local_name": "metro-react-native-babel-preset",
"alias": false,
"peer_metadata": null
} | 0.77.0 | development |
@release-it/conventional-changelogEnvironment{
"local_name": "@release-it/conventional-changelog",
"alias": false,
"peer_metadata": null
} | 8.0.1 | development |
@types/react-native-table-componentEnvironment{
"local_name": "@types/react-native-table-component",
"alias": false,
"peer_metadata": null
} | 1.2.8 | development |
reactEnvironment{
"local_name": "react",
"alias": false,
"peer_metadata": null
} | ^16.8.6 || ^17.0.0 || ^18.0.0 | peer |
react-nativeEnvironment{
"local_name": "react-native",
"alias": false,
"peer_metadata": null
} | >=0.60.0 | peer |
react-native-svgEnvironment{
"local_name": "react-native-svg",
"alias": false,
"peer_metadata": null
} | >=13.14.0 | peer |
Source distribution
{
"shasum": "281ccb618c72b0af73a7a36dcd3949518ec4badc",
"tarball": "https://registry.npmjs.org/@03balogun/react-native-marked/-/react-native-marked-6.1.0.tgz",
"fileCount": 120,
"integrity": "sha512-GVeh49idg9gGwP2rP0scmT51yUIEWZzixQCqujwakELlhuwl+ad5qmZHnDNk9iG10baAL6BhP6WbOuOeKOv/3g==",
"signatures": [
{
"sig": "MEYCIQDtmQdIb985sSHN9CPuM8TTTu0BwsT7D2XzEWRGR49N5wIhAOLB5d63mW3Gh5aDJstG+JGhgH+Zx0iyg5MZokSEnTwB",
"keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"
}
],
"unpackedSize": 220075
}Shared repository data · GitHub
Shared repository data · GitHub
Observed since 20 Oct, 22:00 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package_version:7ce5fd78510e6839add39b0d8a7b3e06e617ddf098b366fae29866defd39588a