Skip to content
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

Let's see what this does #199

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4c557fc
removed unneed json-schema dev dep
hammoudma Nov 13, 2022
0a8cf0c
update markdown-it
hammoudma Nov 13, 2022
5137b4a
updated readme with code that worked with latest react and typescript
ar-to Feb 19, 2023
60990a8
adding sourceinfo and sourceMeta to ASTNode
Feb 21, 2023
e513784
Merge pull request #1 from hammoudma/master
RonRadtke Feb 21, 2023
ffc60a4
Merge pull request #3 from ar-to/readme_update
RonRadtke Feb 21, 2023
1cffb62
Update index.d.ts
Feb 21, 2023
cbdf78a
update dependencies
Feb 21, 2023
7660aa4
Allow for custom Text components (e.g. for themes)
Mar 1, 2023
62665ad
commit package-lock.json
orangecms Mar 2, 2023
876f433
remove pre-commit, we will run checks in CI
orangecms Mar 1, 2023
4d383e2
set up GitHub Action for code checks
orangecms Mar 1, 2023
6d0f19a
Upgrade to TypeScript 4
orangecms Mar 2, 2023
b5592a6
install prettier as dev dependency
orangecms Mar 2, 2023
9577110
prettierrc: remove jsxBracketSameLine
orangecms Mar 2, 2023
441fac9
add format and format-check scripts
orangecms Mar 2, 2023
e525d9c
format files in src/
orangecms Mar 2, 2023
c9d36cd
GitHub Workflows: add format check
orangecms Mar 2, 2023
b98b42a
restore 2-space formatting
orangecms Mar 9, 2023
56badbb
upgrade ESLint and @react-native-community/eslint-config
orangecms Mar 9, 2023
fc56f2e
extend ESLint config, add import plugin
orangecms Mar 9, 2023
7eb827f
use const instead of let, give Markdown component a display name
orangecms Mar 9, 2023
99b9e27
renderRules: make links accessible
orangecms Mar 9, 2023
0f186f2
styles: workaround for odd spacings in links
orangecms Mar 9, 2023
954c25e
update package name
Mar 15, 2023
2a673db
set up npm publish GitHub Action
orangecms Mar 1, 2023
031aad3
update redme
Mar 31, 2023
57fb36c
Merge pull request #4 from RonRadtke/npm-publish-action
RonRadtke Mar 31, 2023
a176175
Update README.md
simondelphia Jun 28, 2023
619d0f0
Update README.md
simondelphia Jun 28, 2023
51d2691
Fix typos in markdown imports in readmes
simondelphia Jul 7, 2023
e092385
Update font: Courier -> Courier New
bi3ri Oct 22, 2023
7484044
fix: lib is broken as it is not pure javasript, but a mix out of type…
macrozone Dec 4, 2023
25fc44a
Merge pull request #12 from bi3ri/patch-1
RonRadtke Sep 10, 2024
7762a30
Merge pull request #11 from simondelphia/patch-1
RonRadtke Sep 10, 2024
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: 5 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"presets": [
"module:metro-react-native-babel-preset"
]
}
29 changes: 24 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
module.exports = {
root: true,
extends: '@react-native-community',
extends: [
'@react-native-community',
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript',
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'prettier',
],
plugins: ['@typescript-eslint'],
parserOptions: {
ecmaVersion: 6,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
},
settings: {
react: {
version: require('./package.json').peerDependencies.react,
},
react: {
version: require('./package.json').peerDependencies.react,
},
'import/ignore': ['node_modules'],
}
};
27 changes: 27 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Code checks

on:
push:
branches: [ "master", "main" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "master", "main" ]

jobs:
checks:
name: Code checks
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install dependencies
run: npm install --ci

- name: Run ESLint
run: npm run lint

- name: Run Prettier
run: npm run format-check

# TODO: type checks...
36 changes: 36 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This workflow will publish a package to npm when a release is created.
# https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages

# TODO: add tests or leave them out, add build steps...?

name: npm publish

on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- run: npm ci
# - run: npm test

publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
registry-url: https://registry.npmjs.org/
- run: npm ci
# - run: npm run build
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/node_modules
/.idea
package-lock.json
/.DS_Store
yarn-error.log
yarn.lock
Expand Down
2 changes: 1 addition & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
bracketSpacing: false,
jsxBracketSameLine: true,
singleQuote: true,
trailingComma: 'all',
useTabs: false,
};
144 changes: 130 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# React Native Markdown Display [![npm version](https://badge.fury.io/js/react-native-markdown-display.svg)](https://badge.fury.io/js/react-native-markdown-display) [![Known Vulnerabilities](https://snyk.io/test/github/iamacup/react-native-markdown-display/badge.svg)](https://snyk.io/test/github/iamacup/react-native-markdown-display)
# React Native Markdown Display [![npm version](https://badge.fury.io/js/@ronradtke%2Freact-native-markdown-display.svg)](https://badge.fury.io/js/@ronradtke%2Freact-native-markdown-display) [![Known Vulnerabilities](https://snyk.io/test/github/iamacup/react-native-markdown-display/badge.svg)](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.

Expand All @@ -10,12 +10,12 @@ This is intended to be a replacement for react-native-markdown-renderer, with a

#### Yarn
```npm
yarn add react-native-markdown-display
yarn add @ronradtke/react-native-markdown-display
```

#### NPM
```npm
npm install -S react-native-markdown-display
npm install -S @ronradtke/react-native-markdown-display
```

### Get Started
Expand All @@ -24,7 +24,7 @@ npm install -S react-native-markdown-display
import React from 'react';
import { SafeAreaView, ScrollView, StatusBar } from 'react-native';

import Markdown from 'react-native-markdown-display';
import Markdown from '@ronradtke/react-native-markdown-display';

const copy = `# h1 Heading 8-)

Expand Down Expand Up @@ -53,7 +53,123 @@ const App: () => React$Node = () => {

export default App;
```
You can find this example [here](https://snack.expo.dev/@hassieb/react-native-markdown-display-ordered-list)

This next example worked with `"react-native-markdown-display": "^7.0.0-alpha.2",` on React`18.1.0`, React Native `0.70.5` via the Expo command `npx create-expo-app --template` with typescript selected.

```jsx
import React from "react";
import { StyleSheet, SafeAreaView, ScrollView, StatusBar } from "react-native";
import { useTheme } from "@react-navigation/native";

import Markdown from "react-native-markdown-display";

const copy = `# h1 Heading 8-)

**This is some bold text!**

This is normal text
`;

const MarkdownWrapper: React.FC<any> = ({ children }) => {
const { colors } = useTheme();
// @ts-ignore
return <Markdown style={styles({ colors })}>{children}</Markdown>;
};

const App: () => React.ReactElement = () => {
return (
<>
<StatusBar barStyle="dark-content" />
<SafeAreaView>
<ScrollView
contentInsetAdjustmentBehavior="automatic"
style={{ height: "100%" }}
>
<MarkdownWrapper>{copy}</MarkdownWrapper>
</ScrollView>
</SafeAreaView>
</>
);
};

export const styles = (props: any) =>
StyleSheet.create({
text: {
color: props.colors.text,
},
});

export default App;
```

With text input

```jsx
import React from "react";
import {
StyleSheet,
SafeAreaView,
ScrollView,
StatusBar,
TextInput,
} from "react-native";
import { useTheme } from "@react-navigation/native";

import Markdown from "react-native-markdown-display";

const copy = `# h1 Heading 8-)

**This is some bold text!**

This is normal text
`;

const MarkdownWrapper: React.FC<any> = ({ children }) => {
const { colors } = useTheme();
// @ts-ignore
return <Markdown style={styles({ colors })}>{children}</Markdown>;
};

const App: () => React.ReactElement = () => {
const [text, onChangeText] = React.useState(copy);
const { colors } = useTheme();
return (
<>
<StatusBar barStyle="dark-content" />
<SafeAreaView>
<ScrollView
contentInsetAdjustmentBehavior="automatic"
style={{ height: "100%" }}
>
<TextInput
multiline
style={{ ...styles({colors}).input, color: colors.text }}
onChangeText={onChangeText}
value={text}
/>
<MarkdownWrapper>{text}</MarkdownWrapper>
</ScrollView>
</SafeAreaView>
</>
);
};

export const styles = (props: any) =>
StyleSheet.create({
text: {
color: props.colors.text,
},
input: {
height: 80,
margin: 12,
borderWidth: 1,
padding: 10,
},
});

export default App;
```

### Props and Functions

Expand Down Expand Up @@ -346,7 +462,7 @@ Identify the new components and integrate the plugin with a rendered component.
import React from 'react';
import { SafeAreaView, ScrollView, StatusBar } from 'react-native';

import Markdown, { MarkdownIt } from 'react-native-markdown-display';
import Markdown, { MarkdownIt }from '@ronradtke/react-native-markdown-display';
import blockEmbedPlugin from 'markdown-it-block-embed';

const markdownItInstance =
Expand Down Expand Up @@ -412,7 +528,7 @@ We need to create the **render rules** and **styles** to handle this new **'vide
import React from 'react';
import { SafeAreaView, ScrollView, StatusBar } from 'react-native';

import Markdown, { MarkdownIt } from 'react-native-markdown-display';
import Markdown, { MarkdownIt }from '@ronradtke/react-native-markdown-display';
import blockEmbedPlugin from 'markdown-it-block-embed';

const markdownItInstance =
Expand Down Expand Up @@ -499,7 +615,7 @@ And all of the video properties needed to render something meaningful are on the
You can do some additional debugging of what the markdown instance is spitting out like this:

```jsx
import Markdown, { MarkdownIt } from 'react-native-markdown-display';
import Markdown, { MarkdownIt }from '@ronradtke/react-native-markdown-display';
import blockEmbedPlugin from 'markdown-it-block-embed';

const markdownItInstance =
Expand Down Expand Up @@ -731,7 +847,7 @@ Think of the implementation like applying styles in CSS. changes to the `body` e
import React from 'react';
import { SafeAreaView, ScrollView, StatusBar } from 'react-native';

import Markdown from 'react-native-markdown-display';
import Markdown from '@ronradtke/react-native-markdown-display';

const copy = `
This is some text which is red because of the body style, which is also really small!
Expand Down Expand Up @@ -794,7 +910,7 @@ Styles are used to override how certain rules are styled. The existing implement
import React from 'react';
import { SafeAreaView, ScrollView, StatusBar, StyleSheet } from 'react-native';

import Markdown from 'react-native-markdown-display';
import Markdown from '@ronradtke/react-native-markdown-display';

const styles = StyleSheet.create({
heading1: {
Expand Down Expand Up @@ -868,7 +984,7 @@ Rules are used to specify how you want certain elements to be displayed. The exi
import React from 'react';
import { SafeAreaView, ScrollView, StatusBar, Text } from 'react-native';

import Markdown from 'react-native-markdown-display';
import Markdown from '@ronradtke/react-native-markdown-display';

const rules = {
heading1: (node, children, parent, styles) =>
Expand Down Expand Up @@ -977,7 +1093,7 @@ It is possible to overwrite this behaviour in one of two ways:
import React from 'react';
import { SafeAreaView, ScrollView, StatusBar } from 'react-native';

import Markdown from 'react-native-markdown-display';
import Markdown from '@ronradtke/react-native-markdown-display';

const copy = `[This is a link!](https://github.com/iamacup/react-native-markdown-display/)`;

Expand Down Expand Up @@ -1029,7 +1145,7 @@ Something like this with `yourCustomHandlerFunctionOrLogicHere`:
import React from 'react';
import { SafeAreaView, ScrollView, StatusBar, Text } from 'react-native';

import Markdown from 'react-native-markdown-display';
import Markdown from '@ronradtke/react-native-markdown-display';

const copy = `[This is a link!](https://github.com/iamacup/react-native-markdown-display/)`;

Expand Down Expand Up @@ -1080,7 +1196,7 @@ This example will stop images and links.
import React from 'react';
import { SafeAreaView, ScrollView, StatusBar, Text } from 'react-native';

import Markdown, { MarkdownIt } from 'react-native-markdown-display';
import Markdown, { MarkdownIt }from '@ronradtke/react-native-markdown-display';

const copy = `
# This heading will show with formatting
Expand Down Expand Up @@ -1124,7 +1240,7 @@ It is possible to need to pre-process the data outside of this library ([related
import React from 'react';
import { SafeAreaView, ScrollView, StatusBar, Text } from 'react-native';

import Markdown, { MarkdownIt, tokensToAST, stringToTokens } from 'react-native-markdown-display';
import Markdown, { MarkdownIt, tokensToAST, stringToTokens }from '@ronradtke/react-native-markdown-display';

const markdownItInstance = MarkdownIt({typographer: true});

Expand Down
Loading