Answer prose round 1: 0 🔴, 6 🟡 (0 misread); say each pair's use once in the module docstring, name what the changelog entry keeps, and make item 391 stand alone
This commit is contained in:
@@ -4,7 +4,7 @@ It runs @larvit/adf-codec, a Node package, in a throwaway container that holds n
|
||||
|
||||
adf-codec has two pairs of calls, and each function here names the one it runs:
|
||||
- The lossless pair, `*_lossless`, for a document that already exists in Jira or Confluence and is edited and saved back. It keeps each block's localId and the empty paragraphs Jira uses for spacing, so a document read and saved unedited comes back identical.
|
||||
- The portable pair, with no suffix, for new text written from scratch, and for markdown shown to a person. It drops both, so saving a document that exists changes it.
|
||||
- The portable pair, with no suffix, for new text written from scratch, and for markdown shown to a person. It drops the localId and the empty paragraphs, so saving a document that exists changes it.
|
||||
"""
|
||||
import contextlib
|
||||
import dataclasses
|
||||
@@ -35,7 +35,7 @@ class Ran:
|
||||
err: str
|
||||
|
||||
|
||||
# Runs the shim in the given mode (`to-adf`, `to-markdown` or either with `-lossless` after it) on a text, or fails to run it.
|
||||
# Runs the shim in the given mode (`to-adf`, `to-markdown`, `to-adf-lossless` or `to-markdown-lossless`) on a text, or fails to run it.
|
||||
Run = typing.Callable[[str, str], Ran | Failure]
|
||||
# Runs a docker command line on a text, in at most the given seconds, or fails to run it.
|
||||
Docker = typing.Callable[[list[str], str, int], Ran | Failure]
|
||||
@@ -190,32 +190,30 @@ def one_markdown(texts: list[str] | Refused | Failure) -> str | Failure:
|
||||
|
||||
|
||||
def markdown_to_adf(markdown: str, run: Run = container_run) -> dict[str, typing.Any] | Failure:
|
||||
"""The ADF document for new markdown, by the portable pair: for text written from scratch. It can't carry a document that exists back unchanged; use markdown_to_adf_lossless."""
|
||||
"""The ADF document for the markdown, by the portable pair."""
|
||||
return to_adf("to-adf", markdown, run)
|
||||
|
||||
|
||||
def markdown_to_adf_lossless(markdown: str, run: Run = container_run) -> dict[str, typing.Any] | Failure:
|
||||
"""The ADF document for markdown that adf_to_markdown_lossless or adfs_to_markdown_lossless wrote, by the lossless pair: for saving an existing Jira or Confluence document back. Unedited, it gives back the document that was read."""
|
||||
"""The ADF document for the markdown, by the lossless pair."""
|
||||
return to_adf("to-adf-lossless", markdown, run)
|
||||
|
||||
|
||||
def adfs_to_markdown(documents: list[dict[str, typing.Any]], run: Run = container_run) -> list[str] | Refused | Failure:
|
||||
"""The markdown for each ADF document, in their order, by the portable pair, from one container run, so a caller with many documents pays one container start.
|
||||
|
||||
For markdown shown to a person; the text can't be saved back without changing the document, so use adfs_to_markdown_lossless to edit one."""
|
||||
"""The markdown for each ADF document, in their order, by the portable pair, from one container run, so a caller with many documents pays one container start."""
|
||||
return to_markdowns("to-markdown", documents, run)
|
||||
|
||||
|
||||
def adfs_to_markdown_lossless(documents: list[dict[str, typing.Any]], run: Run = container_run) -> list[str] | Refused | Failure:
|
||||
"""The markdown for each ADF document, in their order, by the lossless pair, from one container run: for documents that exist in Jira or Confluence and are edited and saved back with markdown_to_adf_lossless."""
|
||||
"""The markdown for each ADF document, in their order, by the lossless pair, from one container run."""
|
||||
return to_markdowns("to-markdown-lossless", documents, run)
|
||||
|
||||
|
||||
def adf_to_markdown(document: dict[str, typing.Any], run: Run = container_run) -> str | Failure:
|
||||
"""The markdown for the ADF document, by the portable pair: for showing it to a person, not for saving it back."""
|
||||
"""The markdown for the ADF document, by the portable pair."""
|
||||
return one_markdown(adfs_to_markdown([document], run))
|
||||
|
||||
|
||||
def adf_to_markdown_lossless(document: dict[str, typing.Any], run: Run = container_run) -> str | Failure:
|
||||
"""The markdown for the ADF document, by the lossless pair: for editing it and saving it back with markdown_to_adf_lossless."""
|
||||
"""The markdown for the ADF document, by the lossless pair."""
|
||||
return one_markdown(adfs_to_markdown_lossless([document], run))
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
// Converts between markdown and ADF with @larvit/adf-codec. The mode is the one argument:
|
||||
// to-adf stdin is markdown, stdout is the ADF document as JSON
|
||||
// to-markdown stdin is a JSON array of ADF documents, stdout a JSON array of their markdown texts, in their order
|
||||
// The portable calls behind those two drop each block's localId and empty paragraphs. The same two modes with the suffix
|
||||
// -lossless, to-adf-lossless and to-markdown-lossless, call adf-codec's lossless pair, which keeps both.
|
||||
// to-adf-lossless, to-markdown-lossless the same, through adf-codec's lossless pair in place of its portable pair
|
||||
// Exit 0: stdout holds the answer. Exit 2: adf-codec refused the input, and stdout holds {"error": {code, message, path, position?}},
|
||||
// with "index", the refused document's place in the array, beside "error" in to-markdown.
|
||||
// Exit 1: the shim could not run, and stderr says why.
|
||||
|
||||
Reference in New Issue
Block a user