Skip to content

Commit

Permalink
cleanup of example code
Browse files Browse the repository at this point in the history
  • Loading branch information
mientjan committed Jun 18, 2018
1 parent 5a1e572 commit 65f0fcc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 58 deletions.
94 changes: 36 additions & 58 deletions example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,43 @@ import pluginRules from './src/pluginRules';
import all from './src/copy/all';
import linkedimg from './src/copy/linkedimg';

const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
android: 'Double tap R on your keyboard to reload,\n' + 'Shake or press menu button for dev menu',
});
import MarkdownIt from 'markdown-it';

const rules = {
// added custom block element defined by plugin
block: (node, children, parents, style) => {
return (
<Text key={getUniqueID()} style={{ backgroundColor: 'green' }}>
{children}
</Text>
);
},

checkbox: (node, children, parents, style) => {
return (
<Text key={getUniqueID()} style={{ backgroundColor: 'green' }}>
{children}
</Text>
);
},
};
const md = MarkdownIt({
typographer: true,
linkify: true,
});

/**
* i'm overriding the default h1 render function.
*/
const renderer = new AstRenderer(
{
...renderRules,
...rules,
},
styles
);
md.linkify.tlds('.py', false); // disables .py as top level domain
// Reload with full tlds list
md.linkify.tlds('onion', true) // Add unofficial `.onion` domain
md.linkify.add('git:', 'http:') // Add `git:` protocol as "alias"
md.linkify.add('ftp:', null) // Disable `ftp:` ptotocol
md.linkify.set({ fuzzyIP: true }); // Enable IPs in fuzzy links (without schema)

md.linkify.add('@', {
validate: function (text, pos, self) {
var tail = text.slice(pos);

if (!self.re.twitter) {
self.re.twitter = new RegExp(
'^([a-zA-Z0-9_]){1,15}(?!_)(?=$|' + self.re.src_ZPCc + ')'
);
}
if (self.re.twitter.test(tail)) {
// Linkifier allows punctuation chars before prefix,
// but we additionally disable `@` ("@@mention" is invalid)
if (pos >= 2 && tail[pos - 2] === '@') {
return false;
}
return tail.match(self.re.twitter)[0].length;
}
return 0;
},
normalize: function (match) {
match.url = 'https://twitter.com/' + match.url.replace(/^@/, '');
}
});

const routes = {
all: () => (
Expand Down Expand Up @@ -115,7 +118,7 @@ const routes = {
),
linkedimg: () => (
<ScrollView>
<Markdown children={linkedimg} />
<Markdown markdownit={md} children={linkedimg} />
</ScrollView>
),
};
Expand All @@ -131,10 +134,6 @@ export default class App extends Component {
routes: [{ key: 'all', title: 'All' }, { key: 'linkedimg', title: 'Linked Images' }],
};

handleChangeValue = (itemValue, itemIndex) => {
this.setState({ view: itemIndex });
};

handleIndexChange = index => this.setState({ index });
renderHeader = props => <TabBar {...props} />;
renderScene = SceneMap(routes);
Expand All @@ -150,25 +149,4 @@ export default class App extends Component {
/>
);
}

render3() {
let currentView = this.state.view;

return (
<View style={styleSheet.container}>
<Text>{currentView}</Text>
<Picker selectedValue={currentView} onValueChange={this.handleChangeValue}>
{this.list.map((val, index) => <Picker.Item key={val.description} label={val.description} value={index} />)}
</Picker>
<ScrollView>{this.getView(currentView)}</ScrollView>
</View>
);
}
}

const styleSheet = StyleSheet.create({
container: {
flex: 1,
marginTop: 20,
},
});
2 changes: 2 additions & 0 deletions example/src/copy/linkedimg.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const copy = `
## Links
@hello
`;
const copy2 = `
**tes
Expand Down

0 comments on commit 65f0fcc

Please sign in to comment.