From 31973aaa1293461230511a5740e0ca356a8ac197 Mon Sep 17 00:00:00 2001

Subject: [PATCH 0/1] plain explode to regex split for level-2 headings, support for level-3 + headings, support for content before first level-2 heading (like book cover)

plain explode to regex split for level-2 headings, support for level-3 + headings, support for content before first level-2 heading (like book cover)

Reply to this note

Please Login to reply.

Discussion

Hmmm... these don't contain my suggestions

```

...

// check if the file contains too many header levels

// (stripos($markdown,'###') !== false) ? throw new InvalidArgumentException('This markdown file contains too many header levels. Please correct down to 2 levels and retry.') : $markdown;

// break the file into metadata and sections

// $markdownFormatted = explode("^##\s", $markdown);

$markdownFormatted = preg_split("^##\s", $markdown); // split on all lines beginning with `##` followed by a space, indicating heading level #2

// check if the file contains too few header levels

(count($markdownFormatted) === 1) ? throw new InvalidArgumentException('This markdown file contain no headers or only one level of headers. Please add a second level and retry.') : $markdownFormatted;

$this->set_short_title(trim($this->bookArguments[1], ".md"));

// $bookTitle = array_shift($markdownFormatted);

$bookCover = explode(PHP_EOL, $markdownFormatted[0], 2);

if(count($bookCover) > 1) {

$bookTitle = $bookCover[0];

$markdownFormatted[0] = $bookCover[1];

} else {

$bookTitle = $bookCover[0];

$bookCover = "";

array_shift($markdownFormatted);

}

$this->set_title(trim(trim($bookTitle, "# ")));

...

```

Changed line 135 to:

$markdownFormatted = preg_split('/^##/\s/', $markdown);

$markdownFormatted = preg_split('\'/^##/\\s/\'', $markdown);

this one seems to work

I can't seem to get it to work. Have you tried it on a file with only 2 header levels and with no content before the first ##?

Let me check...

I think it depends on the implementation of the new line in the *.md. Here's the fix:

`preg_split("/[\n\r]##\s/", $markdown)`

Okay, I'll try that and get back to you.

I've opened up an issue for myself, to figure out why this isn't working on my installation and integrate your ideas. Thank you!

nostr:nevent1qqstsczw4lxjdtwnysemzg8sjl3ythhf7va2h63lrwt4lkdu8m9kvcgpz4mhxue69uhhqatjwpkx2un9d3shjtnrdaksygxavex4usqkgvage45lqpdwzjqgqs630zd4nhj67p38dhn9vv7nryrtntwm

Let me take a closer look at this...

Okay, I finally managed to pull it and create a matching branch, and it seems to work on articles with 2 or 3 headers. Need to trim some returns off and fiddle around a bit, and then I can push the update.