meander

grounded_sage 2024-08-11T15:10:49.889519Z

How do I get this to collect an arbitrary number of paragraphs after a heading?

(m/search (:content (md/parse s))
 (m/scan {:type :heading
          :content [{:text ?heading}]
          :heading-level 2}
          {:type :paragraph
           :content [{:text ?content}]}
          {:type :paragraph
           :content [{:text ?content-1}]})
          {?heading [?content ?content-1]})

markaddleman 2024-08-11T15:44:51.000169Z

Can you give an example of the input data?

grounded_sage 2024-08-11T17:54:06.665699Z

I can do this tomorrow. The input is from md/parse of https://github.com/nextjournal/markdown. Basically taking markdown and wanting to collect the paragraphs under headings whilst maintaining which heading it comes from.

grounded_sage 2024-08-12T06:49:00.427539Z

@markaddleman Basically I want to be able to scope in and extract all paragraphs under a the headings. Keeping the source order of those paragraphs. I want to know how I can generalize this but also get just the paragraphs under specific headings. Which could be done by specifying it to match on like so.

{:type :heading
 :content [{:text "Specific heading"}]
          :heading-level 2}

grounded_sage 2024-08-12T06:49:35.739819Z

At present what I have is broken. It only works when there is 2 paragraphs under a heading level 2. If there is any less Meander returns nothing.

grounded_sage 2024-08-12T06:51:15.156519Z

If I just specify just 1 and there is more I get just the 1 under that heading. The current way I was getting back a list of maps. I would then use (into {} to get them all into a map and destructure to pluck out the paragraphs by the heading as a key.

markaddleman 2024-08-14T15:44:05.661199Z

I think this gives you what you want. The key piece is first partitioning the data into a form that meander can handle easily.