3

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

nb = NotebookOpen["paclet:ref/RandomPrime"];
NotebookImport[nb, "ExampleSection"->"Text"]
(* {} *)
M.R.
  • 31,425
  • 8
  • 90
  • 281

1 Answers1

2

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.

Kuba
  • 136,707
  • 13
  • 279
  • 740