# rntpc_react-native-markdown-display
**Repository Path**: openharmony-sig/rntpc_react-native-markdown-display
## Basic Information
- **Project Name**: rntpc_react-native-markdown-display
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: master
- **Homepage**: https://gitee.com/openharmony-sig/rntpc_react-native-markdown-display
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2024-10-14
- **Last Updated**: 2025-05-07
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# 🚨 **重要提示 | IMPORTANT**
>
> **⚠️ 此代码仓已归档。新地址请访问 [rntpc_react-native-markdown-display](https://gitcode.com/openharmony-sig/rntpc_react-native-markdown-display)。| ⚠️ This repository has been archived. For the new address, please visit [rntpc_react-native-markdown-display](https://gitcode.com/openharmony-sig/rntpc_react-native-markdown-display).**
>
---
>
# React Native Markdown Display [](https://badge.fury.io/js/react-native-markdown-display) [](https://snyk.io/test/github/iamacup/react-native-markdown-display)
It a 100% compatible CommonMark renderer, a react-native markdown renderer done right. This is __not__ a web-view markdown renderer but a renderer that uses native components for all its elements. These components can be overwritten and styled as needed.
### Compatibility with react-native-markdown-renderer
This is intended to be a replacement for react-native-markdown-renderer, with a variety of bug fixes and enhancements - **Due to how the new style rules work, there may be some tweaking needed**, [see how to style stuff section below](#How-to-style-stuff)
### Install
#### Yarn
```npm
yarn add react-native-markdown-display
```
#### NPM
```npm
npm install -S react-native-markdown-display
```
### Get Started
```jsx
import React from 'react';
import { SafeAreaView, ScrollView, StatusBar } from 'react-native';
import Markdown from 'react-native-markdown-display';
const copy = `# h1 Heading 8-)
**This is some bold text!**
This is normal text
`;
const App: () => React$Node = () => {
return (
<>
```
# h1 Heading 8-)
## h2 Heading
### h3 Heading
#### h4 Heading
##### h5 Heading
###### h6 Heading
```
| iOS | Android
| --- | ---
|
```
Some text above
___
Some text in the middle
---
Some text below
```
| iOS | Android
| --- | ---
|
```
**This is bold text**
__This is bold text__
*This is italic text*
_This is italic text_
~~Strikethrough~~
```
| iOS | Android
| --- | ---
|
```
> Blockquotes can also be nested...
>> ...by using additional greater-than signs right next to each other...
> > > ...or with spaces between arrows.
```
| iOS | Android
| --- | ---
|
```
Unordered
+ Create a list by starting a line with `+`, `-`, or `*`
+ Sub-lists are made by indenting 2 spaces:
- Marker character change forces new list start:
* Ac tristique libero volutpat at
+ Facilisis in pretium nisl aliquet. This is a very long list item that will surely wrap onto the next line.
- Nulla volutpat aliquam velit
+ Very easy!
Ordered
1. Lorem ipsum dolor sit amet
2. Consectetur adipiscing elit. This is a very long list item that will surely wrap onto the next line.
3. Integer molestie lorem at massa
Start numbering with offset:
57. foo
58. bar
```
| iOS | Android
| --- | ---
|
```
Inline \`code\`
Indented code
// Some comments
line 1 of code
line 2 of code
line 3 of code
Block code "fences"
\`\`\`
Sample text here...
\`\`\`
Syntax highlighting
\`\`\` js
var foo = function (bar) {
return bar++;
};
console.log(foo(5));
\`\`\`
```
| iOS | Android
| --- | ---
|
```
| Option | Description |
| ------ | ----------- |
| data | path to data files to supply the data that will be passed into templates. |
| engine | engine to be used for processing templates. Handlebars is the default. |
| ext | extension to be used for dest files. |
Right aligned columns
| Option | Description |
| ------:| -----------:|
| data | path to data files to supply the data that will be passed into templates. |
| engine | engine to be used for processing templates. Handlebars is the default. |
| ext | extension to be used for dest files. |
```
| iOS | Android
| --- | ---
|
```
[link text](https://www.google.com)
[link with title](https://www.google.com "title text!")
Autoconverted link https://www.google.com (enable linkify to see)
```
| iOS | Android
| --- | ---
|
```


Like links, Images also have a footnote style syntax
![Alt text][id]
With a reference later in the document defining the URL location:
[id]: https://octodex.github.com/images/dojocat.jpg "The Dojocat"
```
| iOS | Android
| --- | ---
|
```
Enable typographer option to see result.
(c) (C) (r) (R) (tm) (TM) (p) (P) +-
test.. test... test..... test?..... test!....
!!!!!! ???? ,, -- ---
"Smartypants, double quotes" and 'single quotes'
```
| iOS | Android
| --- | ---
|
Plugins for **extra** syntax support can be added using any markdown-it compatible plugins - [see plugins](https://www.npmjs.com/browse/keyword/markdown-it-plugin) for documentation from markdown-it. An example for integration follows:
#### Step 1
Identify the new components and integrate the plugin with a rendered component. We can use the `debugPrintTree` property to see what rules we are rendering:
```jsx
import React from 'react';
import { SafeAreaView, ScrollView, StatusBar } from 'react-native';
import Markdown, { MarkdownIt } from 'react-native-markdown-display';
import blockEmbedPlugin from 'markdown-it-block-embed';
const markdownItInstance =
MarkdownIt({typographer: true})
.use(blockEmbedPlugin, {
containerClassName: "video-embed"
});
const copy = `
# Some header
@[youtube](lJIrF4YjHfQ)
`;
const App: () => React$Node = () => {
return (
<>
Headings
|
Horizontal Rules
|
Emphasis
|
Blockquotes
|
Lists
|
Code
|
Tables
|
Links
|
Images
|
Typographic Replacements
|
Plugins and Extensions
Some header
```
This is all of the markdown in one place for testing that your applied styles work in all cases ``` Headings # h1 Heading 8-) ## h2 Heading ### h3 Heading #### h4 Heading ##### h5 Heading ###### h6 Heading Horizontal Rules Some text above ___ Some text in the middle --- Some text below Emphasis **This is bold text** __This is bold text__ *This is italic text* _This is italic text_ ~~Strikethrough~~ Blockquotes > Blockquotes can also be nested... >> ...by using additional greater-than signs right next to each other... > > > ...or with spaces between arrows. Lists Unordered + Create a list by starting a line with `+`, `-`, or `*` + Sub-lists are made by indenting 2 spaces: - Marker character change forces new list start: * Ac tristique libero volutpat at + Facilisis in pretium nisl aliquet. This is a very long list item that will surely wrap onto the next line. - Nulla volutpat aliquam velit + Very easy! Ordered 1. Lorem ipsum dolor sit amet 2. Consectetur adipiscing elit. This is a very long list item that will surely wrap onto the next line. 3. Integer molestie lorem at massa Start numbering with offset: 57. foo 58. bar Code Inline \`code\` Indented code // Some comments line 1 of code line 2 of code line 3 of code Block code "fences" \`\`\` Sample text here... \`\`\` Syntax highlighting \`\`\` js var foo = function (bar) { return bar++; }; console.log(foo(5)); \`\`\` Tables | Option | Description | | ------ | ----------- | | data | path to data files to supply the data that will be passed into templates. | | engine | engine to be used for processing templates. Handlebars is the default. | | ext | extension to be used for dest files. | Right aligned columns | Option | Description | | ------:| -----------:| | data | path to data files to supply the data that will be passed into templates. | | engine | engine to be used for processing templates. Handlebars is the default. | | ext | extension to be used for dest files. | Links [link text](https://www.google.com) [link with title](https://www.google.com "title text!") Autoconverted link https://www.google.com (enable linkify to see) Images   Like links, Images also have a footnote style syntax ![Alt text][id] With a reference later in the document defining the URL location: [id]: https://octodex.github.com/images/dojocat.jpg "The Dojocat" Typographic Replacements Enable typographer option to see result. (c) (C) (r) (R) (tm) (TM) (p) (P) +- test.. test... test..... test?..... test!.... !!!!!! ???? ,, -- --- "Smartypants, double quotes" and 'single quotes' ```
```jsx
import React from 'react';
import { SafeAreaView, ScrollView, StatusBar } from 'react-native';
import Markdown from 'react-native-markdown-display';
const copy = `
This is some text which is red because of the body style, which is also really small!
\`\`\`
//This is a code block woooo
const cool = () => {
console.log('????');
};
\`\`\`
and some more small text
# This is a h1
## this is a h2
### this is a h3
`;
const App: () => React$Node = () => {
return (
<>
```jsx
import React from 'react';
import { SafeAreaView, ScrollView, StatusBar, StyleSheet } from 'react-native';
import Markdown from 'react-native-markdown-display';
const styles = StyleSheet.create({
heading1: {
fontSize: 32,
backgroundColor: '#000000',
color: '#FFFFFF',
},
heading2: {
fontSize: 24,
},
heading3: {
fontSize: 18,
},
heading4: {
fontSize: 16,
},
heading5: {
fontSize: 13,
},
heading6: {
fontSize: 11,
}
});
const copy = `
# h1 Heading 8-)
## h2 Heading 8-)
### h3 Heading 8-)
| Option | Description |
| ------ | ----------- |
| data | path to data files to supply the data that will be passed into templates. |
| engine | engine to be used for processing templates. Handlebars is the default. |
| ext | extension to be used for dest files. |
`;
const App: () => React$Node = () => {
return (
<>
```jsx
import React from 'react';
import { SafeAreaView, ScrollView, StatusBar, Text } from 'react-native';
import Markdown from 'react-native-markdown-display';
const rules = {
heading1: (node, children, parent, styles) =>
```jsx
import React from 'react';
import { SafeAreaView, ScrollView, StatusBar } from 'react-native';
import Markdown from 'react-native-markdown-display';
const copy = `[This is a link!](https://github.com/iamacup/react-native-markdown-display/)`;
const onLinkPress = (url) => {
if (url) {
// some custom logic
return false;
}
// return true to open with `Linking.openURL
// return false to handle it yourself
return true
}
const App: () => React$Node = () => {
return (
<>
You will need to overwrite one or both of `link` and `blocklink`, the original defenitions can be [found here](https://github.com/iamacup/react-native-markdown-display/blob/master/src/lib/renderRules.js)
Something like this with `yourCustomHandlerFunctionOrLogicHere`:
```jsx
import React from 'react';
import { SafeAreaView, ScrollView, StatusBar, Text } from 'react-native';
import Markdown from 'react-native-markdown-display';
const copy = `[This is a link!](https://github.com/iamacup/react-native-markdown-display/)`;
const rules = {
link: (node, children, parent, styles) => {
return (