마크 다운 및 여러 파일 포함
포함 파일과 같은 다른 파일을 참조 할 수있는 마크 다운 포크가 있습니까? 특히, 자주 호출하지만 항상 그렇지는 않지만 (이 B.md라고 부르는) 링크가있는 별도의 마크 다운 파일을 만들고 싶습니다 .md 파일에서 참조로 링크 할 때 (A.md), 나는 현재 파일의 끝 (A.md)이 아닌 다른 파일 (B.md)에서 링크를 가져 오는 것이 좋습니다.
짧은 대답은 '아니요'입니다. 긴 대답은 그렇습니다. :-)
마크 다운은 사람들이 간단한 HTML 마크 업으로 쉽게 변환 할 수있는 간단하고 읽기 쉬운 텍스트를 작성할 수 있도록 설계되었습니다. 실제로 문서 레이아웃을 수행하지는 않습니다. 예를 들어 이미지를 오른쪽이나 왼쪽으로 정렬하는 실제 방법은 없습니다. 귀하의 질문에 관해서는, 모든 버전의 마크 다운 (내가 아는 한)에서 한 파일에서 다른 파일로의 단일 링크를 포함시키는 마크 다운 명령이 없습니다.
이 기능에 가장 가까운 것은 Pandoc 입니다. Pandoc를 사용하면 변환의 일부로 파일을 병합 할 수 있으므로 여러 파일을 단일 출력으로 쉽게 렌더링 할 수 있습니다. 예를 들어, 책을 작성하는 경우 다음과 같은 장이있을 수 있습니다.
01_preface.md
02_introduction.md
03_why_markdown_is_useful.md
04_limitations_of_markdown.md
05_conclusions.md
동일한 디렉토리에서이 명령을 실행하여 병합 할 수 있습니다.
pandoc *.md > markdown_book.html
pandoc은 번역하기 전에 모든 파일을 병합하므로 다음과 같이 마지막 파일에 링크를 포함시킬 수 있습니다.
01_preface.md
02_introduction.md
03_why_markdown_is_useful.md
04_limitations_of_markdown.md
05_conclusions.md
06_links.md
그래서 당신의 일부는 01_preface.md
다음과 같이 보일 수 있습니다 :
I always wanted to write a book with [markdown][mkdnlink].
그리고 당신의 일부는 02_introduction.md
다음과 같이 보일 수 있습니다 :
Let's start digging into [the best text-based syntax][mkdnlink] available.
마지막 파일에 다음 줄이 포함되어있는 한 :
[mkdnlink]: http://daringfireball.net/projects/markdown
... 이전에 사용 된 동일한 명령은 병합과 변환을 수행하면서 해당 링크를 전체에 포함시킵니다. 해당 파일의 시작 부분에 빈 줄을 두어 두십시오. pandoc 설명서 는이 방법을 병합 파일 사이에 빈 줄을 추가 있다고하지만, 이것은 빈 줄없이 나를 위해 일을하지 않았다.
cat
입력 파일을 파이핑하기 전에 명령을 사용하여 입력 파일을 연결하면 여러 입력 파일이 들어오는 markdown_py
것과 동일한 효과 를 얻을 수 있다고 언급합니다 pandoc
.
cat *.md | markdown_py > youroutputname.html
내 Mac에서 Markdown의 Python 버전에 대한 위 의 pandoc 예제 와 거의 동일하게 작동합니다 .
실제로 MarkdownPP ( MarkdownPP )를 사용할 수 있습니다 . 다른 답변의 가상의 책 예제를 사용 .mdpp
하여 장을 나타내는 파일 을 만듭니다 . .mdpp
파일은 다음 사용할 수있는 !INCLUDE "path/to/file.mdpp"
재귀 최종 출력에 참조 된 파일의 내용으로 지시를 교체하여 작동 지침을.
chapters/preface.mdpp
chapters/introduction.mdpp
chapters/why_markdown_is_useful.mdpp
chapters/limitations_of_markdown.mdpp
chapters/conclusions.mdpp
그런 index.mdpp
다음 다음을 포함 하는 것이 필요합니다 .
!INCLUDE "chapters/preface.mdpp"
!INCLUDE "chapters/introduction.mdpp"
!INCLUDE "chapters/why_markdown_is_useful.mdpp"
!INCLUDE "chapters/limitations_of_markdown.mdpp"
!INCLUDE "chapters/conclusions.mdpp"
책을 렌더링하려면 다음에서 전처리기를 실행하면됩니다 index.mdpp
.
$ markdown-pp.py index.mdpp mybook.md
상기 볼 잊지 마세요 readme.mdpp
에 MarkdownPP의 전처리의 박람회가 큰 문서 프로젝트에 적합한 기능에 대한 저장소.
내 해결책은 m4를 사용하는 것입니다. 대부분의 플랫폼에서 지원되며 binutils 패키지에 포함되어 있습니다.
먼저 changequote()
파일에 매크로 를 포함 시켜 인용 문자를 원하는대로 변경하십시오 (기본값은` '). 파일이 처리되면 매크로가 제거됩니다.
changequote(`{{', `}}')
include({{other_file}})
명령 행에서 :
m4 -I./dir_containing_other_file/ input.md > _tmp.md
pandoc -o output.html _tmp.md
최근에 markdown-include 라는 노드에 다음과 같이 C 스타일 구문으로 markdown 파일을 포함시킬 수있는 것을 작성했습니다.
#include "my-file.md"
I believe this aligns nicely with the question you're asking. I know this an old one, but I wanted to update it at least.
You can include this in any markdown file you wish. That file can also have more includes and markdown-include will make an internal link and do all of the work for you.
You can download it via npm
npm install -g markdown-include
Multimarkdown has this natively. It calls it file transclusion:
{{some_other_file.txt}}
is all it takes. Weird name, but ticks all the boxes.
In fact you can use \input{filename}
and \include{filename}
which are latex commands, directly in Pandoc
, because it supports nearly all html
and latex
syntax.
But beware, the included file will be treated as latex
file. But you can compile your markdown
to latex
with Pandox
easily.
I use a includes.txt
file with all my files in the right order the I execute pandoc like this:
pandoc -s $(cat includes.txt) --quiet -f markdown -t html5 --css pandoc.css -o index.html
Works like a charm!
I think we better adopt a new file inclusion syntax (so won't mess up with code blocks, I think the C style inclusion is totally wrong), and I wrote a small tool in Perl, naming cat.pl
, because it works like cat
(cat a.txt b.txt c.txt
will merge three files), but it merges files in depth, not in width. How to use?
$ perl cat.pl <your file>
The syntax in detail is:
- recursive include files:
@include <-=path=
- just include one:
%include <-=path=
It can properly handle file inclusion loops (if a.txt <- b.txt, b.txt <- a.txt, then what you expect?).
Example:
a.txt:
a.txt
a <- b
@include <-=b.txt=
a.end
b.txt:
b.txt
b <- a
@include <-=a.txt=
b.end
perl cat.pl a.txt > c.txt
, c.txt:
a.txt
a <- b
b.txt
b <- a
a.txt
a <- b
@include <-=b.txt= (note:won't include, because it will lead to infinite loop.)
a.end
b.end
a.end
More examples at https://github.com/district10/cat/blob/master/tutorial_cat.pl_.md.
I also wrote a Java version having an identical effect (not the same, but close).
Asciidoc (http://www.methods.co.nz/asciidoc/) is actually a markdown on steroids. Overall, Asciidoc and Markdown will look very similar and it is rather easy to switch. A huge benefit of Asciidoc over markdown is that it supports includes already, for other Asciidoc files but also for any format you like. You can even partly include files based on line numbers or tags inside your included files.
Including other files is really a life saver when you write docs.
You can for instance have an asciidoc file with such content:
// [source,perl]
// ----
// include::script.pl[]
// ----
and maintain your sample in script.pl
And I am sure you will wonder so yes, Github also supports asciidoc.
I'm actually surprised that no one in this page has offered any HTML solutions. As far I have understood MarkDown files can include wide portion (if not all) of HTML tags. So follow these steps:
From here: put your MarkDown files in
<span style="display:block"> ... </span>
tags to be sure they will be rendered as markdown. You have a whole lot of other style properties you can add. The one I like is thetext-align:justify
.From here: Include the files in your main file using the
<iframe src="/path/to/file.md" seamless></iframe>
P.S.1. this solution does not work on all MarkDown engines / renders. For example Typora did render the files correctly but Visual Studio Code didn't. It would be great if others could share their experience with other platforms. Specially I would like to hear about GitHub and GitLab ...
P.S.2. On further investigation there seems to be major incompatibility issues leading to this not being properly rendered on many platforms, including Typora, GitHub and Visual Studio code. Please do not use this till I resolve them. I will not delete the answer just for the sake of discussion and if maybe you can share your opinions.
P.S.3. To further investigate this issue I have asked this questions here on StackOverflow and here on Reddit.
P.S.4. After some through study, I came to the conclusion that for the moment AsciiDoc is a better option for documentation. It comes with built-in include functionality, it is rendered by GitHub, and major code editors like Atom and vscode have extensions for live preview. One can use Pandoc or other tools to automatically convert existing MarkDown Code to AsciiDoc with minor changes.
P.S.5. Another lightweight markup language with built-in include functionality is reStructuredText
. It comes with .. include:: inclusion.txt
syntax by standard. There is ReText editor with live preview as well.
I use Marked 2 on Mac OS X. It supports the following syntax for including other files.
<<[chapters/chapter1.md]
<<[chapters/chapter2.md]
<<[chapters/chapter3.md]
<<[chapters/chapter4.md]
Sadly, you can't feed that to pandoc as it doesn't understand the syntax. However, writing a script to strip the syntax out to construct a pandoc command line is easy enough.
IMHO, You can get your result by concatenating your input *.md files like:
$ pandoc -s -o outputDoc.pdf inputDoc1.md inputDoc2.md outputDoc3.md
참고URL : https://stackoverflow.com/questions/4779582/markdown-and-including-multiple-files
'development' 카테고리의 다른 글
이 루비 코드에서 (단항) * 연산자는 무엇을합니까? (0) | 2020.05.28 |
---|---|
중복 Mongo ObjectId가 두 개의 다른 컬렉션에서 생성 될 가능성이 있습니까? (0) | 2020.05.28 |
Android 앱은 제거 및 재설치 후 데이터를 기억합니다 (0) | 2020.05.28 |
Vue.js의 URL에서 쿼리 매개 변수를 얻으려면 어떻게해야합니까? (0) | 2020.05.28 |
선분의 법선 벡터는 어떻게 계산합니까? (0) | 2020.05.28 |