Unicode 代表目录&;标记语法中的文件结构

Unicode 代表目录&;标记语法中的文件结构,unicode,markdown,jekyll,directory-structure,project-structure,Unicode,Markdown,Jekyll,Directory Structure,Project Structure,我想在我的一些Jekyll博客文章中描述目录和文件结构,Markdown是否提供了一种输出此类内容的简洁方法 例如,您可以在Jekyll网站上看到,目录和文件结构在页面上输出得非常整齐: . ├── _config.yml ├── _drafts │ ├── begin-with-the-crazy-ideas.textile │ └── on-simplicity-in-technology.markdown ├── _includes │ ├── footer.html │

我想在我的一些Jekyll博客文章中描述目录和文件结构,Markdown是否提供了一种输出此类内容的简洁方法

例如,您可以在Jekyll网站上看到,目录和文件结构在页面上输出得非常整齐:

.
├── _config.yml
├── _drafts
│   ├── begin-with-the-crazy-ideas.textile
│   └── on-simplicity-in-technology.markdown
├── _includes
│   ├── footer.html
│   └── header.html
├── _layouts
│   ├── default.html
│   └── post.html
├── _posts
│   ├── 2007-10-29-why-every-programmer-should-play-nethack.textile
│   └── 2009-04-26-barcamp-boston-4-roundup.textile
├── _data
│   └── members.yml
├── _site
└── index.html

我相信上面的行块字符是Unicode(如中所述),但我不确定标记或不同的浏览器将如何处理它们。我希望Markdown包含了一些这样做的方法,可能会输出为上面的Unicode字符。

您可以使用它生成与您的示例非常相似的内容。获得输出后,您可以将其包装在
标记中,以保留纯文本格式。

如果您关心Unicode字符,可以使用ASCII构建结构,因此示例结构将变为

.
+-- _config.yml
+-- _drafts
|   +-- begin-with-the-crazy-ideas.textile
|   +-- on-simplicity-in-technology.markdown
+-- _includes
|   +-- footer.html
|   +-- header.html
+-- _layouts
|   +-- default.html
|   +-- post.html
+-- _posts
|   +-- 2007-10-29-why-every-programmer-should-play-nethack.textile
|   +-- 2009-04-26-barcamp-boston-4-roundup.textile
+-- _data
|   +-- members.yml
+-- _site
+-- index.html
```
project
│   README.md
│   file001.txt    
│
└───folder1
│   │   file011.txt
│   │   file012.txt
│   │
│   └───subfolder1
│       │   file111.txt
│       │   file112.txt
│       │   ...
│   
└───folder2
    │   file021.txt
    │   file022.txt
```
这类似于当您选择
ANSI
output时
tree
所使用的格式。

我在中遵循了一个示例,并将目录结构包装在一对三回环中(
`
):


我为我的Dropbox文件列表编写了脚本

sed
用于删除
->

不幸的是,标签丢失了。使用
zsh
我可以保留选项卡

!/usr/bin/env bash



我制作了一个节点模块来自动化此任务:

用法 节点mddir“./relative/path/”

要安装:npm install mddir-g

为当前目录生成标记:mddir

为任何绝对路径生成:mddir/absolute/path

为相对路径生成:mddir~/Documents/whatever

在工作目录中生成md文件

当前忽略节点模块和.git文件夹

故障排除 如果收到错误“node\r:没有这样的文件或目录”,问题是操作系统使用不同的行尾,如果没有将行尾样式显式设置为Unix,mddir将无法解析它们。这通常会影响Windows,但也会影响某些版本的Linux。必须在mddir npm global bin文件夹中执行将行尾设置为Unix样式的操作

行尾固定 使用以下命令获取npm bin文件夹路径:

npm配置获取前缀

将Cd放入该文件夹中

brew安装dos2unix

dos2unix lib/node_modules/mddir/src/mddir.js

这会将行尾转换为Unix而不是Dos

然后使用节点mddir“./relative/path/”正常运行

示例生成的标记文件结构“directoryList.md” 我建议使用,然后你可以使用像这样的标记

root
+-- dir1
    +--file1
+-- dir2
    +-- file2
然后在js库中抛出精确的语法


如果您希望动态生成它,我建议使用。它使用起来很简单。

如前所述,您可以使用
。但是,如果要将其与重新构造的文本一起使用,则需要一些额外的参数

如果您使用
pandoc
生成pdf,则不会打印标准
输出

tree--dirsfirst--charset=ascii/path/to/directory
将生成一个漂亮的
ascii
树,可以像这样集成到文档中:

root
├── dir1
│   └── file1
└── dir2
    └── file2

如果您使用的是Atom编辑器,那么您可以通过包来完成这项工作

您可以编写以下树:

tree -L 1 --charset=ascii
并通过选择它并按ctrl-alt-t将其转换为以下内容:

<pre>
.
&#8866; README.md
&#8866; docs
&#8866; e2e
&#8866; karma.conf.js
&#8866; node_modules
&#8866; package.json
&#8866; protractor.conf.js
&#8866; src
&#8866; tsconfig.json
&#8985; tslint.json
</pre>

在OSX下,使用
reveal.js
,如果我只是使用
tree
,然后复制/粘贴输出,就会出现渲染问题:奇怪的符号出现

我找到了两种可能的解决方案

1) 使用字符集ascii,只需在标记文件中复制/粘贴输出

There is an NPM module for this:

npm dree

It allows you to have a representation of a directory tree as a string or an object. Using it with the command line will allow you to save the representation in a txt file.

Example:

$ npm dree parse myDirectory --dest ./generated --name tree
2) 在标记文件中直接使用HTML和unicode

There is an NPM module for this:

npm dree

It allows you to have a representation of a directory tree as a string or an object. Using it with the command line will allow you to save the representation in a txt file.

Example:

$ npm dree parse myDirectory --dest ./generated --name tree

.
⊢ 自述文件
⊢ 文件
⊢ e2e
⊢ karma.conf.js
⊢ 节点单元
⊢ package.json
⊢ progrator.conf.js
⊢ src
⊢ tsconfig.json
⌙ tslint.json

希望有帮助。

如果您使用的是VS代码,这是一个用于生成文件树的工具

直接添加到降价


为此有一个NPM模块:

它允许您将目录树表示为字符串或对象。将其与命令行一起使用将允许您将表示保存在txt文件中

例如:

$npm dree parse myDirectory--dest./generated--name树

很酷,这看起来很有用,谢谢!但是对于理论文件结构呢?如果这是目前唯一的解决方案,我想我可能只需要复制和粘贴我需要的字符。再次干杯。我喜欢这个解决方案。在降价时看起来整洁谢谢。但是,是否应该考虑使用Unicode字符?例如,旧浏览器存在已知问题、标记渲染不正确等。标记不应存在任何问题,它将出现在您的Jekyll模板和用户web浏览器上。与仅出于外观原因而使用不同符号的其他选择相比,此选择的另一个优势是差异较小(与
树的输出类似
)。使用此anwser时,树仅呈现为几行文本。在VSCode和VisualStudio中使用md插件进行测试。此外,在GitHub上,这不起作用。这已在Meta at上讨论过,因为您特别提到了jekyll,这没有绒毛,它可能适合billI使用的堆栈溢出不支持较新的三倍反勾语法;它将它们解释为单反勾号。单反勾号将代码标记为内联文本,仅在一行内;这就是为什么您的示例在每行之间都有白色条纹的原因。为了兼容标记多行代码的方式,请将文本缩进四个空格。虽然这样不支持三反勾号,但大多数其他MD实现都支持(就像Github/BitBucket)这是唯一的方法
root
+-- dir1
    +--file1
+-- dir2
    +-- file2
root
├── dir1
│   └── file1
└── dir2
    └── file2
tree -L 1 --charset=ascii
<pre>
.
&#8866; README.md
&#8866; docs
&#8866; e2e
&#8866; karma.conf.js
&#8866; node_modules
&#8866; package.json
&#8866; protractor.conf.js
&#8866; src
&#8866; tsconfig.json
&#8985; tslint.json
</pre>
There is an NPM module for this:

npm dree

It allows you to have a representation of a directory tree as a string or an object. Using it with the command line will allow you to save the representation in a txt file.

Example:

$ npm dree parse myDirectory --dest ./generated --name tree