Skip to content
This repository has been archived by the owner on Nov 11, 2021. It is now read-only.

Commit

Permalink
修复锚点失效问题;添加不是本站下的路由在新标签页中打开
Browse files Browse the repository at this point in the history
  • Loading branch information
woytu committed Dec 19, 2019
1 parent acdbcf6 commit 1c14776
Show file tree
Hide file tree
Showing 5 changed files with 1,929 additions and 426 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,27 @@ woytu Soft:https://www.woytu.com
└ ......
```

* [https://www.php.net/manual/zh](https://www.php.net/manual/zh)

---

* [https://github.com/erusev/parsedown](https://github.com/erusev/parsedown)

* [https://github.com/erusev/parsedown-extra](https://github.com/erusev/parsedown-extra)

* [https://github.com/taufik-nurrohman/parsedown-extra-plugin](https://github.com/taufik-nurrohman/parsedown-extra-plugin)

* [https://github.com/mrgeneralgoo/typecho-markdown](https://github.com/mrgeneralgoo/typecho-markdown)

---

* [https://getcomposer.org](https://getcomposer.org)

* [https://github.com/michelf/php-markdown](https://github.com/michelf/php-markdown)

* [https://github.com/thephpleague/commonmark](https://github.com/thephpleague/commonmark)


## 注意事项:

### 不显示文件和目录
Expand Down
27 changes: 25 additions & 2 deletions resources/DirectoryLister.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// https://github.com/erusev/parsedown
// 导入Parsedown依赖
require_once('Parsedown.php');
require_once('ParsedownExtra.php');
require_once('ParsedownExtraPlugin.php');
/**
* 一个简单的基于PHP的目录列表器,列出了内容
* 目录及其所有子目录,并且允许轻松
Expand Down Expand Up @@ -464,11 +466,32 @@ public function getReadme()
// 如果配置为空,默认使用Markdown方式
if ($readme_mode == "" || strtoupper($readme_mode) != "HTML") {
$md_path = $md_path . "/README.md";
// https://github.com/erusev/parsedown
$Parsedown = new Parsedown();

if (!file_exists($md_path)) {
return "";
}
// https://github.com/erusev/parsedown
// https://github.com/erusev/parsedown-extra
// https://github.com/tovic/parsedown-extra-plugin
$Parsedown = new ParsedownExtraPlugin();

$Parsedown->headerAttributes = function ($Text, $Attributes, &$Element, $Level) {
$Id = $Attributes['id'] ?? trim(
preg_replace(['/[^a-z\d\x{4e00}-\x{9fa5}]+/u'], '-', strtolower($Text)),
'-'
);
return ['id' => $Id];
};
$Parsedown->linkAttributes = function ($Text, $Attributes, &$Element, $Internal) {
$href = strtolower($Attributes['href']);
// https://www.chrisyue.com/the-fastest-way-to-implement-starts-with-in-php.html
if (!$Internal && strpos($href, "https") === 0 && strpos($href, "http") === 0) {
return [
'target' => '_blank'
];
}
return [];
};
return $Parsedown->text(file_get_contents($md_path));
} else {
$md_path = $md_path . "/README.html";
Expand Down
Loading

0 comments on commit 1c14776

Please sign in to comment.