diff --git a/package-lock.json b/package-lock.json index f208b89..ba4a60f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6305,6 +6305,14 @@ "type-check": "0.3.2" } }, + "linkify-it": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-2.0.3.tgz", + "integrity": "sha1-2UpGSPmxwXnWT6lykSaL22zpQ08=", + "requires": { + "uc.micro": "1.0.5" + } + }, "load-json-file": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz", @@ -8788,6 +8796,16 @@ "resolved": "https://registry.npmjs.org/react-lazyload/-/react-lazyload-2.3.0.tgz", "integrity": "sha512-0z3qmL+qtSERdfKFpn0yKXm+1Gg1ZLZBXnCzHhSGiu1L8iDARuCkbOypxEx9+ETxZvMnXj98xvWCs5jyXTuM2w==" }, + "react-linkify": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/react-linkify/-/react-linkify-0.2.2.tgz", + "integrity": "sha512-0S8cvUNtEgfJpIGDPKklyrnrTffJ63WuJAc4KaYLBihl5TjgH5cHUmYD+AXLpsV+CVmfoo/56SUNfrZcY4zYMQ==", + "requires": { + "linkify-it": "2.0.3", + "prop-types": "15.6.2", + "tlds": "1.203.1" + } + }, "react-scripts": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/react-scripts/-/react-scripts-1.1.4.tgz", @@ -10091,6 +10109,11 @@ "setimmediate": "1.0.5" } }, + "tlds": { + "version": "1.203.1", + "resolved": "https://registry.npmjs.org/tlds/-/tlds-1.203.1.tgz", + "integrity": "sha512-7MUlYyGJ6rSitEZ3r1Q1QNV8uSIzapS8SmmhSusBuIc7uIxPPwsKllEP0GRp1NS6Ik6F+fRZvnjDWm3ecv2hDw==" + }, "tmp": { "version": "0.0.33", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", @@ -10234,6 +10257,11 @@ "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.18.tgz", "integrity": "sha512-LtzwHlVHwFGTptfNSgezHp7WUlwiqb0gA9AALRbKaERfxwJoiX0A73QbTToxteIAuIaFshhgIZfqK8s7clqgnA==" }, + "uc.micro": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.5.tgz", + "integrity": "sha512-JoLI4g5zv5qNyT09f4YAvEZIIV1oOjqnewYg5D38dkQljIzpPT296dbIGvKro3digYI1bkb7W6EP1y4uDlmzLg==" + }, "uglify-js": { "version": "3.4.7", "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.4.7.tgz", diff --git a/package.json b/package.json index 8f733ad..cbfbc10 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,9 @@ "react": "^16.4.2", "react-dom": "^16.4.2", "react-lazyload": "^2.3.0", + "react-linkify": "^0.2.2", "react-scripts": "1.1.4", - "react-timeago": "^4.1.9" + "react-timeago": "^4.1.9", }, "scripts": { "start": "react-scripts start", diff --git a/src/Common.js b/src/Common.js index 42a72d0..b0498d1 100644 --- a/src/Common.js +++ b/src/Common.js @@ -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) { {props.text}
) +} + +export function AutoLink(props) { + return ( +{props.text.replace(new RegExp(PID_RE_TEXT,'g'),' #$1 ')}+
{props.info.text}+
{props.info.text}+