Browse Source

支持嵌入视频

pull/16/head
hole-thu 3 years ago
parent
commit
f91c2c8e0c
  1. 2
      public/index.html
  2. 2
      src/Common.css
  3. 32
      src/Common.js

2
public/index.html

@ -6,6 +6,8 @@
<link rel="icon" href="%PUBLIC_URL%/static/favicon/512.png">
<meta name="format-detection" content="telephone=no">
<meta name="referrer" content="no-referrer">
<meta name="mobile-web-app-capable" content="yes">
<link rel="shortcut icon" href="%PUBLIC_URL%/static/favicon/512.png">
<link rel="manifest" href="./static/manifest.json">

2
src/Common.css

@ -59,7 +59,7 @@
margin-left: .15rem;
}
.ext-img {
.ext-img, .ext-video {
max-width: 100%;
max-height: 2000px;
display: block;

32
src/Common.js

@ -24,6 +24,15 @@ function escape_regex(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}
function is_video(s) {
try {
let url = new URL(s);
return url.pathname.endsWith('.mp4') || url.pathname.endsWith('.mov');
} catch (e) {
return false;
}
}
export function build_highlight_re(
txt,
split = ' ',
@ -150,15 +159,20 @@ export class HighlightedMarkdown extends Component {
/##
</span>
) : rule === 'url' ? (
<a
href={normalize_url(p)}
className="ext-link"
target="_blank"
rel="noopener noreferrer"
>
{p}
<span className="icon icon-new-tab" />
</a>
<>
<a
href={normalize_url(p)}
className="ext-link"
target="_blank"
rel="noopener noreferrer"
>
{p}
<span className="icon icon-new-tab" />
</a>
{is_video(p) && (
<video className="ext-video" src={p} controls loop/>
)}
</>
) : rule === 'pid' ? (
<a
href={'#' + p}

Loading…
Cancel
Save