Return (part-content) whats in between <h2 id="method>...</h2>

Hi,
I am trying to simplify a couple of things on the website that I am building.
What I want to achieve is to, use partial to grab from 1st occurrence <h2> element with id="method" and paste what after the first occurrence of <h2 with id=method but not after the next one (this may be tricky)

example markdown

## Method
lorem ipsum lorem ipsum
## Comment
dolor sit amet

return only

lorem ipsum lorem ipsum

Have looked at

{{ (findRE "<h2 id=\"method\">(.|\n)*?</h2>" .Content 1) }}

but that returning, as intended and described here)

[<h2 id="method">Method</h2>]

Know this may be a bit difficult if not imposible.

Update #1

Got something like that

{{ (findRE "Method</h2>(.|\n)*?<h2 *?" .Content) }}

which gives me

[Method</h2> <p>lorem ipsum</p><p>lorem ipsum</p> <h2]

Now todo > strip array [ ], replace unwanted bits with empty (know how) and then make it plain (plainify?)

What is the goal of this regex? Can you show the original h2 element HTML and HTML you plan to transform to?

I think that Heading Render Hooks might make it a lot easier than parsing HTML with regex.

I missed this part. So that should be possible using Heading Render Hooks. Have an if condition in that that returns “” if certain conditions match (like .Title is method, .Level is 2). Otherwise, return the heading element you define there.


But removing the content after the Comment heading will still require you to use the regex parsing unfortunately.

1 Like