Skip to content
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

preserve order of text containing list items #364

Open
waldenn opened this issue May 1, 2020 · 3 comments
Open

preserve order of text containing list items #364

waldenn opened this issue May 1, 2020 · 3 comments

Comments

@waldenn
Copy link
Contributor

waldenn commented May 1, 2020

example

Sometimes the parsed list is moved to the beginning of a section.

@niebert
Copy link
Contributor

niebert commented May 2, 2020

This may related to fact that objects in Javascript do not preserve the order.

obj = {
  a:4545,
  b:"test",
  c:4.5
};

With the iteration over the variables of the object obj you would expect the following result:

4545
test
4.5

and you create the output abover with the following code

for (var variable in obj) {
    if (obj.hasOwnProperty(variable)) {
      console.log(obj.variable)
    }
  }

But order of variable/keys of the object is not deterministic in all browsers. You could also get in another browser C the following result:

test
4.5
4545

This problem could lead to additional workload to preserve the variable order of an object. E.g. with an array of variable names/keys:

obj = {
  a:4545,
  b:"test",
  c:4.5
};

myorder = ["a","b","c"]

for (var i = 0; i < myorder.length; i++) {
  console.log( obj[myorder[i]] )
}

The array preserves the order of variables/keys of the object browser independently.

@waldenn
Copy link
Contributor Author

waldenn commented May 2, 2020

Hey Niebert. Object-key order should be predictable in modern browsers, but still this is good to keep in mind.

@waldenn
Copy link
Contributor Author

waldenn commented May 3, 2020

Using a customized wtf-debug instance and looking at the console.log() of wtf list objects of this example, could we not just add an increasing order number (which resets for each section, or even better perhaps: some global numbering scheme like eg. <section-nr>, <section-item-nr>, <sentence-item-nr> ) to all major wtf objects (sentences, lists, templates, etc)? A <sentence-item-nr> would only increment for items within a sentence. Not sure how tables with complex content would work with this though, perhaps tables should only be ordered to the <section-item-nr>.

This way we would get the natural order of things, and would be able to render them in that order if so desired. For some elements a different presentation order may be desirable and that could still work, if the user ignores/removes that element (or those types of elements) from the ordered list and places it somewhere else.

If this could work, it would solve a lot of inline-content issues. Eg. to show the "quote" at the right position in the section or the list. A first step to tackle this could be by just adding this "3-level" ordering data to all objects and later reviewing it in the debugger by parsing the objects in order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants