Note that there are some explanatory texts on larger screens.

plurals
  1. POExtracting context from a set point in the middle of an HTML file
    primarykey
    data
    text
    <p>I have some HTML, and I'm extracting a snippet at a certain point (an inline image), but I'd like to show some context around this image.</p> <p>I'm using PHP, and I know that both Symfony and Wordpress provide functions for dealing with what happens when you chop up text in the middle of some HTML (it closes all open tags), but nothing for dealing with snippets in the other direction.</p> <p>So, in the case of :</p> <pre><code> 'Snippet of text and a &lt;a href="#moo"&gt;link right her' </code></pre> <p>I can use the above-mentioned function to fix, but what about:</p> <pre><code>'nk right here&lt;/a&gt; and then more text after the link.' </code></pre> <p>I've considered the possibility that even the tag-closing snippet is probably the wrong way to go about this, and I should instead be using Xpath to parse the HTML. However, I can't find any examples or mentions of using xpath to create snippets like this.</p> <p><strong>Update:</strong></p> <p>So my current idea is:</p> <ol> <li><p>move up the parse tree until I get to the tag that encloses all the content (div class=post in my case). The last node that I have before this div is the starting point (most likely a p tag).</p></li> <li><p>From here, get the previous sibling (which should be a p tag again).</p></li> <li><p>Descend into this node and get the last children, saving the text content to a temporary string. Keep stepping back through these children, until we get enough of a snippet.</p></li> </ol> <p>This still ins't ideal, as I'm not sure how far I'll have to step down to get the text content.</p> <p>Does anyone know of an implementation of this idea anywhere?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload