How can I use NotebookImport for grabbing "ExampleSection" cells?

nb = NotebookOpen["paclet:ref/RandomPrime"];
NotebookImport[nb, "ExampleSection"->"Text"]
(* {} *)

Because of reasons those cells have multiple styles, or rather a duplicated style:

enter image description here

NotebookImport has issues with such cells: NotebookImport ignoring multiple style cells

So you can import them with:

NotebookImport[nb, {"ExampleSection", "ExampleSection"} -> "Text"]

enter image description here

But it contains string representation of boxes with the cell opener etc.

You can play around with NotebookImport but this seems to do the job:

  NotebookRead /@ Cells[nb, CellStyle -> "ExampleSection"]
  All, (*every cell*)
  1,   (*TextData*)
  1,   (*TextData arg is list*)
  3    (*our string is after the opener and a spacer*)
{"Basic Examples", "Scope", "Applications", "Properties & Relations", "Possible Issues"}

Though I did not test it on every page.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.