Create alphabetical ordered index-page from list attribute

See .isort().

Also useful to know: Lexical vs. numeric sorting.

1 Like

.isort() an easy add to the function when needed. Thanks!

1 Like

My main question is the second one, about the markup differences in the second tbx attached even though it is the same functions being called.

When using the stamp, you call your function to place a list of entries into the text of the note. Each entry is separated with a carriage return:

	return result.format("\n");

When you export (or preview) the page, each paragraph receives markup, transforming “TermA, Chapter 1, Chapter 6\n” to

<p>TermA, Chapter 1, Chapter 6</p>

That second step isn’t done in ^value(), which inserts the literal result.

One solution would be to insert HTML markup in the function:

	return result.format("<br> \n");

This is poor HTML style, but it gets the job done. Better would be to export a proper list:

         <li> entry 1 </li> 
         ...
</ul> 

That’s easy enough as well.

You could also write a function that takes the result of termToLoc and wraps each line in paragraph markup:

function asList(theIndex:string) {
    var:string result;
   theIndex.eachLine(entry) {
      result += "<p>" + entry + "</p>";
      }
   return result;
}
2 Likes

This makes me very happy. :smiling_face_with_three_hearts::smiling_face_with_three_hearts::smiling_face_with_three_hearts:

[sorry about the seeming partial answer—I was half out the door to fix storm damage at out allotment (garden) when I saw the post. I answered the bit it I knew.]

If I understand correctly, the difference lies in understanding $Text in Text vs. Preview mode. Looking at Index-text-test.tbx, and “Index - ^value(function)” vs. “Index - stamp me” in Export pane shows this use. I feel like an angry prophet, but if you click from Text to Preview and it looks wrong, look at the Export tab before trying to fix anything.

That said, this seemingly ‘simple’ problem, which 50 minutes later turns out to be a limitation of what can be done inside ^value()^. I won’t go into gory detail here as it ins more helpful to look at this in a version of your test doc:

Index-text-test copy.tbx (246.9 KB)

In this, I’ve copied your original “Index - ^value(function)” as “Index - ^value(function) original”. I also changed the note to turns off ‘smart quotes’ as the fix needs code in the note.

My first thought was to write something like this:

^value(locToTerm($Path(parent)).replace("\n","").format("","<p>","</p>","")^

but that failed. But this works:

^action(
var:list vListOne = termToLoc($Path(parent)).replace("\n",";");
$Text(/log) = vListOne;
var:string vStringOne = vListOne.format("","<p>","</p>\n","");
var:list vListTwo = locToTerm($Path(parent)).replace("\n",";");
$Text(/log) = vListTwo;
var:string vStringTwo = vListTwo.format("","<p>","</p>\n","");

)^
<h3>Term to Location</h3>
...etc.

As the previous reply in-thread shows, there’s no one ‘right’ answer. However, the above hopefully sticks close to what you thought you were trying to do.

HTH

2 Likes

The explanations and the many examples approaching the problem from different angles are most helpful. Thank you!

3 Likes