Skip to content

Commit

Permalink
支持自动添加 TOC/TOCM 目录命令到 Markdown 文档,基于配置 WIZARD_MARKDOWN_TOC_DEFAULT
Browse files Browse the repository at this point in the history
  • Loading branch information
mylxsw committed Jan 22, 2021
1 parent 7802b75 commit a733d70
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
20 changes: 20 additions & 0 deletions app/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,26 @@ function convertSqlTo(string $sql, $callback)
}
}

/**
* Markdown 预处理
*
* @param string $markdown
* @return string
*/
function processMarkdown(string $markdown): string
{
$defaultTOC = config('wizard.markdown.default_toc');
if (!in_array($defaultTOC, ['TOC', 'TOCM'])) {
return $markdown;
}

if (Str::contains($markdown, ['[TOC]', '[TOCM]'])) {
return $markdown;
}

return "[{$defaultTOC}]\n\n{$markdown}";
}

/**
* 预处理 X-spreadsheet 表格内容
*
Expand Down
14 changes: 10 additions & 4 deletions config/wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,23 @@
/**
* Markdown 配置
*/
'markdown' => [
'markdown' => [
/**
* 是否启用严格的 Markdown 解释器,如果你的 markdown 格式并不标准,可以将该选项设置为 false
*/
'strict' => env('WIZARD_MARKDOWN_STRICT', true),
'strict' => env('WIZARD_MARKDOWN_STRICT', true),
/**
* 是否自动添加 TOC(文档目录,当页面内容中不包含 TOC/TOCM 标签时,自动添加)
*
* 设置为空则不启用该功能,如果启用,则设置为 TOC 或者 TOCM
*/
'default_toc' => env('WIZARD_MARKDOWN_TOC_DEFAULT', ''),
],

/**
* 表格类型文档配置
*/
'spreedsheet' => [
'spreedsheet' => [
/**
* 最大支持的行数
*/
Expand All @@ -122,7 +128,7 @@
/**
* 文件附件
*/
'attachments' => [
'attachments' => [
/**
* 支持的文件扩展名列表,使用,分割
*/
Expand Down
1 change: 1 addition & 0 deletions resources/views/components/markdown-show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
}
editormd.markdownToHTML('markdown-body', {
tocm: true,
toc: true,
tocDropdown: false,
markdownSourceCode: true,
taskList: true,
Expand Down
2 changes: 1 addition & 1 deletion resources/views/project/project.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@

<div class="markdown-body wz-panel-limit {{ $type == 'markdown' ? 'wz-markdown-style-fix' : '' }}" id="markdown-body">
@if($type === 'markdown')
<textarea class="d-none wz-markdown-content">{{ $pageItem->content }}</textarea>
<textarea class="d-none wz-markdown-content">{{ processMarkdown($pageItem->content ?? '') }}</textarea>
@endif
@if($type === 'table')
<textarea id="x-spreadsheet-content" class="d-none">{{ processSpreedSheet($pageItem->content) }}</textarea>
Expand Down

0 comments on commit a733d70

Please sign in to comment.