ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Automatically adjust number of table columns
@ 2021-09-05 11:01 Sylvain Hubert via ntg-context
  0 siblings, 0 replies; only message in thread
From: Sylvain Hubert via ntg-context @ 2021-09-05 11:01 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Sylvain Hubert


[-- Attachment #1.1: Type: text/plain, Size: 1989 bytes --]

Dear List,

I'm trying to make "\startchoice", "\stopchoice", and "\choice", such that:

    \startchoice
    \choice -1
    \choice 0
    \choice 1
    \choice N/A
    \stopchoice

results in (_ for whitespace)

    A. -1______B. 0______C. 1______D. N/A

while

    \startchoice
    \choice not so short choice
    \choice must wrap here
    \choice another choice
    \choice yet another choice
    \stopchoice

results in

    A. not so short choice____B. must wrap here
    C. another choice_______D. yet another choice

In another word, it should have the same effect as the addData() function
in the page below (save as whatever.html and open it)

<html>
<head>
<style>
table { width: 100%; border: 1px solid black; }
#root { width: 10cm; }
</style>
</head>

<body>
<div id="root">
</div>

<script>
function make(tag, children) {
const node = document.createElement(tag);
for (const c of children) {
if (typeof c === "string") {
node.appendChild(document.createTextNode(c));
} else {
node.appendChild(c);
}
}
return node;
}

function addData(data) {
const root = document.getElementById("root");

let table = make("table", [make("tr", data.map(d => make("td", [d])))]);
root.appendChild(table);
if (table.scrollWidth <= root.offsetWidth) {
return;
}

root.removeChild(table);
table = make("table", [
make("tr", [make("td", [data[0]]), make("td", [data[1]])]),
make("tr", [make("td", [data[2]]), make("td", [data[3]])]),
]);
root.appendChild(table);
if (table.scrollWidth <= root.offsetWidth) {
return;
}

root.removeChild(table);
table = make("table", data.map(d => make("tr", [make("td", [d])])));
root.appendChild(table);
}

addData(["1".repeat(10), "2".repeat(10), "3".repeat(10), "4".repeat(10), ]);
addData(["1".repeat(20), "2".repeat(20), "3".repeat(20), "4".repeat(20), ]);
addData(["1".repeat(30), "2".repeat(30), "3".repeat(30), "4".repeat(30), ]);
</script>
</body>
</html>

Does anyone have an idea how it can be implemented in context?

Thanks in advance!

Best,
Sylvain

[-- Attachment #1.2: Type: text/html, Size: 3179 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-09-05 11:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-05 11:01 Automatically adjust number of table columns Sylvain Hubert via ntg-context

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).