-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
jq manual remake #3183
Comments
I've converted a few more sections now and enabled "Run" links for jqplay.org, the result is here. |
How do you generate |
@01mf02 - Rewriting the jq manual in the way you've described sounds like a very I was wondering whether you've considered (either I would also like to see a new page under the Tips section, which It would be really helpful to have an up-to-date "Regarding jaq" page, |
Creating the combination of |
It's might actually be a less ambitious project than I thought, for I was able to convert the whole manual to HTML/PDF. I did this as follows: I converted
The jq script "---\ntitle: jq manual\n---\n\n",
.body,
(.sections[] | (
"# \(.title)",
.body // "",
(.entries[]? | (
"## \(.title)",
.body,
if .examples then "::: Examples\n", (.examples[] | (
"~~~",
(.program | gsub("\n"; " ")),
.input,
(.output | if . == [] then "\n" else .[] end),
"~~~\n"
)), ":::\n" else empty end
))
)) From this, I use Pandoc to convert Markdown to HTML:
This creates an HTML file -- inline code is always written in jq
function Code(code)
code.classes[1] = "jq"
return code
end
-- code blocks are assumed to be in jq if no other language is given
function CodeBlock(block)
if next(block.classes) == nil then
block.classes[1] = "jq"
return block
end
end
function Div(el)
if el.classes:includes'Examples' then
return pandoc.walk_block(el, {CodeBlock = function(block)
-- print example to stdout
print(block.text .. "\n")
return exampleTable(block.text)
end})
end
end
function exampleTable(test)
local _, _, filter, input, output = test:find("([^\n]+)\n([^\n]+)\n(.*)")
local url = "https://jqplay.org/jq?q=" .. encodeUrl(filter) .. "&j=" .. encodeUrl(input)
simple_table = pandoc.SimpleTable(
"", -- caption
{pandoc.AlignRight, pandoc.AlignLeft},
{0, 0}, -- let pandoc determine col widths,
{}, -- headers
{
{pandoc.Plain("Filter"), pandoc.Code(filter, {class = "jq" })},
{pandoc.Plain( "Input"), pandoc.Code( input, {class = "json"})},
{pandoc.Plain("Output"), pandoc.Code(output, {class = "json"})},
{pandoc.Link("Run", url), {}}
}
)
return pandoc.utils.from_simple_table(simple_table)
end
function encodeUrl(str)
str = string.gsub(str, "\n", "\r\n")
str = string.gsub(str, "([^%w%.%- ])", function(c) return string.format("%%%02X", string.byte(c)) end)
str = string.gsub(str, " ", "+")
return str
end We can also create a PDF file, by going through Typst:
I used this to produce the PDF file at the beginning of this post.
I have not considered this so far. In the context of the present issue, I would like to concentrate on making the format of the manual easier to modify. Revising documentation is a different issue.
I think the best would be if any information that would be available at some "Regarding jaq" page would be directly integrated into the manual. That makes it much easier for users to find information and to keep it up-to-date. ## `input`
Outputs one new input. My idea is to enhance it as follows: ## `input`
Outputs one new input.
::: Compatibility
Available since jq 1.5.
When there is no more input,
jq returns an error, whereas
jaq returns no output (`empty`).
::: The compatibility statement could be rendered in the documentation as a block. |
By the way, Pandoc can also create man pages, so we can use it to generate |
This is needed to make the Markdown -> HTML conversion work with Pandoc, see jqlang#3183.
@itchyny, I've found a way to generate both mkdir -p tests
split --separator='\0' -l1 all.test tests/
REGEX="test|match|capture|scan|split|splits|sub|gsub"
grep -L -E $REGEX tests/* | xargs cat | sed 's/\x0/\n/g' > man.test
grep -l -E $REGEX tests/* | xargs cat | sed 's/\x0/\n/g' > manonig.test
rm -r tests |
I've now performed the conversion of the manual to Markdown, see #3186. |
I would like to extend the jq manual with information about diverging behaviour between different jq implementations (jq, gojq, jaq, ...). For this, I will have to go through the whole manual once, which I think would be a nice opportunity to adapt its format.
Currently, the jq manual is written as a YAML file, which mostly contains Markdown blocks and examples.
I thought about transforming it to a pure Markdown file, and then creating HTML from it via Pandoc.
The advantages of this would be:
To show the feasibility of it, I recreated a part of the "Conditionals and Comparisons" section of the jq manual in Markdown. You can use
to render this to the following HTML (sorry, GitHub doesn't let me upload HTML directly, so I exported the HTML to PDF and uploaded that).
This requires the file
filter.lua
, which I wrote today in about 2 hours (I don't know Lua ^^) and which currently looks like this:I am fairly confident that I would be able to convert the whole manual to this Markdown format.
But I'm only going to do this if it's likely that this is going to be merged into jq.
So the question is: Would you consider merging such a change?
The text was updated successfully, but these errors were encountered: