Skip to content

Commit ccfae8c

Browse files
committed
Added .pull command
1 parent a97829d commit ccfae8c

File tree

3 files changed

+90
-19
lines changed

3 files changed

+90
-19
lines changed

README.md

+62-13
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,39 @@
22
<center>
33
<img src="https://github.com/imatix/gitdown/raw/master/images/README_1.png" alt="1">
44
</center>
5+
/----------------------------------------------------------\+\
6+
|/---------------------------------------------------------/||
7+
|| /--+ +------+ +------\ /----\/+ +\ +\ +\ /------\ ||
8+
|| \-\| \--\/--/ |+----\| |/---/|| || || || |/----\| ||
9+
|| || || || || || || || || || || || ||
10+
|| +---\ || || || || || || || || || || || ||
11+
|| \--\| || || \/ || || || || || || || || ||
12+
|| || || || /-----/| |\----/| |\--/\--/| || || ||
13+
|| || \/ \/ +------/ \------/ \--------/ +/ \+ ||
14+
|\-----/|+--------------------------------------------------/|
15+
\-------/+---------------------------------------------------/
16+
[/diagram]
517

618
<A name="toc1-17" title="Welcome To Gitdown" />
719
Welcome To Gitdown
820
==================
921

1022
Gitdown is a simple tool for writing documentation hosted on a github repository. It uses [ditaa][] to convert ascii diagrams into images, and produces [markdown][] documents that can be uploaded to your repository along with code. I made Gitdown so that we could write technical white papers and user guides as plain text (including diagrams) and publish them with a single "git push" command. Gitdown is a simpler version of the tool we use to maintain the [ØMQ][zeromq] [Guide][zguide].
1123

12-
Gitdown is written and maintained by Pieter Hintjens. Please use the issue [tracker][] for all comments and errata. This document was published on Thursday February, 2011 at 12:07:19, and generated by the magic of Gitdown from README.txt.
24+
Gitdown is written and maintained by Pieter Hintjens. Please use the issue [tracker][] for all comments and errata. This document was published on Thursday March, 2011 at 20:11:14, and generated by the magic of Gitdown from README.txt.
1325

14-
This is version 2010.10.11 of Gitdown. Changelog:
26+
This is version 2011.03.24 of Gitdown. Changelog:
1527

28+
* 2010.03.24: added .pull command to include chunks from other files.
1629
* 2010.10.11: don't do symbol substitution in code blocks.
1730
* 2010.10.09: added .toc token to generate table of contents.
1831

19-
<A name="toc2-30" title="Contents" />
32+
<A name="toc2-31" title="Contents" />
2033
Contents
2134
--------
2235

23-
&emsp;<a href="#toc2-36">License</a>
24-
&emsp;<a href="#toc2-45">Installation and Use</a>
25-
&emsp;<a href="#toc2-70">How it Works</a>
26-
&emsp;<a href="#toc2-125">Gitdown Syntax Summary</a>
27-
&emsp;<a href="#toc2-182">Markdown Syntax Summary</a>
2836

29-
<A name="toc2-36" title="License" />
37+
<A name="toc2-37" title="License" />
3038
License
3139
-------
3240

@@ -35,7 +43,7 @@ Copyright (c) 1996-2011 iMatix Corporation
3543

3644
This is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
3745

38-
<A name="toc2-45" title="Installation and Use" />
46+
<A name="toc2-46" title="Installation and Use" />
3947
Installation and Use
4048
--------------------
4149

@@ -60,7 +68,7 @@ To use Gitdown, edit a text document much like this README.txt. Then:
6068

6169
The images directory holds images for all documents in the current directory. You can write documents anywhere on the git tree but if they are not at the root you must tell Gitdown how to create a full image path by setting the SUBDIR symbol (see below).
6270

63-
<A name="toc2-70" title="How it Works" />
71+
<A name="toc2-71" title="How it Works" />
6472
How it Works
6573
------------
6674

@@ -71,6 +79,44 @@ The Gitdown workflow is:
7179
<center>
7280
<img src="https://github.com/imatix/gitdown/raw/master/images/README_2.png" alt="2">
7381
</center>
82+
+-------------------+
83+
| me.txt |
84+
+-------------------+
85+
| Text file in +---> Saved in git as source
86+
| Gitdown format |
87+
+---------+---------+
88+
|
89+
|
90+
+----------------------------+
91+
| |
92+
v v
93+
+---------+---------+ +---------+---------+
94+
| me.md | | images.html |
95+
+-------------------+ +-------------------+
96+
| Markdown output | | Temporary HTML |
97+
| cFDA| | to feed Ditaa |
98+
+---------+---------+ +---------+---------+
99+
| |
100+
| |
101+
| v
102+
| +---------+---------+
103+
: | |
104+
References | Ditaa |
105+
| | {o}|
106+
| +---------+---------+
107+
| |
108+
| |
109+
| v
110+
| +---------+---------+
111+
| | images/me_nnn.png |
112+
+----------------->+-------------------+
113+
| Image files |
114+
| cFDA|
115+
+-------------------+
116+
117+
118+
Figure # - Gitdown workflow
119+
[/diagram]
74120

75121
1. You edit a text file that contains text and diagrams in a single document.
76122
2. You process this document with Gitdown to give a Markdown document plus a number of images in an images subdirectory.
@@ -79,7 +125,7 @@ The Gitdown workflow is:
79125

80126
This README acts as an example.
81127

82-
<A name="toc2-125" title="Gitdown Syntax Summary" />
128+
<A name="toc2-126" title="Gitdown Syntax Summary" />
83129
Gitdown Syntax Summary
84130
---------------------
85131

@@ -92,6 +138,7 @@ Gitdown is a pre-processor that adds these syntax elements on top of Markdown:
92138
.set name=value Sets Gitdown symbol
93139
.sub oldval=newval Replaces oldval by newval in every line
94140
.toc [top] Insert table of contents
141+
.pull srcfile@tag[,opts] Pull a chunk of text from sourcefile
95142
.end Everything past this is ignored
96143

97144
$\(xxx) Value of variable, anywhere in text
@@ -124,6 +171,8 @@ Gitdown is a pre-processor that adds these syntax elements on top of Markdown:
124171

125172
The top argument for .toc tells it the top header level in the text. Lower levels are shown horizontally. E.g. this file has level 2 headers in the text and uses `.toc 1` to get these laid-out on a single row.
126173

174+
The opts argument for .pull can be: 'code' to indicate the results should be indented 4 spaces. An opts of 'left' removes any left margin. A chunk of text is identified by '@tag' anywhere in the line before the chunk, and any other tag signalling the end. '@end' can be used to close any chunk. Tag names must be alphanumeric.
175+
127176
These symbols have special meaning:
128177

129178
* GIT defines the root HTTP URL of the git repository.
@@ -136,7 +185,7 @@ These symbols are predefined by gitdown for you:
136185
* SELF specifies the input file name without extension.
137186
* OUTPUT specifies the current output file name,
138187

139-
<A name="toc2-182" title="Markdown Syntax Summary" />
188+
<A name="toc2-186" title="Markdown Syntax Summary" />
140189
Markdown Syntax Summary
141190
-----------------------
142191

README.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ Gitdown is a simple tool for writing documentation hosted on a github repository
2121

2222
Gitdown is written and maintained by Pieter Hintjens. Please use the issue [tracker][] for all comments and errata. This document was published on &date("dddd mmmm, yyyy") at &time(), and generated by the magic of Gitdown from $(INPUT).
2323

24-
This is version 2010.10.11 of Gitdown. Changelog:
24+
This is version 2011.03.24 of Gitdown. Changelog:
2525

26+
* 2010.03.24: added .pull command to include chunks from other files.
2627
* 2010.10.11: don't do symbol substitution in code blocks.
2728
* 2010.10.09: added .toc token to generate table of contents.
2829

@@ -129,6 +130,7 @@ Gitdown is a pre-processor that adds these syntax elements on top of Markdown:
129130
.set name=value Sets Gitdown symbol
130131
.sub oldval=newval Replaces oldval by newval in every line
131132
.toc [top] Insert table of contents
133+
.pull srcfile@tag[,opts] Pull a chunk of text from sourcefile
132134
.end Everything past this is ignored
133135

134136
$\(xxx) Value of variable, anywhere in text
@@ -161,6 +163,8 @@ Gitdown is a pre-processor that adds these syntax elements on top of Markdown:
161163

162164
The top argument for .toc tells it the top header level in the text. Lower levels are shown horizontally. E.g. this file has level 2 headers in the text and uses `.toc 1` to get these laid-out on a single row.
163165

166+
The opts argument for .pull can be: 'code' to indicate the results should be indented 4 spaces. An opts of 'left' removes any left margin. A chunk of text is identified by '@tag' anywhere in the line before the chunk, and any other tag signalling the end. '@end' can be used to close any chunk. Tag names must be alphanumeric.
167+
164168
These symbols have special meaning:
165169

166170
* GIT defines the root HTTP URL of the git repository.

bin/gitdown

+23-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# See README.txt for details.
55
#
6-
# Copyright (c) 1996-2010 iMatix Corporation
6+
# Copyright (c) 1996-2011 iMatix Corporation
77
#
88
# This is free software; you can redistribute it and/or modify it under the
99
# terms of the GNU General Public License as published by the Free Software
@@ -28,7 +28,7 @@ push(@INC, $path);
2828
# Uses the Perl SFL modules from htmlpp
2929
require 'sflcvdp.pl'; # SFL date picture formatting
3030

31-
$version = "2010.10.09";
31+
$version = "2011.03.24";
3232

3333
# Parse and validate provided filename
3434
die "Syntax: gitdoc textfilename\n"
@@ -65,9 +65,8 @@ $symbols {"PREBRANCH"} = "raw";
6565
$symbols {"BRANCH"} = "master";
6666

6767
$imgpath = "";
68-
$line = 0;
69-
while ($line < @input) {
70-
$_ = $input [$line++];
68+
69+
foreach (@input) {
7170
if (/^\./) {
7271
# Process directive
7372
if (/^\.set\s+(\w+)=(.*)\s*/) {
@@ -120,6 +119,25 @@ while ($line < @input) {
120119
elsif (/^\.\-/) {
121120
# Comment, ignore
122121
}
122+
elsif (/^\.pull (.*)(@[a-zA-Z0-9]+)(,(.*)\s*)?/) {
123+
$source = $1;
124+
$tag = $2;
125+
$opts = $4;
126+
die "Can't read $source: $!"
127+
unless open (SOURCE, $source);
128+
while (<SOURCE>) {
129+
if (/$tag/) {
130+
while (<SOURCE>) {
131+
last if /@[a-zA-Z0-9]+/;
132+
chop;
133+
$_ = " $_" if ($opts eq "code");
134+
s/^ // if ($opts eq "left");
135+
writeln ($_);
136+
}
137+
}
138+
}
139+
close (SOURCE);
140+
}
123141
elsif (/^\.end/) {
124142
writeln ("(More coming soon...)");
125143
$EOD = 1; # Stop output here

0 commit comments

Comments
 (0)