Is there a command line program to query markdown files? - command-line

I'm looking for a command-line tool that can extract the text from a subsection of a markdown file. There are many markdown parsers, but not really any user-facing query tools.
I know about jq for JSON files, and yq for YAML files, but I can't seem to find something similar for markdown files. The closest I've found is mkql which looks unmaintained. I could dig into awk and sed, but I was hoping for something more like jq and yq.
Any suggestions for CLI tools that can query markdown are welcomed.

Related

Parse files without extensions

I'm setting up the doxygen for a project. The module files have their language standard extension (.py), but the executable scripts do not. How can I get doxygen to read these correctly (Python in this case)? I tried
EXTENSION_MAPPING = ''=Python
But that looks for files named "blah.". I'm on a Unix system, so the concept of a file extension doesn't even exist here. And this is an existing project, so renaming all of the existing scripts is not an option.
Any ideas?
I modified doxygen to handle filenames without dots in them, and I'll submit the patch to the maintainers.
One simple trick is to make a symbolic link to the script that does have the right extension, and let doxygen then process the symbol link.
Say you have a python script called test, then do
ln -s test test.py
and then specify the test.py file in doxygen's configuration file
INPUT = test.py
According to doxygen's EXTENSION_MAPPING docs,
EXTENSION_MAPPING = ".no_extension=python"
should work.

How to make my Perl module's README file compatible with Github's Markdown display?

I've authored the README file in my Perl module in Markdown. Github treats this README file as plain text. I tried renaming the file to "README.md"—which looks great on Github, but is invisible to Perl tools that look for a file named "README."
Is there any way I can have both a README file, and have my Markdown formatting be interpreted correctly by Github?
The only option I could come up with was to have both a README and a README.md, but I'd prefer not to have to manually keep the two files in sync.
Thanks for your help.
Format your README in pod, rename it README.pod and then it works both places! Example
For my purposes I actually just generate my README.pod from the main pod by doing
$ podselect lib/My/Main/Module.pm > README.pod
One caveat, named external links don't work correctly L<GitHub|http://github.com> will unfortunately point to search.cpan.org looking for a GitHub module. I have tried to inform them of this glitch but it got me nowhere. Instead you can just use plain external links (i.e. GitHub: L<http://github.com>) and they work fine.
Good news, it appears that they have fixed this since the last time I checked!
Just a question, what parts of the Perl toolchain expect a README file? If you mean including it in your tarball, just be sure to add the file to your MANIFEST and it should get included.
Have you heard of POD? This is the standard documentation tool in Perl. POD is a simple text documentation format that actually lives in your code. One of the commands that come with perl is perldoc. You can use it to get the information of any Perl command. Try these:
$ perldoc File::Find
$ perldoc -f split
All Perl modules in CPAN are required to incorporate POD documentation. In fact, this is how the CPAN webpages themselves are built.
So, where am I going with this and how is this going to help you?
You should include POD documentation in your Perl program. Then, you can use the pod2text command to create your README for your Perl program:
$ pod2text myperl.pl > README
That handles half of your issue.
The other half is a bit more tricky. You need to install from CPAN the Pod::Markdown on your system. Then, you can run the pod2markdown command that comes with this module to create the markdown version of your file:
$ pod2markdown myperl.pl > README.md
The results:
Your documentation lives, as it should, in your Perl program.
Users can use the perldoc program to print out complete documentation of your program.
You can use the pod2text tool to create your README file.
You can use the pod2markdown tool to create your README.md file.
As a bonus, you can use the Pod::Usage module that comes with Perl to show the POD documentation (or bits and pieces of it) as help text that's displayed when a user runs your program with the -help parameter.
So, one place where your documentation lives, and you're using a couple of helper programs to create the files Github and whatever Perl tools you use need.
If you don't mind using Dist::Zilla you can pretty much do away with maintaining a README entirely. For example Dist::Zilla::Plugin::ReadmeFromPod can create your README file by extracting the Pod from your main module. This means never having to write a README again.
I've never tried it myself, but you could look at something like Dist::Zilla::Plugin::ReadmeMarkdownFromPod to create your README automatically in markdown.
This may not be the exact answer you're looking for, but I think using this sort of a tool can save you a lot of time as it allows you avoid repeating yourself in your documentation.
Another solution if you really want to distribute your module with a Markdown README, that doesn't involve Pod is to :
rename your README file to README.md
update the previous change in the MANIFEST file
I think it can be an interesting solution because more people know Markdown syntax than Pod one. As the aim of the README file is to be read by anyone, Markdown should be considered.
I was just looking for a solution for this problem and decided to use Dist::Zilla::Plugin::ReadmeAnyFromPod as it understands =attr and =method tags from Pod::Weaver.
The only option I could come up with was to have both a README and a
README.md, but I'd prefer not to have to manually keep the two files
in sync.
Then automatically keep them in sync?

From a kdiff3 file comparison, can I generate a diff in unified diff format?

I have a kdiff3 comparison in Windows, and I would like to save the comparison as a text file in unified diff format.
I realize this is kind of a strange question. Usually, people already have the text diff in hand, and want to see it graphically in kdiff3.
I'm using an ... unusual ... version control tool in Windows, and it can compare versions and display the comparison in kdiff3. However, it is decidedly unfriendly in generating Unix-friendly output, at least for non-ClearCase-ninjas like me.
What I would really, truly, love is to get the output of the comparison in a unified diff format, so I can use tools like patch or similar. I do not particularly love ClearCase, and I would be happy to leave it alone as much as possible.
Can kdiff3 take an existing comparison and export it to a unified diff format?
kdiff3 in Windows tends to come with the standard command-line diff utils as well -- look in your C:\Program Files*\KDiff3\bin folder; if diff.exe is there, you can use that (the standard diff -u file1 file2). (If it's not there, re-run the kdiff3 installer and select the "Utilities" option.)
If you're looking at some files in a running kdiff3 that was auto-launched from ClearCase, open a command prompt in the kdiff3 bin directory (or copy the contents of the bin directory into C:\Windows to make these commands work from anywhere) and do:
diff -u "<copy-pasted path of file A>" "<copy-pasted path of file B>"
where the paths for file A and file B come from your kdiff3 window (doesn't matter if they're temporary files; they'll exist as long as the kdiff3 window is open).
Don't bother with kdiff3. The command you're looking for is
cleartool diff --diff-format
Answered by John here: From a kdiff3 file comparison, can I generate a diff in unified diff format?

How do I extract translatable strings from a glade (Builder) file?

In command prompt I wrote:
C:\Users\Waqar Ali Khan\Documents\NetBeansProjects\MedicalEmergency>xgettext -d
MedicalEmergency -o LocaleStrings.pot main.cpp MedicalEmergency.glade
xgettext: Language "glade" is not supported. xgettext relies on expat.
This version was built without expat.
I tried to locate the libexpat and it was there with the xgettext.exe but still I'm getting this error, can any one guide me how do I extract translatable strings from a glade file?
I know i m doing right but this error is weird no where mentioned in any tutorial :(
I'm on Windows using Netbeans IDE with GTK+ - 2.0 and MinGW with MSYS.
It's best to use Intltool for extracting strings from Glade files. By coincidence, I am currently writing a tutorial on that. Look in the "Setting up Gettext" section.
Note that to use Intltool, you will have to download and build that somehow. I really hope it works on Windows, but I honestly have no idea.

How to find unique lines in a text file from command line?

I would like to know how to extract a list of unique lines from a text file.
Preferably through Cygwin.
sort -u file > new_file
Your question is somewhat unclear. If you want to eliminate all duplicate lines from a text file you can do something like this:
cat file.txt | sort | uniq
Since the original question referenced Cygwin, which is Windows specific, I'll mention that Luis' answer works just as well using the GNU utilities for Win32 sort. I use the GNU ports off a USB key when I'm working on a machine that I don't want to install Cygwin on, or downloading and installing Cygwin seems like too heavy a solution for the problem I'm trying to solve.