@@ -24,40 +24,43 @@ import pluginRules from './src/pluginRules';
2424import all from './src/copy/all' ;
2525import linkedimg from './src/copy/linkedimg' ;
2626
27- const instructions = Platform . select ( {
28- ios : 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu' ,
29- android : 'Double tap R on your keyboard to reload,\n' + 'Shake or press menu button for dev menu' ,
30- } ) ;
27+ import MarkdownIt from 'markdown-it' ;
3128
32- const rules = {
33- // added custom block element defined by plugin
34- block : ( node , children , parents , style ) => {
35- return (
36- < Text key = { getUniqueID ( ) } style = { { backgroundColor : 'green' } } >
37- { children }
38- </ Text >
39- ) ;
40- } ,
41-
42- checkbox : ( node , children , parents , style ) => {
43- return (
44- < Text key = { getUniqueID ( ) } style = { { backgroundColor : 'green' } } >
45- { children }
46- </ Text >
47- ) ;
48- } ,
49- } ;
29+ const md = MarkdownIt ( {
30+ typographer : true ,
31+ linkify : true ,
32+ } ) ;
5033
51- /**
52- * i'm overriding the default h1 render function.
53- */
54- const renderer = new AstRenderer (
55- {
56- ...renderRules ,
57- ...rules ,
58- } ,
59- styles
60- ) ;
34+ md . linkify . tlds ( '.py' , false ) ; // disables .py as top level domain
35+ // Reload with full tlds list
36+ md . linkify . tlds ( 'onion' , true ) // Add unofficial `.onion` domain
37+ md . linkify . add ( 'git:' , 'http:' ) // Add `git:` protocol as "alias"
38+ md . linkify . add ( 'ftp:' , null ) // Disable `ftp:` ptotocol
39+ md . linkify . set ( { fuzzyIP : true } ) ; // Enable IPs in fuzzy links (without schema)
40+
41+ md . linkify . add ( '@' , {
42+ validate : function ( text , pos , self ) {
43+ var tail = text . slice ( pos ) ;
44+
45+ if ( ! self . re . twitter ) {
46+ self . re . twitter = new RegExp (
47+ '^([a-zA-Z0-9_]){1,15}(?!_)(?=$|' + self . re . src_ZPCc + ')'
48+ ) ;
49+ }
50+ if ( self . re . twitter . test ( tail ) ) {
51+ // Linkifier allows punctuation chars before prefix,
52+ // but we additionally disable `@` ("@@mention" is invalid)
53+ if ( pos >= 2 && tail [ pos - 2 ] === '@' ) {
54+ return false ;
55+ }
56+ return tail . match ( self . re . twitter ) [ 0 ] . length ;
57+ }
58+ return 0 ;
59+ } ,
60+ normalize : function ( match ) {
61+ match . url = 'https://twitter.com/' + match . url . replace ( / ^ @ / , '' ) ;
62+ }
63+ } ) ;
6164
6265const routes = {
6366 all : ( ) => (
@@ -115,7 +118,7 @@ const routes = {
115118 ) ,
116119 linkedimg : ( ) => (
117120 < ScrollView >
118- < Markdown children = { linkedimg } />
121+ < Markdown markdownit = { md } children = { linkedimg } />
119122 </ ScrollView >
120123 ) ,
121124} ;
@@ -131,10 +134,6 @@ export default class App extends Component {
131134 routes : [ { key : 'all' , title : 'All' } , { key : 'linkedimg' , title : 'Linked Images' } ] ,
132135 } ;
133136
134- handleChangeValue = ( itemValue , itemIndex ) => {
135- this . setState ( { view : itemIndex } ) ;
136- } ;
137-
138137 handleIndexChange = index => this . setState ( { index } ) ;
139138 renderHeader = props => < TabBar { ...props } /> ;
140139 renderScene = SceneMap ( routes ) ;
@@ -150,25 +149,4 @@ export default class App extends Component {
150149 />
151150 ) ;
152151 }
153-
154- render3 ( ) {
155- let currentView = this . state . view ;
156-
157- return (
158- < View style = { styleSheet . container } >
159- < Text > { currentView } </ Text >
160- < Picker selectedValue = { currentView } onValueChange = { this . handleChangeValue } >
161- { this . list . map ( ( val , index ) => < Picker . Item key = { val . description } label = { val . description } value = { index } /> ) }
162- </ Picker >
163- < ScrollView > { this . getView ( currentView ) } </ ScrollView >
164- </ View >
165- ) ;
166- }
167152}
168-
169- const styleSheet = StyleSheet . create ( {
170- container : {
171- flex : 1 ,
172- marginTop : 20 ,
173- } ,
174- } ) ;
0 commit comments