From 42d9f2c27dba4cf0811e320e82b6eea8df688ff1 Mon Sep 17 00:00:00 2001 From: Mattias Wadman Date: Tue, 29 Nov 2022 18:59:28 +0100 Subject: [PATCH] interp,help: Properly count line length when breaking on whole words Whitespace between words were not counted --- format/markdown/markdown.jq | 6 +++--- format/riff/testdata/help_avi.fqtest | 4 ++-- format/xml/testdata/help_xml.fqtest | 12 +++++++----- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/format/markdown/markdown.jq b/format/markdown/markdown.jq index 907f5ce2..d3df910b 100644 --- a/format/markdown/markdown.jq +++ b/format/markdown/markdown.jq @@ -1,9 +1,9 @@ def _markdown__todisplay: tovalue; -def word_break($width): +def _word_break($width): def _f($a; $acc; $l): ( $a[0] as $w - | ($w // "" | length) as $wl + | ($w // "" | length+1) as $wl | if $w == null then $acc elif ($l + $wl) >= $width then ( $acc @@ -17,7 +17,7 @@ def word_break($width): ); def _markdown_to_text($width; $header_depth): - def lb: if $width > 0 then word_break($width) | join("\n") end; + def lb: if $width > 0 then _word_break($width) | join("\n") end; def _f($pln): if type == "string" then gsub("\n"; " ") elif .type == "document" then .children[] | _f("\n\n") diff --git a/format/riff/testdata/help_avi.fqtest b/format/riff/testdata/help_avi.fqtest index 48d2d00a..0607b549 100644 --- a/format/riff/testdata/help_avi.fqtest +++ b/format/riff/testdata/help_avi.fqtest @@ -20,8 +20,8 @@ Decode examples Samples ======= -AVI has many redundant ways to index samples so currently .streams[].samples will only include samples the most "modern" way used in the file. That is in order -of stream super index, movi ix index then idx1 index. +AVI has many redundant ways to index samples so currently .streams[].samples will only include samples the most "modern" way used in +the file. That is in order of stream super index, movi ix index then idx1 index. Extract samples for stream 1 ============================ diff --git a/format/xml/testdata/help_xml.fqtest b/format/xml/testdata/help_xml.fqtest index 5a11ff73..dfc3051a 100644 --- a/format/xml/testdata/help_xml.fqtest +++ b/format/xml/testdata/help_xml.fqtest @@ -20,11 +20,12 @@ Decode examples # Decode value as xml ... | xml({array:false,attribute_prefix:"@",seq:false}) -XML can be decoded and encoded into jq values in two ways, elements as object or array. Which variant to use depends a bit what you want to do. The object variant -might be easier to query for a specific value but array might be easier to use to generate xml or to query after all elements of some kind etc. +XML can be decoded and encoded into jq values in two ways, elements as object or array. Which variant to use depends a bit what you +want to do. The object variant might be easier to query for a specific value but array might be easier to use to generate xml or to +query after all elements of some kind etc. -Encoding is done using the toxml function and it will figure what variant that is used based on the input value. Is has two optional options indent and -attribute_prefix. +Encoding is done using the toxml function and it will figure what variant that is used based on the input value. Is has two optional +options indent and attribute_prefix. Elements as object ================== @@ -36,7 +37,8 @@ Element can have different shapes depending on body text, attributes and childre - text is {"a":{"b":["","text"]}} two children with same name end up in an array - text is {"a":{"b":["",{"#text":"text","@key":"value"}]}} -If there is #seq attribute it encodes the child element order. Use -o seq=true to include sequence number when decoding, otherwise order might be lost. +If there is #seq attribute it encodes the child element order. Use -o seq=true to include sequence number when decoding, otherwise +order might be lost. # decode as object is the default