Skip to content
Myr

Remove ruby dependency from manpage build

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by William Langford · committed by Nico Williams · parent c1f1185 · Browse files · 5 files+302 added−36 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+302 added−36 removed

  • other:+302 added−36 removed

5 files+302 added−36 removed

modified:docs/content/manual/manual.yml+31 added-31 removed
170 unmodified lines
171 "\u03bc"). Using this option, you can force jq to produce pure172 ASCII output with every non-ASCII character replaced with the173 equivalent escape sequence.174175 * `--unbuffered`175 * `--unbuffered`:176177 Flush the output after each JSON object is printed (useful if178 you're piping a slow data source into jq and piping jq's179 output elsewhere).
477 unmodified lines
657658 - **Strings** are added by being joined into a larger string.659660 - **Objects** are added by merging, that is, inserting all661 the key-value pairs from both objects into a single662 combined object. If both objects contain a value for the663 same key, the object on the right of the `+` wins. (For664 recursive merge use the `*` operator.)661 the key-value pairs from both objects into a single662 combined object. If both objects contain a value for the663 same key, the object on the right of the `+` wins. (For664 recursive merge use the `*` operator.)665666 `null` can be added to any value, and returns the other667 value unchanged.668
1305 unmodified lines
1974 body: |19751976 jq provides a few SQL-style operators.19771978 * INDEX(stream; index_expression):1978 * INDEX(stream; index_expression):19791980 This builtin produces an object whose keys are computed by1981 the given index expression applied to each value from the1982 given stream.1980 This builtin produces an object whose keys are computed by1981 the given index expression applied to each value from the1982 given stream.19831984 * JOIN($idx; stream; idx_expr; join_expr):1984 * JOIN($idx; stream; idx_expr; join_expr):19851986 This builtin joins the values from the given stream to the1987 given index. The index's keys are computed by applying the1988 given index expression to each value from the given stream.1989 An array of the value in the stream and the corresponding1990 value from the index is fed to the given join expression to1991 produce each result.1986 This builtin joins the values from the given stream to the1987 given index. The index's keys are computed by applying the1988 given index expression to each value from the given stream.1989 An array of the value in the stream and the corresponding1990 value from the index is fed to the given join expression to1991 produce each result.19921993 * JOIN($idx; stream; idx_expr):1993 * JOIN($idx; stream; idx_expr):19941995 Same as `JOIN($idx; stream; idx_expr; .)`.1995 Same as `JOIN($idx; stream; idx_expr; .)`.19961997 * JOIN($idx; idx_expr):1997 * JOIN($idx; idx_expr):19981999 This builtin joins the input `.` to the given index, applying2000 the given index expression to `.` to compute the index key.2001 The join operation is as described above.1999 This builtin joins the input `.` to the given index, applying2000 the given index expression to `.` to compute the index key.2001 The join operation is as described above.20022003 * IN(s):2003 * IN(s):20042005 This builtin outputs `true` if `.` appears in the given2006 stream, otherwise it outputs `false`.2005 This builtin outputs `true` if `.` appears in the given2006 stream, otherwise it outputs `false`.20072008 * IN(source; s):2008 * IN(source; s):20092010 This builtin outputs `true` if any value in the source stream2011 appears in the second stream, otherwise it outputs `false`.2010 This builtin outputs `true` if any value in the source stream2011 appears in the second stream, otherwise it outputs `false`.20122013 - title: "`builtins`"2014 body: |2015
626 unmodified lines
2642 to be able to create recursive functions.26432644 For example, in the following expression there is a binding2645 which is visible "to the right" of it, `... | .*3 as2646 $times_three | [. + $times_three] | ...`, but not "to the2646 $times_three | [. + $times_three] | ...`, but not "to the2647 left". Consider this expression now, `... | (.*3 as2648 $times_three | [.+ $times_three]) | ...`: here the binding2648 $times_three | [. + $times_three]) | ...`: here the binding2649 `$times_three` is _not_ visible past the closing parenthesis.26502651 - title: Reduce2652 body: |
214 unmodified lines
2867 be interleaved with each other.28682869 Two builtins provide minimal output capabilities, `debug`, and2870 `stderr`. (Recall that a jq program's output values are always2871 output as JSON texts on `stdout`.) The `debug` builtin can have2871 output as JSON texts on `stdout`.) The `debug` builtin can have2872 application-specific behavior, such as for executables that use2873 the libjq C API but aren't the jq executable itself. The `stderr`2874 builtin outputs its input in raw mode to stder with no additional2875 decoration, not even a newline.
429 unmodified lines
modified:docs/build_manpage.py+234 added-1 removed
1#!/usr/bin/env python32print("Manpage build not yet supported")2from datetime import date3from io import StringIO4from lxml import etree5import markdown6from markdown.extensions import Extension7import re8import sys9import yaml1011# Prevent our markdown parser from trying to help by interpreting things in angle brackets as HTML tags.12class EscapeHtml(Extension):13 def extendMarkdown(self, md, md_globals):14 del md.preprocessors['html_block']15 del md.inlinePatterns['html']1617class RoffWalker(object):18 def __init__(self, tree, output=sys.stdout):19 self.tree = tree20 self.target = output21 self.f = StringIO()2223 def walk(self):24 self._walk(self.tree, parent_tag=None)25 # We don't want to start lines with \. because that can confuse man26 # For lines that start with \., we need to prefix them with \& so it27 # knows not to treat that line as a directive28 data = re.sub(r'^\\\.', r'\&.', self.f.getvalue(), flags=re.MULTILINE)29 self.target.write(data)3031 def _ul_is_special(self, root):32 if len(root) != 1:33 return False34 child = root[0]35 if child.tag != 'li':36 return False37 msg = ''.join(child.itertext()).strip()38 return msg.endswith(':')3940 def _walk_child(self, root):41 if len(root) > 0:42 self._walk(root[0], parent_tag=root.tag)4344 def _write_element(self, root, ensure_newline=True):45 if root.text is not None:46 text = self._sanitize(root.text)47 self.__write_raw(text)48 self._walk_child(root)49 self._write_tail(root, ensure_newline=ensure_newline)5051 def _write_tail(self, root, ensure_newline=False, inline=False):52 if root.tail is not None:53 if inline or root.tail != '\n':54 text = self._sanitize(root.tail)55 if text.endswith('\n'):56 ensure_newline = False57 self.__write_raw(text)58 if ensure_newline:59 self.__write_raw('\n')6061 def _walk(self, root, parent_tag=None):62 last_tag = None63 while root is not None:64 if root.tag == 'h1':65 self.__write_cmd('.TH "JQ" "1" "{}" "" ""'.format(date.today().strftime('%B %Y')))66 self.__write_cmd('.SH "NAME"')67 # TODO: properly parse this68 self.__write_raw(r'\fBjq\fR \- Command\-line JSON processor' + "\n")6970 elif root.tag == 'h2':71 self.__write_cmd('.SH "{}"'.format(''.join(root.itertext()).strip()))7273 elif root.tag == 'h3':74 text = ''.join(root.itertext()).strip()75 self.__write_cmd('.SS "{}"'.format(self._h3_sanitize(text)))7677 elif root.tag == 'p':78 if last_tag not in ['h2', 'h3'] and parent_tag not in ['li']:79 self.__write_cmd('.P')80 self._write_element(root, ensure_newline=(parent_tag != 'li'))8182 elif root.tag == 'ul':83 if self._ul_is_special(root):84 li = root[0]85 self.__write_cmd('.TP')86 self._write_element(li)87 next = root.getnext()88 while next is not None and next.tag == 'p':89 if next.getnext() is not None and next.getnext().tag == 'pre':90 # we don't want to .IP these, because it'll look funny with the code indent91 break92 self.__write_cmd('.IP')93 self._write_element(next)94 root = next95 next = root.getnext()96 else:97 self._walk_child(root)98 self._write_tail(root)99 # A pre tag after the end of a list doesn't want two of the indentation commands100 if root.getnext() is None or root.getnext().tag != 'pre':101 self.__write_cmd('.IP "" 0')102103 elif root.tag == 'li':104 self.__write_cmd(r'.IP "\(bu" 4')105 if root.text is not None and root.text.strip() != '':106 text = self._sanitize(root.text)107 self.__write_raw(text)108 self._walk_child(root)109 self._write_tail(root, ensure_newline=True)110111 elif root.tag == 'strong':112 if root.text is not None:113 text = self._sanitize(root.text)114 self.__write_raw('\\fB{}\\fR'.format(text))115116 self._write_tail(root, inline=True)117118 elif root.tag == 'em':119 if root.text is not None:120 text = self._sanitize(root.text)121 self.__write_raw('\\fI{}\\fR'.format(text))122 self._write_tail(root, inline=True)123124 elif root.tag == 'code':125 if root.text is not None:126 text = self._code_sanitize(root.text)127 self.__write_raw('\\fB{}\\fR'.format(text))128 self._write_tail(root, inline=True)129130 elif root.tag == 'pre':131 self.__write_cmd('.IP "" 4')132 self.__write_cmd('.nf\n') # extra newline for spacing reasons133 next = root134 first = True135 while next is not None and next.tag == 'pre':136 if not first:137 self.__write_raw('\n')138 text = ''.join(next.itertext(with_tail=False))139 self.__write_raw(self._pre_sanitize(text))140 first = False141 root = next142 next = next.getnext()143 self.__write_cmd('.fi')144 self.__write_cmd('.IP "" 0')145146 else:147 self._walk_child(root)148149 last_tag = root.tag150 root = root.getnext()151152 def _base_sanitize(self, text):153 text = re.sub(r'\\', r'\\e', text)154 text = re.sub(r'\.', r'\\.', text)155 text = re.sub("'", r"\'", text)156 text = re.sub('-', r'\-', text)157 return text158159 def _pre_sanitize(self, text):160 return self._base_sanitize(text)161162 def _code_sanitize(self, text):163 text = self._base_sanitize(text)164 text = re.sub(r'\s', ' ', text)165 return text166167 def _h3_sanitize(self, text):168 text = self._base_sanitize(text)169 text = re.sub(' \n|\n ', ' ', text)170 text = re.sub('\n', ' ', text)171 return text172173 def _sanitize(self, text):174 text = self._base_sanitize(text)175 text = re.sub(r'<([^>]+)>', r'\\fI\1\\fR', text)176 text = re.sub(r' +', ' ', text)177 text = re.sub('\n', ' ', text)178 return text179180 def __write_cmd(self, dat):181 print('.', dat, sep='\n', file=self.f)182 pass183184 def __write_raw(self, dat):185 print(dat, sep='', end='', file=self.f)186 pass187188def load_yml_file(fn):189 with open(fn) as f:190 return yaml.load(f)191192def dedent_body(body):193 lines = [re.sub(r'^ (\S)', r'\1', l) for l in body.split('\n')]194 return '\n'.join(lines)195196def convert_manual_to_markdown():197 f = StringIO()198 manual = load_yml_file("content/manual/manual.yml")199 f.write(manual.get('manpage_intro', '\n'))200 f.write(dedent_body(manual.get('body', '\n')))201 for section in manual.get('sections', []):202 f.write('## {}\n'.format(section.get('title', '').upper()))203 f.write(dedent_body(section.get('body', '\n')))204 f.write('\n')205 for entry in section.get('entries', []):206 f.write('### {}\n'.format(entry.get('title', '')))207 f.write(dedent_body(entry.get('body', '\n')))208 f.write('\n')209 if entry.get('examples') is not None:210 f.write("~~~~\n")211 first = True212 for example in entry.get('examples'):213 if not first:214 f.write('\n')215 f.write("jq '{}'\n".format(example.get('program', '')))216 f.write(" {}\n".format(example.get('input', '')))217 output = [str(x) for x in example.get('output', [])]218 f.write("=> {}\n".format(', '.join(output)))219 first = False220 f.write("~~~~\n")221 f.write('\n')222 f.write(manual.get('manpage_epilogue', ''))223 return f.getvalue()224225# Convert manual.yml to our special markdown format226markdown_data = convert_manual_to_markdown()227228# Convert markdown to html229html_data = markdown.markdown(markdown_data, extensions=[EscapeHtml(), 'fenced_code'])230231# Parse the html into a tree so we can walk it232tr = etree.HTML(html_data, etree.HTMLParser())233234# Convert the markdown to ROFF235RoffWalker(tr).walk()
modified:docs/Pipfile+2 added-1 removed
6 unmodified lines
78[packages]9jinja2 = "*"10pyyaml = "*"11markdown = "*"11markdown = "*"12lxml = "*"
modified:docs/Pipfile.lock+33 added-1 removed
1{2 "_meta": {3 "hash": {4 "sha256": "6cffc39e0d43a6d7c78f39636c7ed1b047f7b819b158213a96d7cbfefd6524d7"4 "sha256": "16a9ef323592a417142c30be17e58c3cf36dc2bfdbf4757106a796b22262a1ce"5 },6 "pipfile-spec": 6,7 "requires": {},8 "sources": [
12 unmodified lines
21 ],22 "index": "pypi",23 "version": "==2.10"24 },25 "lxml": {26 "hashes": [27 "sha256:0537eee4902e8bf4f41bfee8133f7edf96533dd175930a12086d6a40d62376b2",28 "sha256:0562ec748abd230ab87d73384e08fa784f9b9cee89e28696087d2d22c052cc27",29 "sha256:09e91831e749fbf0f24608694e4573be0ef51430229450c39c83176cc2e2d353",30 "sha256:1ae4c0722fc70c0d4fba43ae33c2885f705e96dce1db41f75ae14a2d2749b428",31 "sha256:1c630c083d782cbaf1f7f37f6cac87bda9cff643cf2803a5f180f30d97955cef",32 "sha256:2fe74e3836bd8c0fa7467ffae05545233c7f37de1eb765cacfda15ad20c6574a",33 "sha256:37af783c2667ead34a811037bda56a0b142ac8438f7ed29ae93f82ddb812fbd6",34 "sha256:3f2d9eafbb0b24a33f56acd16f39fc935756524dcb3172892721c54713964c70",35 "sha256:47d8365a8ef14097aa4c65730689be51851b4ade677285a3b2daa03b37893e26",36 "sha256:510e904079bc56ea784677348e151e1156040dbfb736f1d8ea4b9e6d0ab2d9f4",37 "sha256:58d0851da422bba31c7f652a7e9335313cf94a641aa6d73b8f3c67602f75b593",38 "sha256:7940d5c2185ffb989203dacbb28e6ae88b4f1bb25d04e17f94b0edd82232bcbd",39 "sha256:7cf39bb3a905579836f7a8f3a45320d9eb22f16ab0c1e112efb940ced4d057a5",40 "sha256:9563a23c1456c0ab550c087833bc13fcc61013a66c6420921d5b70550ea312bf",41 "sha256:95b392952935947e0786a90b75cc33388549dcb19af716b525dae65b186138fc",42 "sha256:983129f3fd3cef5c3cf067adcca56e30a169656c00fcc6c648629dbb850b27fa",43 "sha256:a0b75b1f1854771844c647c464533def3e0a899dd094a85d1d4ed72ecaaee93d",44 "sha256:b5db89cc0ef624f3a81214b7961a99f443b8c91e88188376b6b322fd10d5b118",45 "sha256:c0a7751ba1a4bfbe7831920d98cee3ce748007eab8dfda74593d44079568219a",46 "sha256:c0c5a7d4aafcc30c9b6d8613a362567e32e5f5b708dc41bc3a81dac56f8af8bb",47 "sha256:d4d63d85eacc6cb37b459b16061e1f100d154bee89dc8d8f9a6128a5a538e92e",48 "sha256:da5e7e941d6e71c9c9a717c93725cda0708c2474f532e3680ac5e39ec57d224d",49 "sha256:dccad2b3c583f036f43f80ac99ee212c2fa9a45151358d55f13004d095e683b2",50 "sha256:df46307d39f2aeaafa1d25309b8a8d11738b73e9861f72d4d0a092528f498baa",51 "sha256:e70b5e1cb48828ddd2818f99b1662cb9226dc6f57d07fc75485405c77da17436",52 "sha256:ea825562b8cd057cbc9810d496b8b5dec37a1e2fc7b27bc7c1e72ce94462a09a"53 ],54 "index": "pypi",55 "version": "==4.3.1"56 },57 "markdown": {58 "hashes": [59 "sha256:c00429bd503a47ec88d5e30a751e147dcb4c6889663cd3e2ba0afe858e009baa",60 "sha256:d02e0f9b04c500cde6637c11ad7c72671f359b87b9fe924b2383649d8841db7c"
57 unmodified lines
modified:Makefile.am+2 added-2 removed
163 unmodified lines
164install-binaries: $(BUILT_SOURCES)165 $(MAKE) $(AM_MAKEFLAGS) install-exec166167DOC_FILES = docs/content docs/public docs/templates docs/site.yml \168 docs/Pipfile docs/Pipfile.lock docs/build_website.py \169 docs/README.md jq.1.prebuilt168 docs/Pipfile docs/Pipfile.lock docs/build_manpage.py \169 docs/build_manpage.py docs/README.md jq.1.prebuilt170171EXTRA_DIST = $(DOC_FILES) $(man_MANS) $(TESTS) $(TEST_LOG_COMPILER) \172 jq.1.prebuilt jq.spec src/lexer.c src/lexer.h src/parser.c \173 src/parser.h src/version.h src/builtin.jq \
49 unmodified lines