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

Dependency updates (primarily React 17 and React Native 0.64.2) #147

Open
wants to merge 6 commits into
base: master
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
8 changes: 4 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module.exports = {
root: true,
extends: '@react-native-community',
settings: {
react: {
version: require('./package.json').peerDependencies.react,
},
}
react: {
version: require('./package.json').peerDependencies.react,
},
},
};
26 changes: 14 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,26 @@
"homepage": "https://github.com/iamacup/react-native-markdown-display/",
"dependencies": {
"css-to-react-native": "^3.0.0",
"markdown-it": "^10.0.0",
"markdown-it": "^13.0.0",
"prop-types": "^15.7.2",
"react-native-fit-image": "^1.5.5"
},
"peerDependencies": {
"react": "^16.2.0",
"react": "^17 || ^18",
"react-native": ">=0.50.4"
},
"devDependencies": {
"@types/markdown-it": "^10.0.1",
"@types/react-native": ">=0.50.0",
"@babel/core": "^7.9.6",
"@babel/runtime": "^7.9.6",
"@react-native-community/eslint-config": "^1.1.0",
"@typescript-eslint/parser": "^2.32.0",
"eslint": "^7.0.0",
"json-schema": "^0.2.5",
"pre-commit": "1.2.2",
"typescript": "^3.8.3"
"@babel/core": "^7.15.0",
"@babel/runtime": "^7.15.3",
"@react-native-community/eslint-config": "^3.0.0",
"@types/markdown-it": "^12.2.1",
"@types/react-native": "^0.64.13",
"@typescript-eslint/parser": "^4.29.3",
"eslint": "^7.32.0",
"eslint-plugin-prettier": "^4.0.0",
"json-schema": "^0.4.0",
"pre-commit": "^1.2.2",
"prettier": "^2.6.2",
"typescript": "^4.4.2"
}
}
2 changes: 2 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export interface ASTNode {
}

export class AstRenderer {
// eslint-disable-next-line no-shadow
constructor(renderRules: RenderRules, style?: any);
getRenderFunction(type: string): RenderFunction;
renderNode(node: any, parentNodes: ReadonlyArray<any>): ReactNode;
Expand All @@ -71,6 +72,7 @@ export class AstRenderer {
export function parser(
source: string,
renderer: (node: ASTNode) => View,
// eslint-disable-next-line no-shadow
parser: MarkdownParser,
): any;

Expand Down
50 changes: 20 additions & 30 deletions src/lib/renderRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@ import hasParents from './util/hasParents';

import textStyleProps from './data/textStyleProps';

function renderText(node, inheritedStyles, styles) {
// we trim new lines off the end of code blocks because the parser sends an extra one.
let {content} = node;

if (
typeof node.content === 'string' &&
node.content.charAt(node.content.length - 1) === '\n'
) {
content = node.content.substring(0, node.content.length - 1);
}

return (
<Text key={node.key} style={[inheritedStyles, styles.code_block]}>
{content}
</Text>
);
}

const renderRules = {
// when unknown elements are introduced, so it wont break
unknown: (node, children, parent, styles) => null,
Expand Down Expand Up @@ -177,38 +195,10 @@ const renderRules = {
</Text>
),
code_block: (node, children, parent, styles, inheritedStyles = {}) => {
// we trim new lines off the end of code blocks because the parser sends an extra one.
let {content} = node;

if (
typeof node.content === 'string' &&
node.content.charAt(node.content.length - 1) === '\n'
) {
content = node.content.substring(0, node.content.length - 1);
}

return (
<Text key={node.key} style={[inheritedStyles, styles.code_block]}>
{content}
</Text>
);
return renderText(node, inheritedStyles, styles);
},
fence: (node, children, parent, styles, inheritedStyles = {}) => {
// we trim new lines off the end of code blocks because the parser sends an extra one.
let {content} = node;

if (
typeof node.content === 'string' &&
node.content.charAt(node.content.length - 1) === '\n'
) {
content = node.content.substring(0, node.content.length - 1);
}

return (
<Text key={node.key} style={[inheritedStyles, styles.fence]}>
{content}
</Text>
);
return renderText(node, inheritedStyles, styles);
},

// Tables
Expand Down
2 changes: 1 addition & 1 deletion src/lib/util/cleanupTokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function cleanupTokens(tokens) {
* nested non text tokens breaks component
*/
const stack = [];
tokens = tokens.reduce((acc, token, index) => {
tokens = tokens.reduce((acc, token) => {
if (token.type === 'link' && token.nesting === 1) {
stack.push(token);
} else if (
Expand Down
4 changes: 1 addition & 3 deletions src/lib/util/convertAdditionalStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,5 @@ export default function convertAdditionalStyles(style) {
return x != null;
});

const conv = cssToReactNative(tuples);

return conv;
return cssToReactNative(tuples);
}
2 changes: 1 addition & 1 deletion src/lib/util/groupTextTokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default function groupTextTokens(tokens) {

let hasGroup = false;

tokens.forEach((token, index) => {
tokens.forEach((token) => {
if (!token.block && !hasGroup) {
hasGroup = true;
result.push(new Token('textgroup', 1));
Expand Down
4 changes: 2 additions & 2 deletions src/lib/util/renderInlineAsText.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default function renderInlineAsText(tokens) {
var result = '';
let result = '';

for (var i = 0, len = tokens.length; i < len; i++) {
for (let i = 0, len = tokens.length; i < len; i++) {
if (tokens[i].type === 'text') {
result += tokens[i].content;
} else if (tokens[i].type === 'image') {
Expand Down