Skip to content

Commit 9f74d9f

Browse files
twang2218agnivade
authored andcommitted
Add --markdown output option
Signed-off-by: Tao Wang <twang2218@gmail.com>
1 parent ba0ab27 commit 9f74d9f

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ To see tldr pages:
2929
- `tldr --list-all` show all available pages
3030
- `tldr --random` show a page at random
3131
- `tldr --random-example` show a single random example
32+
- `tldr --markdown` show the original markdown format page
3233

3334
The client caches a copy of all pages locally, in `~/.tldr`.
3435
There are more commands to control the local cache:

bin/autocompletion.zsh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ _arguments \
1212
'(- *)'{-1,--single-column}'[list one command per line (used with -l or -a)]' \
1313
'(- *)'{-r,--random}'[show a random command]' \
1414
'(- *)'{-e,--random-example}'[show a random example]' \
15+
'(- *)'{-m,--markdown}'[show the original markdown format page]' \
1516
'(-f --render)'{-f,--render}'[render a specific markdown file]:markdown file:_files -/' \
1617
'(-o --os)'{-o,--os}"[override operating system]:os:${oses}" \
1718
'--linux[override operating system with Linux]' \

bin/tldr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ program
1919
.option('-r, --random', 'Show a random command')
2020
.option('-e, --random-example', 'Show a random example')
2121
.option('-f, --render [file]', 'Render a specific markdown [file]')
22+
.option('-m, --markdown', 'Output in markdown format')
2223
.option('-o, --os [type]', 'Override the operating system [linux, osx, sunos]')
2324
.option('--linux', 'Override the operating system with Linux')
2425
.option('--osx', 'Override the operating system with OSX')

lib/tldr.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ exports.listAll = (singleColumn) => {
2424
});
2525
};
2626

27-
exports.get = (commands) => {
28-
printBestPage(commands.join('-'));
27+
exports.get = (commands, options) => {
28+
printBestPage(commands.join('-'), options);
2929
};
3030

3131
exports.random = () => {
@@ -97,6 +97,8 @@ function printPages(pages, singleColumn) {
9797
}
9898

9999
function printBestPage(command, options) {
100+
// TODO: replace with default parameter if Node v4 support dropped.
101+
options = options || {};
100102
/* eslint-disable */ // To allow not checking for err
101103
// Trying to get the page from cache first
102104
cache.getPage(command, (err, content) => {
@@ -132,6 +134,9 @@ function printBestPage(command, options) {
132134
}
133135

134136
function renderContent(content, options) {
137+
if (options.markdown) {
138+
return console.log(content);
139+
}
135140
let page = parser.parse(content);
136141
if (options && options.randomExample === true) {
137142
page.examples = [sample(page.examples)];

0 commit comments

Comments
 (0)