Last active
February 6, 2017 00:04
-
-
Save coldfix/2e22e1c549754493ea80068b52314226 to your computer and use it in GitHub Desktop.
primitive texdoc replacement for when you don't have latex documentation installed on disk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/zsh | |
prefix=$HOME/.texdoc | |
pkg=$1 | |
doc=$(hrefbytext http://ctan.org/pkg/$pkg 'Pack­age doc­u­men­ta­tion') && | |
mkdir -p $prefix | |
cache=$prefix/$(basename $doc) && ( | |
if [[ ! -e $cache ]]; then | |
wget $doc -O $cache | |
fi | |
) && | |
evince $cache |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# encoding: utf-8 | |
""" | |
Get link by text content. | |
Usage: | |
hrefbytext URL TEXT | |
Example: | |
hrefbytext "http://ctan.org/pkg/subcaption" \ | |
"Pack­age doc­u­men­ta­tion" | |
""" | |
import sys | |
from lxml.html import parse, fromstring | |
def main(args): | |
url = args[0] | |
doc = parse(url).getroot() | |
text = fromstring(args[1]).text_content() # replace HTML entities | |
for link in doc.cssselect('a'): | |
if link.text_content() == text: | |
print(link.get('href')) | |
if __name__ == '__main__': | |
main(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment