add auto link
This commit is contained in:
@@ -1,10 +1,21 @@
|
||||
import React, {Component} from 'react';
|
||||
|
||||
import TimeAgo from 'react-timeago';
|
||||
import Linkify, {linkify} from 'react-linkify';
|
||||
import chineseStrings from 'react-timeago/lib/language-strings/zh-CN';
|
||||
import buildFormatter from 'react-timeago/lib/formatters/buildFormatter';
|
||||
|
||||
import './Common.css';
|
||||
|
||||
const chinese_format=buildFormatter(chineseStrings);
|
||||
const PID_RE_TEXT=/(?:^|[^\d])(\d{5,6})(?!\d)/g;
|
||||
|
||||
linkify.add('#', {
|
||||
validate: /^(\d{5,6})/,
|
||||
normalize: (match) => {
|
||||
match.url='#'+match.url;
|
||||
},
|
||||
});
|
||||
|
||||
function pad2(x) {
|
||||
return x<10 ? '0'+x : ''+x;
|
||||
@@ -28,4 +39,12 @@ export function TitleLine(props) {
|
||||
<span>{props.text}</span>
|
||||
</p>
|
||||
)
|
||||
}
|
||||
|
||||
export function AutoLink(props) {
|
||||
return (
|
||||
<Linkify properties={{target: '_blank'}}>
|
||||
<pre>{props.text.replace(new RegExp(PID_RE_TEXT,'g'),' #$1 ')}</pre>
|
||||
</Linkify>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user