Skip to content

Commit c6d6bd2

Browse files
committed
fixing issue mientjan#52
fixed issue mientjan#46
1 parent 1def748 commit c6d6bd2

File tree

12 files changed

+86
-34
lines changed

12 files changed

+86
-34
lines changed

example/App.js

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,54 @@ const renderer = new AstRenderer(
6262
const routes = {
6363
all: () => (
6464
<ScrollView>
65-
<Markdown children={all} />
65+
<Markdown
66+
children={all}
67+
style={StyleSheet.create({
68+
foo: {
69+
color: 'red',
70+
},
71+
})}
72+
rules={{
73+
foo: (node, children, parent, styles) => (
74+
<Text key={node.key} style={styles.foo}>
75+
{node.content}
76+
</Text>
77+
),
78+
}}
79+
plugins={[
80+
new PluginContainer(
81+
(md, name, options) => {
82+
const parse = state => {
83+
const Token = state.Token;
84+
85+
for (let i = 0; i < state.tokens.length; i++) {
86+
const block = state.tokens[i];
87+
if (block.type !== 'inline') {
88+
continue;
89+
}
90+
91+
for (let j = 0; j < block.children.length; j++) {
92+
const token = block.children[j];
93+
if (token.type !== 'text') {
94+
continue;
95+
}
96+
97+
if (token.content === name) {
98+
const newToken = new Token(name, '', token.nesting);
99+
newToken.content = token.content;
100+
block.children = md.utils.arrayReplaceAt(block.children, j, [newToken]);
101+
}
102+
}
103+
}
104+
};
105+
106+
md.core.ruler.after('inline', name, parse);
107+
},
108+
'foo',
109+
{}
110+
),
111+
]}
112+
/>
66113
</ScrollView>
67114
),
68115
linkedimg: () => (

example/react-native-markdown-renderer/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { MarkdownIt, Token } from 'markdown-it';
33
import { ComponentType, ReactNode } from 'react';
44
import { StyleSheet, View } from 'react-native';
55

6+
export function applyStyle(children: any[], styles: any, type: string): any;
7+
68
export function getUniqueID(): string;
79
export function openUrl(url: string): void;
810

example/react-native-markdown-renderer/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import React, { Component } from 'react';
66
import PropTypes from 'prop-types';
77
import { View } from 'react-native';
88
import { parser, stringToTokens } from './lib/parser';
9+
import applyStyle from './lib/util/applyStyle';
910
import getUniqueID from './lib/util/getUniqueID';
1011
import hasParents from './lib/util/hasParents';
1112
import openUrl from './lib/util/openUrl';
@@ -21,6 +22,7 @@ import { styles } from './lib/styles';
2122
*
2223
*/
2324
export {
25+
applyStyle,
2426
getUniqueID,
2527
openUrl,
2628
hasParents,
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default [
2+
'text',
3+
'span',
4+
'strong',
5+
'code_inline',
6+
'link',
7+
's',
8+
'em',
9+
'softbreak',
10+
];

example/react-native-markdown-renderer/lib/styles.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Platform, StyleSheet } from 'react-native';
2-
import PlatformEnum from './enum/PlatformEnum';
2+
import PlatformEnum from './data/PlatformEnum';
33

44
/**
55
*
Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
1-
/**
2-
*
3-
* @type {[string,string,string,string,string,string,string]}
4-
*/
5-
const textTypes = [
6-
'text',
7-
'span',
8-
'strong',
9-
'link',
10-
's',
11-
'em',
12-
'softbreak',
13-
];
1+
import InlineTextTypes from "../data/InlineTextTypes"
142

153
/**
164
*
175
* @param node
186
* @return {boolean}
197
*/
20-
export default function getIsInlineTextType(type) {
21-
return textTypes.indexOf(type) > -1;
8+
export default function getIsInlineTextType(type, ) {
9+
return InlineTextTypes.indexOf(type) > -1;
2210
}

example/src/copy/all.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
const copy = `
2-
# Syntax Support
2+
# Syntax Support
3+
foo
4+
5+
# code inline
6+
7+
Hello \`code inline\` code_inline
38
49
__Advertisement :)__
510

src/lib/data/InlineTextTypes.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default [
2+
'text',
3+
'span',
4+
'strong',
5+
'code_inline',
6+
'link',
7+
's',
8+
'em',
9+
'softbreak',
10+
];
File renamed without changes.

src/lib/styles.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Platform, StyleSheet } from 'react-native';
2-
import PlatformEnum from './enum/PlatformEnum';
2+
import PlatformEnum from './data/PlatformEnum';
33

44
/**
55
*

src/lib/util/getIsInlineTextType.js

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
1-
/**
2-
*
3-
* @type {[string,string,string,string,string,string,string]}
4-
*/
5-
const textTypes = [
6-
'text',
7-
'span',
8-
'strong',
9-
'link',
10-
's',
11-
'em',
12-
'softbreak',
13-
];
1+
import InlineTextTypes from "../data/InlineTextTypes"
142

153
/**
164
*
175
* @param node
186
* @return {boolean}
197
*/
20-
export default function getIsInlineTextType(type) {
21-
return textTypes.indexOf(type) > -1;
8+
export default function getIsInlineTextType(type, ) {
9+
return InlineTextTypes.indexOf(type) > -1;
2210
}

0 commit comments

Comments
 (0)