• Resolved peterdeegan

    (@peterdeegan)


    Marc,

    This is possibly too niche a request but I add it for your consideration. I continue to be very happy with your SimpleTOC and my readers appreciate it too.

    We have to repurpose WordPress posts for other uses and that means stripping out some of the WP and plugin generated HTML. Usually done via RegEx.

    At present your opening <ul or <div tags have clear labels like class=”simpletoc-list” but the closing tags are just </ul> or </div> which makes it hard for computers and sometimes humans to parse. With nested <ul …> tags it’s difficult for Regex to work out where SimpleTOC ends it’s work.

    Could you consider giving one or both of the tags a fixed ending label such as </div id=”simpletoc”> which makes it easy for both parsing code and human coders to see? I thought adding it to the <div… might be more appropriate than the standard <ul …> then I could use the add_filter( ‘simpletoc_wrapper_enabled’ … option.

    Danke,

    Peter Deegan

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Marc Tönsing

    (@marcdk)

    Hi,

    Thank you for your feedback. Much appreciated. Don’t use regex for parsing HTML. Use http://docs.php.net/manual/en/domdocument.loadhtml.php instead. SimpleTOC uses that internally. Your suggestion would result in bad HTML and therefore this is not an option

    Thread Starter peterdeegan

    (@peterdeegan)

    I take your point about RegEx and HTML. The code we have is very old and we’ve been happy with things the way they are. To say nothing of the difficulties understanding the DOM model.

    But I’ve taken the plunge and added a DOM object. FWIW, this is the code I’m using to remove SimpleTOC block from a posts HTML.

    // removes the SimpleTOC block - finds any UL tag with the class=" as shown and remove entire block including nested UL's.
    $xpath = new DOMXPath($dom);
    foreach($xpath->query('//ul[@class="simpletoc-list"]') as $div) {
    $div->parentNode->removeChild($div);
    }

    Not many people will need this, our exporting posts scenario is quite rare.

    Danke,

    Plugin Author Marc Tönsing

    (@marcdk)

    Gern geschehen! You are welcome. And thanks for sharing with everyone!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘More detailed end tag’ is closed to new replies.